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
|
---|---|---|---|---|---|---|
DorianScholz/OpenLibre | app/src/main/java/de/dorianscholz/openlibre/ui/SensorStatusFragment.java | // Path: app/src/main/java/de/dorianscholz/openlibre/model/SensorData.java
// public class SensorData extends RealmObject {
// public static final String ID = "id";
// public static final String START_DATE = "startDate";
//
// public static final long minSensorAgeInMinutes = 60; // data generated by the sensor in the first 60 minutes is not correct
// public static final long maxSensorAgeInMinutes = TimeUnit.DAYS.toMinutes(14); // data generated by the sensor after 14 days also has faults
//
// @PrimaryKey
// private String id;
// private long startDate = -1;
//
// public SensorData() {}
//
// public SensorData(RawTagData rawTagData) {
// id = String.format(Locale.US, "sensor_%s", rawTagData.getTagId());
// startDate = rawTagData.getDate() - (rawTagData.getDate() % TimeUnit.MINUTES.toMillis(1))
// - TimeUnit.MINUTES.toMillis(rawTagData.getSensorAgeInMinutes());
// }
//
// public SensorData(SensorData sensor) {
// this.id = sensor.id;
// this.startDate = sensor.getStartDate();
// }
//
// public String getTagId() {
// return id.substring(7);
// }
//
// public long getTimeLeft() {
// return max(0, startDate + TimeUnit.MINUTES.toMillis(maxSensorAgeInMinutes) - System.currentTimeMillis());
// }
//
// public long getStartDate() {
// return startDate;
// }
//
// public String getId() {
// return id;
// }
// }
//
// Path: app/src/main/java/de/dorianscholz/openlibre/OpenLibre.java
// public static RealmConfiguration realmConfigProcessedData;
//
// Path: app/src/main/java/de/dorianscholz/openlibre/model/AlgorithmUtil.java
// public static String getDurationBreakdown(Resources resources, long duration)
// {
// duration = max(0, duration);
//
// long days = TimeUnit.MILLISECONDS.toDays(duration);
// duration -= TimeUnit.DAYS.toMillis(days);
// long hours = TimeUnit.MILLISECONDS.toHours(duration);
// duration -= TimeUnit.HOURS.toMillis(hours);
// long minutes = TimeUnit.MILLISECONDS.toMinutes(duration);
//
// if (days > 1) {
// return days + " " + resources.getString(R.string.days);
// }
// if (days == 1) {
// return "1 " + resources.getString(R.string.day);
// }
// if (hours > 1) {
// return hours + " " + resources.getString(R.string.hours);
// }
// if (hours == 1) {
// return "1 " + resources.getString(R.string.hour);
// }
// if (minutes > 1) {
// return minutes + " " + resources.getString(R.string.minutes);
// }
// if (minutes == 1) {
// return "1 " + resources.getString(R.string.minute);
// }
//
// return "0 " + resources.getString(R.string.minutes);
// }
//
// Path: app/src/main/java/de/dorianscholz/openlibre/model/SensorData.java
// public static final String START_DATE = "startDate";
| import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.DialogFragment;
import android.support.v7.app.AlertDialog;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import java.text.DateFormat;
import java.util.Date;
import java.util.concurrent.TimeUnit;
import de.dorianscholz.openlibre.R;
import de.dorianscholz.openlibre.model.SensorData;
import io.realm.Realm;
import io.realm.RealmResults;
import io.realm.Sort;
import static de.dorianscholz.openlibre.OpenLibre.realmConfigProcessedData;
import static de.dorianscholz.openlibre.model.AlgorithmUtil.getDurationBreakdown;
import static de.dorianscholz.openlibre.model.SensorData.START_DATE; | package de.dorianscholz.openlibre.ui;
public class SensorStatusFragment extends DialogFragment {
public SensorStatusFragment() {
// Required empty public constructor
}
public static SensorStatusFragment newInstance() {
SensorStatusFragment fragment = new SensorStatusFragment();
Bundle args = new Bundle();
fragment.setArguments(args);
return fragment;
}
public void setupUi(View view) {
Realm realmProcessedData = Realm.getInstance(realmConfigProcessedData);
RealmResults<SensorData> sensorDataResults = realmProcessedData.where(SensorData.class). | // Path: app/src/main/java/de/dorianscholz/openlibre/model/SensorData.java
// public class SensorData extends RealmObject {
// public static final String ID = "id";
// public static final String START_DATE = "startDate";
//
// public static final long minSensorAgeInMinutes = 60; // data generated by the sensor in the first 60 minutes is not correct
// public static final long maxSensorAgeInMinutes = TimeUnit.DAYS.toMinutes(14); // data generated by the sensor after 14 days also has faults
//
// @PrimaryKey
// private String id;
// private long startDate = -1;
//
// public SensorData() {}
//
// public SensorData(RawTagData rawTagData) {
// id = String.format(Locale.US, "sensor_%s", rawTagData.getTagId());
// startDate = rawTagData.getDate() - (rawTagData.getDate() % TimeUnit.MINUTES.toMillis(1))
// - TimeUnit.MINUTES.toMillis(rawTagData.getSensorAgeInMinutes());
// }
//
// public SensorData(SensorData sensor) {
// this.id = sensor.id;
// this.startDate = sensor.getStartDate();
// }
//
// public String getTagId() {
// return id.substring(7);
// }
//
// public long getTimeLeft() {
// return max(0, startDate + TimeUnit.MINUTES.toMillis(maxSensorAgeInMinutes) - System.currentTimeMillis());
// }
//
// public long getStartDate() {
// return startDate;
// }
//
// public String getId() {
// return id;
// }
// }
//
// Path: app/src/main/java/de/dorianscholz/openlibre/OpenLibre.java
// public static RealmConfiguration realmConfigProcessedData;
//
// Path: app/src/main/java/de/dorianscholz/openlibre/model/AlgorithmUtil.java
// public static String getDurationBreakdown(Resources resources, long duration)
// {
// duration = max(0, duration);
//
// long days = TimeUnit.MILLISECONDS.toDays(duration);
// duration -= TimeUnit.DAYS.toMillis(days);
// long hours = TimeUnit.MILLISECONDS.toHours(duration);
// duration -= TimeUnit.HOURS.toMillis(hours);
// long minutes = TimeUnit.MILLISECONDS.toMinutes(duration);
//
// if (days > 1) {
// return days + " " + resources.getString(R.string.days);
// }
// if (days == 1) {
// return "1 " + resources.getString(R.string.day);
// }
// if (hours > 1) {
// return hours + " " + resources.getString(R.string.hours);
// }
// if (hours == 1) {
// return "1 " + resources.getString(R.string.hour);
// }
// if (minutes > 1) {
// return minutes + " " + resources.getString(R.string.minutes);
// }
// if (minutes == 1) {
// return "1 " + resources.getString(R.string.minute);
// }
//
// return "0 " + resources.getString(R.string.minutes);
// }
//
// Path: app/src/main/java/de/dorianscholz/openlibre/model/SensorData.java
// public static final String START_DATE = "startDate";
// Path: app/src/main/java/de/dorianscholz/openlibre/ui/SensorStatusFragment.java
import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.DialogFragment;
import android.support.v7.app.AlertDialog;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import java.text.DateFormat;
import java.util.Date;
import java.util.concurrent.TimeUnit;
import de.dorianscholz.openlibre.R;
import de.dorianscholz.openlibre.model.SensorData;
import io.realm.Realm;
import io.realm.RealmResults;
import io.realm.Sort;
import static de.dorianscholz.openlibre.OpenLibre.realmConfigProcessedData;
import static de.dorianscholz.openlibre.model.AlgorithmUtil.getDurationBreakdown;
import static de.dorianscholz.openlibre.model.SensorData.START_DATE;
package de.dorianscholz.openlibre.ui;
public class SensorStatusFragment extends DialogFragment {
public SensorStatusFragment() {
// Required empty public constructor
}
public static SensorStatusFragment newInstance() {
SensorStatusFragment fragment = new SensorStatusFragment();
Bundle args = new Bundle();
fragment.setArguments(args);
return fragment;
}
public void setupUi(View view) {
Realm realmProcessedData = Realm.getInstance(realmConfigProcessedData);
RealmResults<SensorData> sensorDataResults = realmProcessedData.where(SensorData.class). | findAllSorted(START_DATE, Sort.DESCENDING); |
DorianScholz/OpenLibre | app/src/main/java/de/dorianscholz/openlibre/ui/SensorStatusFragment.java | // Path: app/src/main/java/de/dorianscholz/openlibre/model/SensorData.java
// public class SensorData extends RealmObject {
// public static final String ID = "id";
// public static final String START_DATE = "startDate";
//
// public static final long minSensorAgeInMinutes = 60; // data generated by the sensor in the first 60 minutes is not correct
// public static final long maxSensorAgeInMinutes = TimeUnit.DAYS.toMinutes(14); // data generated by the sensor after 14 days also has faults
//
// @PrimaryKey
// private String id;
// private long startDate = -1;
//
// public SensorData() {}
//
// public SensorData(RawTagData rawTagData) {
// id = String.format(Locale.US, "sensor_%s", rawTagData.getTagId());
// startDate = rawTagData.getDate() - (rawTagData.getDate() % TimeUnit.MINUTES.toMillis(1))
// - TimeUnit.MINUTES.toMillis(rawTagData.getSensorAgeInMinutes());
// }
//
// public SensorData(SensorData sensor) {
// this.id = sensor.id;
// this.startDate = sensor.getStartDate();
// }
//
// public String getTagId() {
// return id.substring(7);
// }
//
// public long getTimeLeft() {
// return max(0, startDate + TimeUnit.MINUTES.toMillis(maxSensorAgeInMinutes) - System.currentTimeMillis());
// }
//
// public long getStartDate() {
// return startDate;
// }
//
// public String getId() {
// return id;
// }
// }
//
// Path: app/src/main/java/de/dorianscholz/openlibre/OpenLibre.java
// public static RealmConfiguration realmConfigProcessedData;
//
// Path: app/src/main/java/de/dorianscholz/openlibre/model/AlgorithmUtil.java
// public static String getDurationBreakdown(Resources resources, long duration)
// {
// duration = max(0, duration);
//
// long days = TimeUnit.MILLISECONDS.toDays(duration);
// duration -= TimeUnit.DAYS.toMillis(days);
// long hours = TimeUnit.MILLISECONDS.toHours(duration);
// duration -= TimeUnit.HOURS.toMillis(hours);
// long minutes = TimeUnit.MILLISECONDS.toMinutes(duration);
//
// if (days > 1) {
// return days + " " + resources.getString(R.string.days);
// }
// if (days == 1) {
// return "1 " + resources.getString(R.string.day);
// }
// if (hours > 1) {
// return hours + " " + resources.getString(R.string.hours);
// }
// if (hours == 1) {
// return "1 " + resources.getString(R.string.hour);
// }
// if (minutes > 1) {
// return minutes + " " + resources.getString(R.string.minutes);
// }
// if (minutes == 1) {
// return "1 " + resources.getString(R.string.minute);
// }
//
// return "0 " + resources.getString(R.string.minutes);
// }
//
// Path: app/src/main/java/de/dorianscholz/openlibre/model/SensorData.java
// public static final String START_DATE = "startDate";
| import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.DialogFragment;
import android.support.v7.app.AlertDialog;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import java.text.DateFormat;
import java.util.Date;
import java.util.concurrent.TimeUnit;
import de.dorianscholz.openlibre.R;
import de.dorianscholz.openlibre.model.SensorData;
import io.realm.Realm;
import io.realm.RealmResults;
import io.realm.Sort;
import static de.dorianscholz.openlibre.OpenLibre.realmConfigProcessedData;
import static de.dorianscholz.openlibre.model.AlgorithmUtil.getDurationBreakdown;
import static de.dorianscholz.openlibre.model.SensorData.START_DATE; | package de.dorianscholz.openlibre.ui;
public class SensorStatusFragment extends DialogFragment {
public SensorStatusFragment() {
// Required empty public constructor
}
public static SensorStatusFragment newInstance() {
SensorStatusFragment fragment = new SensorStatusFragment();
Bundle args = new Bundle();
fragment.setArguments(args);
return fragment;
}
public void setupUi(View view) {
Realm realmProcessedData = Realm.getInstance(realmConfigProcessedData);
RealmResults<SensorData> sensorDataResults = realmProcessedData.where(SensorData.class).
findAllSorted(START_DATE, Sort.DESCENDING);
TextView sensorId = (TextView) view.findViewById(R.id.tv_sensor_id_value);
TextView sensorStartDate = (TextView) view.findViewById(R.id.tv_sensor_start_date_value);
TextView sensorEndsIn = (TextView) view.findViewById(R.id.tv_sensor_ends_in_value);
if (sensorDataResults.size() == 0) {
sensorId.setText(getResources().getString(R.string.no_sensor_registered));
sensorStartDate.setText("");
sensorEndsIn.setText("");
} else {
SensorData sensorData = sensorDataResults.first();
sensorId.setText(sensorData.getTagId());
DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.SHORT);
sensorStartDate.setText(dateFormat.format(new Date(sensorData.getStartDate())));
long timeLeft = sensorData.getTimeLeft();
if (timeLeft >= TimeUnit.MINUTES.toMillis(1L)) { | // Path: app/src/main/java/de/dorianscholz/openlibre/model/SensorData.java
// public class SensorData extends RealmObject {
// public static final String ID = "id";
// public static final String START_DATE = "startDate";
//
// public static final long minSensorAgeInMinutes = 60; // data generated by the sensor in the first 60 minutes is not correct
// public static final long maxSensorAgeInMinutes = TimeUnit.DAYS.toMinutes(14); // data generated by the sensor after 14 days also has faults
//
// @PrimaryKey
// private String id;
// private long startDate = -1;
//
// public SensorData() {}
//
// public SensorData(RawTagData rawTagData) {
// id = String.format(Locale.US, "sensor_%s", rawTagData.getTagId());
// startDate = rawTagData.getDate() - (rawTagData.getDate() % TimeUnit.MINUTES.toMillis(1))
// - TimeUnit.MINUTES.toMillis(rawTagData.getSensorAgeInMinutes());
// }
//
// public SensorData(SensorData sensor) {
// this.id = sensor.id;
// this.startDate = sensor.getStartDate();
// }
//
// public String getTagId() {
// return id.substring(7);
// }
//
// public long getTimeLeft() {
// return max(0, startDate + TimeUnit.MINUTES.toMillis(maxSensorAgeInMinutes) - System.currentTimeMillis());
// }
//
// public long getStartDate() {
// return startDate;
// }
//
// public String getId() {
// return id;
// }
// }
//
// Path: app/src/main/java/de/dorianscholz/openlibre/OpenLibre.java
// public static RealmConfiguration realmConfigProcessedData;
//
// Path: app/src/main/java/de/dorianscholz/openlibre/model/AlgorithmUtil.java
// public static String getDurationBreakdown(Resources resources, long duration)
// {
// duration = max(0, duration);
//
// long days = TimeUnit.MILLISECONDS.toDays(duration);
// duration -= TimeUnit.DAYS.toMillis(days);
// long hours = TimeUnit.MILLISECONDS.toHours(duration);
// duration -= TimeUnit.HOURS.toMillis(hours);
// long minutes = TimeUnit.MILLISECONDS.toMinutes(duration);
//
// if (days > 1) {
// return days + " " + resources.getString(R.string.days);
// }
// if (days == 1) {
// return "1 " + resources.getString(R.string.day);
// }
// if (hours > 1) {
// return hours + " " + resources.getString(R.string.hours);
// }
// if (hours == 1) {
// return "1 " + resources.getString(R.string.hour);
// }
// if (minutes > 1) {
// return minutes + " " + resources.getString(R.string.minutes);
// }
// if (minutes == 1) {
// return "1 " + resources.getString(R.string.minute);
// }
//
// return "0 " + resources.getString(R.string.minutes);
// }
//
// Path: app/src/main/java/de/dorianscholz/openlibre/model/SensorData.java
// public static final String START_DATE = "startDate";
// Path: app/src/main/java/de/dorianscholz/openlibre/ui/SensorStatusFragment.java
import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.DialogFragment;
import android.support.v7.app.AlertDialog;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import java.text.DateFormat;
import java.util.Date;
import java.util.concurrent.TimeUnit;
import de.dorianscholz.openlibre.R;
import de.dorianscholz.openlibre.model.SensorData;
import io.realm.Realm;
import io.realm.RealmResults;
import io.realm.Sort;
import static de.dorianscholz.openlibre.OpenLibre.realmConfigProcessedData;
import static de.dorianscholz.openlibre.model.AlgorithmUtil.getDurationBreakdown;
import static de.dorianscholz.openlibre.model.SensorData.START_DATE;
package de.dorianscholz.openlibre.ui;
public class SensorStatusFragment extends DialogFragment {
public SensorStatusFragment() {
// Required empty public constructor
}
public static SensorStatusFragment newInstance() {
SensorStatusFragment fragment = new SensorStatusFragment();
Bundle args = new Bundle();
fragment.setArguments(args);
return fragment;
}
public void setupUi(View view) {
Realm realmProcessedData = Realm.getInstance(realmConfigProcessedData);
RealmResults<SensorData> sensorDataResults = realmProcessedData.where(SensorData.class).
findAllSorted(START_DATE, Sort.DESCENDING);
TextView sensorId = (TextView) view.findViewById(R.id.tv_sensor_id_value);
TextView sensorStartDate = (TextView) view.findViewById(R.id.tv_sensor_start_date_value);
TextView sensorEndsIn = (TextView) view.findViewById(R.id.tv_sensor_ends_in_value);
if (sensorDataResults.size() == 0) {
sensorId.setText(getResources().getString(R.string.no_sensor_registered));
sensorStartDate.setText("");
sensorEndsIn.setText("");
} else {
SensorData sensorData = sensorDataResults.first();
sensorId.setText(sensorData.getTagId());
DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.SHORT);
sensorStartDate.setText(dateFormat.format(new Date(sensorData.getStartDate())));
long timeLeft = sensorData.getTimeLeft();
if (timeLeft >= TimeUnit.MINUTES.toMillis(1L)) { | sensorEndsIn.setText(getDurationBreakdown(getResources(), sensorData.getTimeLeft())); |
DorianScholz/OpenLibre | app/src/main/java/de/dorianscholz/openlibre/ui/SettingsActivity.java | // Path: app/src/main/java/de/dorianscholz/openlibre/OpenLibre.java
// public static float GLUCOSE_TARGET_MAX = 140;
//
// Path: app/src/main/java/de/dorianscholz/openlibre/OpenLibre.java
// public static float GLUCOSE_TARGET_MIN = 80;
//
// Path: app/src/main/java/de/dorianscholz/openlibre/OpenLibre.java
// public static boolean GLUCOSE_UNIT_IS_MMOL = false;
//
// Path: app/src/main/java/de/dorianscholz/openlibre/OpenLibre.java
// public static void refreshApplicationSettings(SharedPreferences settings) {
// // read settings values
// NFC_USE_MULTI_BLOCK_READ = settings.getBoolean("pref_nfc_use_multi_block_read", NFC_USE_MULTI_BLOCK_READ);
// GLUCOSE_UNIT_IS_MMOL = settings.getBoolean("pref_glucose_unit_is_mmol", GLUCOSE_UNIT_IS_MMOL);
// GLUCOSE_TARGET_MIN = Float.parseFloat(settings.getString("pref_glucose_target_min", Float.toString(GLUCOSE_TARGET_MIN)));
// GLUCOSE_TARGET_MAX = Float.parseFloat(settings.getString("pref_glucose_target_max", Float.toString(GLUCOSE_TARGET_MAX)));
// }
//
// Path: app/src/main/java/de/dorianscholz/openlibre/model/GlucoseData.java
// public static float convertGlucoseMGDLToMMOL(float mgdl) {
// return mgdl / 18f;
// }
//
// Path: app/src/main/java/de/dorianscholz/openlibre/model/GlucoseData.java
// public static float convertGlucoseMMOLToMGDL(float mmol) {
// return mmol * 18f;
// }
| import android.app.Activity;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.renderscript.Float2;
import io.tidepool.api.APIClient;
import static de.dorianscholz.openlibre.OpenLibre.GLUCOSE_TARGET_MAX;
import static de.dorianscholz.openlibre.OpenLibre.GLUCOSE_TARGET_MIN;
import static de.dorianscholz.openlibre.OpenLibre.GLUCOSE_UNIT_IS_MMOL;
import static de.dorianscholz.openlibre.OpenLibre.refreshApplicationSettings;
import static de.dorianscholz.openlibre.model.GlucoseData.convertGlucoseMGDLToMMOL;
import static de.dorianscholz.openlibre.model.GlucoseData.convertGlucoseMMOLToMGDL; | package de.dorianscholz.openlibre.ui;
public class SettingsActivity extends Activity implements SharedPreferences.OnSharedPreferenceChangeListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
PreferenceManager.getDefaultSharedPreferences(this).registerOnSharedPreferenceChangeListener(this);
// Display the fragment as the main content.
getFragmentManager().beginTransaction()
.replace(android.R.id.content, new SettingsFragment())
.commit();
}
@Override
public void onSharedPreferenceChanged(SharedPreferences settings, String key) {
// when username or server changes update the key for the sync progress
if (key.equals("pref_tidepool_username") || key.equals("pref_tidepool_server")) {
// trim spaces off of email address
String tidepoolUsername = settings.getString("pref_tidepool_username", "").trim();
SharedPreferences.Editor editor = settings.edit();
editor.putString("pref_tidepool_username", tidepoolUsername);
editor.apply();
String tidepoolServer = settings.getString("pref_tidepool_server", APIClient.PRODUCTION);
SharedPreferences.Editor preferencesEditor = getApplicationContext().getSharedPreferences("tidepool", MODE_PRIVATE).edit();
preferencesEditor.putString("upload_timestamp_key", "upload_timestamp_for_" + tidepoolUsername.toLowerCase() + "_at_" + tidepoolServer);
preferencesEditor.apply();
}
if (key.equals("pref_glucose_unit_is_mmol")) { | // Path: app/src/main/java/de/dorianscholz/openlibre/OpenLibre.java
// public static float GLUCOSE_TARGET_MAX = 140;
//
// Path: app/src/main/java/de/dorianscholz/openlibre/OpenLibre.java
// public static float GLUCOSE_TARGET_MIN = 80;
//
// Path: app/src/main/java/de/dorianscholz/openlibre/OpenLibre.java
// public static boolean GLUCOSE_UNIT_IS_MMOL = false;
//
// Path: app/src/main/java/de/dorianscholz/openlibre/OpenLibre.java
// public static void refreshApplicationSettings(SharedPreferences settings) {
// // read settings values
// NFC_USE_MULTI_BLOCK_READ = settings.getBoolean("pref_nfc_use_multi_block_read", NFC_USE_MULTI_BLOCK_READ);
// GLUCOSE_UNIT_IS_MMOL = settings.getBoolean("pref_glucose_unit_is_mmol", GLUCOSE_UNIT_IS_MMOL);
// GLUCOSE_TARGET_MIN = Float.parseFloat(settings.getString("pref_glucose_target_min", Float.toString(GLUCOSE_TARGET_MIN)));
// GLUCOSE_TARGET_MAX = Float.parseFloat(settings.getString("pref_glucose_target_max", Float.toString(GLUCOSE_TARGET_MAX)));
// }
//
// Path: app/src/main/java/de/dorianscholz/openlibre/model/GlucoseData.java
// public static float convertGlucoseMGDLToMMOL(float mgdl) {
// return mgdl / 18f;
// }
//
// Path: app/src/main/java/de/dorianscholz/openlibre/model/GlucoseData.java
// public static float convertGlucoseMMOLToMGDL(float mmol) {
// return mmol * 18f;
// }
// Path: app/src/main/java/de/dorianscholz/openlibre/ui/SettingsActivity.java
import android.app.Activity;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.renderscript.Float2;
import io.tidepool.api.APIClient;
import static de.dorianscholz.openlibre.OpenLibre.GLUCOSE_TARGET_MAX;
import static de.dorianscholz.openlibre.OpenLibre.GLUCOSE_TARGET_MIN;
import static de.dorianscholz.openlibre.OpenLibre.GLUCOSE_UNIT_IS_MMOL;
import static de.dorianscholz.openlibre.OpenLibre.refreshApplicationSettings;
import static de.dorianscholz.openlibre.model.GlucoseData.convertGlucoseMGDLToMMOL;
import static de.dorianscholz.openlibre.model.GlucoseData.convertGlucoseMMOLToMGDL;
package de.dorianscholz.openlibre.ui;
public class SettingsActivity extends Activity implements SharedPreferences.OnSharedPreferenceChangeListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
PreferenceManager.getDefaultSharedPreferences(this).registerOnSharedPreferenceChangeListener(this);
// Display the fragment as the main content.
getFragmentManager().beginTransaction()
.replace(android.R.id.content, new SettingsFragment())
.commit();
}
@Override
public void onSharedPreferenceChanged(SharedPreferences settings, String key) {
// when username or server changes update the key for the sync progress
if (key.equals("pref_tidepool_username") || key.equals("pref_tidepool_server")) {
// trim spaces off of email address
String tidepoolUsername = settings.getString("pref_tidepool_username", "").trim();
SharedPreferences.Editor editor = settings.edit();
editor.putString("pref_tidepool_username", tidepoolUsername);
editor.apply();
String tidepoolServer = settings.getString("pref_tidepool_server", APIClient.PRODUCTION);
SharedPreferences.Editor preferencesEditor = getApplicationContext().getSharedPreferences("tidepool", MODE_PRIVATE).edit();
preferencesEditor.putString("upload_timestamp_key", "upload_timestamp_for_" + tidepoolUsername.toLowerCase() + "_at_" + tidepoolServer);
preferencesEditor.apply();
}
if (key.equals("pref_glucose_unit_is_mmol")) { | GLUCOSE_UNIT_IS_MMOL = settings.getBoolean("pref_glucose_unit_is_mmol", GLUCOSE_UNIT_IS_MMOL); |
DorianScholz/OpenLibre | app/src/main/java/de/dorianscholz/openlibre/ui/SettingsActivity.java | // Path: app/src/main/java/de/dorianscholz/openlibre/OpenLibre.java
// public static float GLUCOSE_TARGET_MAX = 140;
//
// Path: app/src/main/java/de/dorianscholz/openlibre/OpenLibre.java
// public static float GLUCOSE_TARGET_MIN = 80;
//
// Path: app/src/main/java/de/dorianscholz/openlibre/OpenLibre.java
// public static boolean GLUCOSE_UNIT_IS_MMOL = false;
//
// Path: app/src/main/java/de/dorianscholz/openlibre/OpenLibre.java
// public static void refreshApplicationSettings(SharedPreferences settings) {
// // read settings values
// NFC_USE_MULTI_BLOCK_READ = settings.getBoolean("pref_nfc_use_multi_block_read", NFC_USE_MULTI_BLOCK_READ);
// GLUCOSE_UNIT_IS_MMOL = settings.getBoolean("pref_glucose_unit_is_mmol", GLUCOSE_UNIT_IS_MMOL);
// GLUCOSE_TARGET_MIN = Float.parseFloat(settings.getString("pref_glucose_target_min", Float.toString(GLUCOSE_TARGET_MIN)));
// GLUCOSE_TARGET_MAX = Float.parseFloat(settings.getString("pref_glucose_target_max", Float.toString(GLUCOSE_TARGET_MAX)));
// }
//
// Path: app/src/main/java/de/dorianscholz/openlibre/model/GlucoseData.java
// public static float convertGlucoseMGDLToMMOL(float mgdl) {
// return mgdl / 18f;
// }
//
// Path: app/src/main/java/de/dorianscholz/openlibre/model/GlucoseData.java
// public static float convertGlucoseMMOLToMGDL(float mmol) {
// return mmol * 18f;
// }
| import android.app.Activity;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.renderscript.Float2;
import io.tidepool.api.APIClient;
import static de.dorianscholz.openlibre.OpenLibre.GLUCOSE_TARGET_MAX;
import static de.dorianscholz.openlibre.OpenLibre.GLUCOSE_TARGET_MIN;
import static de.dorianscholz.openlibre.OpenLibre.GLUCOSE_UNIT_IS_MMOL;
import static de.dorianscholz.openlibre.OpenLibre.refreshApplicationSettings;
import static de.dorianscholz.openlibre.model.GlucoseData.convertGlucoseMGDLToMMOL;
import static de.dorianscholz.openlibre.model.GlucoseData.convertGlucoseMMOLToMGDL; | package de.dorianscholz.openlibre.ui;
public class SettingsActivity extends Activity implements SharedPreferences.OnSharedPreferenceChangeListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
PreferenceManager.getDefaultSharedPreferences(this).registerOnSharedPreferenceChangeListener(this);
// Display the fragment as the main content.
getFragmentManager().beginTransaction()
.replace(android.R.id.content, new SettingsFragment())
.commit();
}
@Override
public void onSharedPreferenceChanged(SharedPreferences settings, String key) {
// when username or server changes update the key for the sync progress
if (key.equals("pref_tidepool_username") || key.equals("pref_tidepool_server")) {
// trim spaces off of email address
String tidepoolUsername = settings.getString("pref_tidepool_username", "").trim();
SharedPreferences.Editor editor = settings.edit();
editor.putString("pref_tidepool_username", tidepoolUsername);
editor.apply();
String tidepoolServer = settings.getString("pref_tidepool_server", APIClient.PRODUCTION);
SharedPreferences.Editor preferencesEditor = getApplicationContext().getSharedPreferences("tidepool", MODE_PRIVATE).edit();
preferencesEditor.putString("upload_timestamp_key", "upload_timestamp_for_" + tidepoolUsername.toLowerCase() + "_at_" + tidepoolServer);
preferencesEditor.apply();
}
if (key.equals("pref_glucose_unit_is_mmol")) {
GLUCOSE_UNIT_IS_MMOL = settings.getBoolean("pref_glucose_unit_is_mmol", GLUCOSE_UNIT_IS_MMOL);
SharedPreferences.Editor editor = settings.edit();
if (GLUCOSE_UNIT_IS_MMOL) { | // Path: app/src/main/java/de/dorianscholz/openlibre/OpenLibre.java
// public static float GLUCOSE_TARGET_MAX = 140;
//
// Path: app/src/main/java/de/dorianscholz/openlibre/OpenLibre.java
// public static float GLUCOSE_TARGET_MIN = 80;
//
// Path: app/src/main/java/de/dorianscholz/openlibre/OpenLibre.java
// public static boolean GLUCOSE_UNIT_IS_MMOL = false;
//
// Path: app/src/main/java/de/dorianscholz/openlibre/OpenLibre.java
// public static void refreshApplicationSettings(SharedPreferences settings) {
// // read settings values
// NFC_USE_MULTI_BLOCK_READ = settings.getBoolean("pref_nfc_use_multi_block_read", NFC_USE_MULTI_BLOCK_READ);
// GLUCOSE_UNIT_IS_MMOL = settings.getBoolean("pref_glucose_unit_is_mmol", GLUCOSE_UNIT_IS_MMOL);
// GLUCOSE_TARGET_MIN = Float.parseFloat(settings.getString("pref_glucose_target_min", Float.toString(GLUCOSE_TARGET_MIN)));
// GLUCOSE_TARGET_MAX = Float.parseFloat(settings.getString("pref_glucose_target_max", Float.toString(GLUCOSE_TARGET_MAX)));
// }
//
// Path: app/src/main/java/de/dorianscholz/openlibre/model/GlucoseData.java
// public static float convertGlucoseMGDLToMMOL(float mgdl) {
// return mgdl / 18f;
// }
//
// Path: app/src/main/java/de/dorianscholz/openlibre/model/GlucoseData.java
// public static float convertGlucoseMMOLToMGDL(float mmol) {
// return mmol * 18f;
// }
// Path: app/src/main/java/de/dorianscholz/openlibre/ui/SettingsActivity.java
import android.app.Activity;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.renderscript.Float2;
import io.tidepool.api.APIClient;
import static de.dorianscholz.openlibre.OpenLibre.GLUCOSE_TARGET_MAX;
import static de.dorianscholz.openlibre.OpenLibre.GLUCOSE_TARGET_MIN;
import static de.dorianscholz.openlibre.OpenLibre.GLUCOSE_UNIT_IS_MMOL;
import static de.dorianscholz.openlibre.OpenLibre.refreshApplicationSettings;
import static de.dorianscholz.openlibre.model.GlucoseData.convertGlucoseMGDLToMMOL;
import static de.dorianscholz.openlibre.model.GlucoseData.convertGlucoseMMOLToMGDL;
package de.dorianscholz.openlibre.ui;
public class SettingsActivity extends Activity implements SharedPreferences.OnSharedPreferenceChangeListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
PreferenceManager.getDefaultSharedPreferences(this).registerOnSharedPreferenceChangeListener(this);
// Display the fragment as the main content.
getFragmentManager().beginTransaction()
.replace(android.R.id.content, new SettingsFragment())
.commit();
}
@Override
public void onSharedPreferenceChanged(SharedPreferences settings, String key) {
// when username or server changes update the key for the sync progress
if (key.equals("pref_tidepool_username") || key.equals("pref_tidepool_server")) {
// trim spaces off of email address
String tidepoolUsername = settings.getString("pref_tidepool_username", "").trim();
SharedPreferences.Editor editor = settings.edit();
editor.putString("pref_tidepool_username", tidepoolUsername);
editor.apply();
String tidepoolServer = settings.getString("pref_tidepool_server", APIClient.PRODUCTION);
SharedPreferences.Editor preferencesEditor = getApplicationContext().getSharedPreferences("tidepool", MODE_PRIVATE).edit();
preferencesEditor.putString("upload_timestamp_key", "upload_timestamp_for_" + tidepoolUsername.toLowerCase() + "_at_" + tidepoolServer);
preferencesEditor.apply();
}
if (key.equals("pref_glucose_unit_is_mmol")) {
GLUCOSE_UNIT_IS_MMOL = settings.getBoolean("pref_glucose_unit_is_mmol", GLUCOSE_UNIT_IS_MMOL);
SharedPreferences.Editor editor = settings.edit();
if (GLUCOSE_UNIT_IS_MMOL) { | editor.putString("pref_glucose_target_min", Float.toString(convertGlucoseMGDLToMMOL(GLUCOSE_TARGET_MIN))); |
DorianScholz/OpenLibre | app/src/main/java/de/dorianscholz/openlibre/ui/SettingsActivity.java | // Path: app/src/main/java/de/dorianscholz/openlibre/OpenLibre.java
// public static float GLUCOSE_TARGET_MAX = 140;
//
// Path: app/src/main/java/de/dorianscholz/openlibre/OpenLibre.java
// public static float GLUCOSE_TARGET_MIN = 80;
//
// Path: app/src/main/java/de/dorianscholz/openlibre/OpenLibre.java
// public static boolean GLUCOSE_UNIT_IS_MMOL = false;
//
// Path: app/src/main/java/de/dorianscholz/openlibre/OpenLibre.java
// public static void refreshApplicationSettings(SharedPreferences settings) {
// // read settings values
// NFC_USE_MULTI_BLOCK_READ = settings.getBoolean("pref_nfc_use_multi_block_read", NFC_USE_MULTI_BLOCK_READ);
// GLUCOSE_UNIT_IS_MMOL = settings.getBoolean("pref_glucose_unit_is_mmol", GLUCOSE_UNIT_IS_MMOL);
// GLUCOSE_TARGET_MIN = Float.parseFloat(settings.getString("pref_glucose_target_min", Float.toString(GLUCOSE_TARGET_MIN)));
// GLUCOSE_TARGET_MAX = Float.parseFloat(settings.getString("pref_glucose_target_max", Float.toString(GLUCOSE_TARGET_MAX)));
// }
//
// Path: app/src/main/java/de/dorianscholz/openlibre/model/GlucoseData.java
// public static float convertGlucoseMGDLToMMOL(float mgdl) {
// return mgdl / 18f;
// }
//
// Path: app/src/main/java/de/dorianscholz/openlibre/model/GlucoseData.java
// public static float convertGlucoseMMOLToMGDL(float mmol) {
// return mmol * 18f;
// }
| import android.app.Activity;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.renderscript.Float2;
import io.tidepool.api.APIClient;
import static de.dorianscholz.openlibre.OpenLibre.GLUCOSE_TARGET_MAX;
import static de.dorianscholz.openlibre.OpenLibre.GLUCOSE_TARGET_MIN;
import static de.dorianscholz.openlibre.OpenLibre.GLUCOSE_UNIT_IS_MMOL;
import static de.dorianscholz.openlibre.OpenLibre.refreshApplicationSettings;
import static de.dorianscholz.openlibre.model.GlucoseData.convertGlucoseMGDLToMMOL;
import static de.dorianscholz.openlibre.model.GlucoseData.convertGlucoseMMOLToMGDL; | package de.dorianscholz.openlibre.ui;
public class SettingsActivity extends Activity implements SharedPreferences.OnSharedPreferenceChangeListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
PreferenceManager.getDefaultSharedPreferences(this).registerOnSharedPreferenceChangeListener(this);
// Display the fragment as the main content.
getFragmentManager().beginTransaction()
.replace(android.R.id.content, new SettingsFragment())
.commit();
}
@Override
public void onSharedPreferenceChanged(SharedPreferences settings, String key) {
// when username or server changes update the key for the sync progress
if (key.equals("pref_tidepool_username") || key.equals("pref_tidepool_server")) {
// trim spaces off of email address
String tidepoolUsername = settings.getString("pref_tidepool_username", "").trim();
SharedPreferences.Editor editor = settings.edit();
editor.putString("pref_tidepool_username", tidepoolUsername);
editor.apply();
String tidepoolServer = settings.getString("pref_tidepool_server", APIClient.PRODUCTION);
SharedPreferences.Editor preferencesEditor = getApplicationContext().getSharedPreferences("tidepool", MODE_PRIVATE).edit();
preferencesEditor.putString("upload_timestamp_key", "upload_timestamp_for_" + tidepoolUsername.toLowerCase() + "_at_" + tidepoolServer);
preferencesEditor.apply();
}
if (key.equals("pref_glucose_unit_is_mmol")) {
GLUCOSE_UNIT_IS_MMOL = settings.getBoolean("pref_glucose_unit_is_mmol", GLUCOSE_UNIT_IS_MMOL);
SharedPreferences.Editor editor = settings.edit();
if (GLUCOSE_UNIT_IS_MMOL) { | // Path: app/src/main/java/de/dorianscholz/openlibre/OpenLibre.java
// public static float GLUCOSE_TARGET_MAX = 140;
//
// Path: app/src/main/java/de/dorianscholz/openlibre/OpenLibre.java
// public static float GLUCOSE_TARGET_MIN = 80;
//
// Path: app/src/main/java/de/dorianscholz/openlibre/OpenLibre.java
// public static boolean GLUCOSE_UNIT_IS_MMOL = false;
//
// Path: app/src/main/java/de/dorianscholz/openlibre/OpenLibre.java
// public static void refreshApplicationSettings(SharedPreferences settings) {
// // read settings values
// NFC_USE_MULTI_BLOCK_READ = settings.getBoolean("pref_nfc_use_multi_block_read", NFC_USE_MULTI_BLOCK_READ);
// GLUCOSE_UNIT_IS_MMOL = settings.getBoolean("pref_glucose_unit_is_mmol", GLUCOSE_UNIT_IS_MMOL);
// GLUCOSE_TARGET_MIN = Float.parseFloat(settings.getString("pref_glucose_target_min", Float.toString(GLUCOSE_TARGET_MIN)));
// GLUCOSE_TARGET_MAX = Float.parseFloat(settings.getString("pref_glucose_target_max", Float.toString(GLUCOSE_TARGET_MAX)));
// }
//
// Path: app/src/main/java/de/dorianscholz/openlibre/model/GlucoseData.java
// public static float convertGlucoseMGDLToMMOL(float mgdl) {
// return mgdl / 18f;
// }
//
// Path: app/src/main/java/de/dorianscholz/openlibre/model/GlucoseData.java
// public static float convertGlucoseMMOLToMGDL(float mmol) {
// return mmol * 18f;
// }
// Path: app/src/main/java/de/dorianscholz/openlibre/ui/SettingsActivity.java
import android.app.Activity;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.renderscript.Float2;
import io.tidepool.api.APIClient;
import static de.dorianscholz.openlibre.OpenLibre.GLUCOSE_TARGET_MAX;
import static de.dorianscholz.openlibre.OpenLibre.GLUCOSE_TARGET_MIN;
import static de.dorianscholz.openlibre.OpenLibre.GLUCOSE_UNIT_IS_MMOL;
import static de.dorianscholz.openlibre.OpenLibre.refreshApplicationSettings;
import static de.dorianscholz.openlibre.model.GlucoseData.convertGlucoseMGDLToMMOL;
import static de.dorianscholz.openlibre.model.GlucoseData.convertGlucoseMMOLToMGDL;
package de.dorianscholz.openlibre.ui;
public class SettingsActivity extends Activity implements SharedPreferences.OnSharedPreferenceChangeListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
PreferenceManager.getDefaultSharedPreferences(this).registerOnSharedPreferenceChangeListener(this);
// Display the fragment as the main content.
getFragmentManager().beginTransaction()
.replace(android.R.id.content, new SettingsFragment())
.commit();
}
@Override
public void onSharedPreferenceChanged(SharedPreferences settings, String key) {
// when username or server changes update the key for the sync progress
if (key.equals("pref_tidepool_username") || key.equals("pref_tidepool_server")) {
// trim spaces off of email address
String tidepoolUsername = settings.getString("pref_tidepool_username", "").trim();
SharedPreferences.Editor editor = settings.edit();
editor.putString("pref_tidepool_username", tidepoolUsername);
editor.apply();
String tidepoolServer = settings.getString("pref_tidepool_server", APIClient.PRODUCTION);
SharedPreferences.Editor preferencesEditor = getApplicationContext().getSharedPreferences("tidepool", MODE_PRIVATE).edit();
preferencesEditor.putString("upload_timestamp_key", "upload_timestamp_for_" + tidepoolUsername.toLowerCase() + "_at_" + tidepoolServer);
preferencesEditor.apply();
}
if (key.equals("pref_glucose_unit_is_mmol")) {
GLUCOSE_UNIT_IS_MMOL = settings.getBoolean("pref_glucose_unit_is_mmol", GLUCOSE_UNIT_IS_MMOL);
SharedPreferences.Editor editor = settings.edit();
if (GLUCOSE_UNIT_IS_MMOL) { | editor.putString("pref_glucose_target_min", Float.toString(convertGlucoseMGDLToMMOL(GLUCOSE_TARGET_MIN))); |
DorianScholz/OpenLibre | app/src/main/java/de/dorianscholz/openlibre/ui/SettingsActivity.java | // Path: app/src/main/java/de/dorianscholz/openlibre/OpenLibre.java
// public static float GLUCOSE_TARGET_MAX = 140;
//
// Path: app/src/main/java/de/dorianscholz/openlibre/OpenLibre.java
// public static float GLUCOSE_TARGET_MIN = 80;
//
// Path: app/src/main/java/de/dorianscholz/openlibre/OpenLibre.java
// public static boolean GLUCOSE_UNIT_IS_MMOL = false;
//
// Path: app/src/main/java/de/dorianscholz/openlibre/OpenLibre.java
// public static void refreshApplicationSettings(SharedPreferences settings) {
// // read settings values
// NFC_USE_MULTI_BLOCK_READ = settings.getBoolean("pref_nfc_use_multi_block_read", NFC_USE_MULTI_BLOCK_READ);
// GLUCOSE_UNIT_IS_MMOL = settings.getBoolean("pref_glucose_unit_is_mmol", GLUCOSE_UNIT_IS_MMOL);
// GLUCOSE_TARGET_MIN = Float.parseFloat(settings.getString("pref_glucose_target_min", Float.toString(GLUCOSE_TARGET_MIN)));
// GLUCOSE_TARGET_MAX = Float.parseFloat(settings.getString("pref_glucose_target_max", Float.toString(GLUCOSE_TARGET_MAX)));
// }
//
// Path: app/src/main/java/de/dorianscholz/openlibre/model/GlucoseData.java
// public static float convertGlucoseMGDLToMMOL(float mgdl) {
// return mgdl / 18f;
// }
//
// Path: app/src/main/java/de/dorianscholz/openlibre/model/GlucoseData.java
// public static float convertGlucoseMMOLToMGDL(float mmol) {
// return mmol * 18f;
// }
| import android.app.Activity;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.renderscript.Float2;
import io.tidepool.api.APIClient;
import static de.dorianscholz.openlibre.OpenLibre.GLUCOSE_TARGET_MAX;
import static de.dorianscholz.openlibre.OpenLibre.GLUCOSE_TARGET_MIN;
import static de.dorianscholz.openlibre.OpenLibre.GLUCOSE_UNIT_IS_MMOL;
import static de.dorianscholz.openlibre.OpenLibre.refreshApplicationSettings;
import static de.dorianscholz.openlibre.model.GlucoseData.convertGlucoseMGDLToMMOL;
import static de.dorianscholz.openlibre.model.GlucoseData.convertGlucoseMMOLToMGDL; | package de.dorianscholz.openlibre.ui;
public class SettingsActivity extends Activity implements SharedPreferences.OnSharedPreferenceChangeListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
PreferenceManager.getDefaultSharedPreferences(this).registerOnSharedPreferenceChangeListener(this);
// Display the fragment as the main content.
getFragmentManager().beginTransaction()
.replace(android.R.id.content, new SettingsFragment())
.commit();
}
@Override
public void onSharedPreferenceChanged(SharedPreferences settings, String key) {
// when username or server changes update the key for the sync progress
if (key.equals("pref_tidepool_username") || key.equals("pref_tidepool_server")) {
// trim spaces off of email address
String tidepoolUsername = settings.getString("pref_tidepool_username", "").trim();
SharedPreferences.Editor editor = settings.edit();
editor.putString("pref_tidepool_username", tidepoolUsername);
editor.apply();
String tidepoolServer = settings.getString("pref_tidepool_server", APIClient.PRODUCTION);
SharedPreferences.Editor preferencesEditor = getApplicationContext().getSharedPreferences("tidepool", MODE_PRIVATE).edit();
preferencesEditor.putString("upload_timestamp_key", "upload_timestamp_for_" + tidepoolUsername.toLowerCase() + "_at_" + tidepoolServer);
preferencesEditor.apply();
}
if (key.equals("pref_glucose_unit_is_mmol")) {
GLUCOSE_UNIT_IS_MMOL = settings.getBoolean("pref_glucose_unit_is_mmol", GLUCOSE_UNIT_IS_MMOL);
SharedPreferences.Editor editor = settings.edit();
if (GLUCOSE_UNIT_IS_MMOL) {
editor.putString("pref_glucose_target_min", Float.toString(convertGlucoseMGDLToMMOL(GLUCOSE_TARGET_MIN))); | // Path: app/src/main/java/de/dorianscholz/openlibre/OpenLibre.java
// public static float GLUCOSE_TARGET_MAX = 140;
//
// Path: app/src/main/java/de/dorianscholz/openlibre/OpenLibre.java
// public static float GLUCOSE_TARGET_MIN = 80;
//
// Path: app/src/main/java/de/dorianscholz/openlibre/OpenLibre.java
// public static boolean GLUCOSE_UNIT_IS_MMOL = false;
//
// Path: app/src/main/java/de/dorianscholz/openlibre/OpenLibre.java
// public static void refreshApplicationSettings(SharedPreferences settings) {
// // read settings values
// NFC_USE_MULTI_BLOCK_READ = settings.getBoolean("pref_nfc_use_multi_block_read", NFC_USE_MULTI_BLOCK_READ);
// GLUCOSE_UNIT_IS_MMOL = settings.getBoolean("pref_glucose_unit_is_mmol", GLUCOSE_UNIT_IS_MMOL);
// GLUCOSE_TARGET_MIN = Float.parseFloat(settings.getString("pref_glucose_target_min", Float.toString(GLUCOSE_TARGET_MIN)));
// GLUCOSE_TARGET_MAX = Float.parseFloat(settings.getString("pref_glucose_target_max", Float.toString(GLUCOSE_TARGET_MAX)));
// }
//
// Path: app/src/main/java/de/dorianscholz/openlibre/model/GlucoseData.java
// public static float convertGlucoseMGDLToMMOL(float mgdl) {
// return mgdl / 18f;
// }
//
// Path: app/src/main/java/de/dorianscholz/openlibre/model/GlucoseData.java
// public static float convertGlucoseMMOLToMGDL(float mmol) {
// return mmol * 18f;
// }
// Path: app/src/main/java/de/dorianscholz/openlibre/ui/SettingsActivity.java
import android.app.Activity;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.renderscript.Float2;
import io.tidepool.api.APIClient;
import static de.dorianscholz.openlibre.OpenLibre.GLUCOSE_TARGET_MAX;
import static de.dorianscholz.openlibre.OpenLibre.GLUCOSE_TARGET_MIN;
import static de.dorianscholz.openlibre.OpenLibre.GLUCOSE_UNIT_IS_MMOL;
import static de.dorianscholz.openlibre.OpenLibre.refreshApplicationSettings;
import static de.dorianscholz.openlibre.model.GlucoseData.convertGlucoseMGDLToMMOL;
import static de.dorianscholz.openlibre.model.GlucoseData.convertGlucoseMMOLToMGDL;
package de.dorianscholz.openlibre.ui;
public class SettingsActivity extends Activity implements SharedPreferences.OnSharedPreferenceChangeListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
PreferenceManager.getDefaultSharedPreferences(this).registerOnSharedPreferenceChangeListener(this);
// Display the fragment as the main content.
getFragmentManager().beginTransaction()
.replace(android.R.id.content, new SettingsFragment())
.commit();
}
@Override
public void onSharedPreferenceChanged(SharedPreferences settings, String key) {
// when username or server changes update the key for the sync progress
if (key.equals("pref_tidepool_username") || key.equals("pref_tidepool_server")) {
// trim spaces off of email address
String tidepoolUsername = settings.getString("pref_tidepool_username", "").trim();
SharedPreferences.Editor editor = settings.edit();
editor.putString("pref_tidepool_username", tidepoolUsername);
editor.apply();
String tidepoolServer = settings.getString("pref_tidepool_server", APIClient.PRODUCTION);
SharedPreferences.Editor preferencesEditor = getApplicationContext().getSharedPreferences("tidepool", MODE_PRIVATE).edit();
preferencesEditor.putString("upload_timestamp_key", "upload_timestamp_for_" + tidepoolUsername.toLowerCase() + "_at_" + tidepoolServer);
preferencesEditor.apply();
}
if (key.equals("pref_glucose_unit_is_mmol")) {
GLUCOSE_UNIT_IS_MMOL = settings.getBoolean("pref_glucose_unit_is_mmol", GLUCOSE_UNIT_IS_MMOL);
SharedPreferences.Editor editor = settings.edit();
if (GLUCOSE_UNIT_IS_MMOL) {
editor.putString("pref_glucose_target_min", Float.toString(convertGlucoseMGDLToMMOL(GLUCOSE_TARGET_MIN))); | editor.putString("pref_glucose_target_max", Float.toString(convertGlucoseMGDLToMMOL(GLUCOSE_TARGET_MAX))); |
DorianScholz/OpenLibre | app/src/main/java/de/dorianscholz/openlibre/ui/SettingsActivity.java | // Path: app/src/main/java/de/dorianscholz/openlibre/OpenLibre.java
// public static float GLUCOSE_TARGET_MAX = 140;
//
// Path: app/src/main/java/de/dorianscholz/openlibre/OpenLibre.java
// public static float GLUCOSE_TARGET_MIN = 80;
//
// Path: app/src/main/java/de/dorianscholz/openlibre/OpenLibre.java
// public static boolean GLUCOSE_UNIT_IS_MMOL = false;
//
// Path: app/src/main/java/de/dorianscholz/openlibre/OpenLibre.java
// public static void refreshApplicationSettings(SharedPreferences settings) {
// // read settings values
// NFC_USE_MULTI_BLOCK_READ = settings.getBoolean("pref_nfc_use_multi_block_read", NFC_USE_MULTI_BLOCK_READ);
// GLUCOSE_UNIT_IS_MMOL = settings.getBoolean("pref_glucose_unit_is_mmol", GLUCOSE_UNIT_IS_MMOL);
// GLUCOSE_TARGET_MIN = Float.parseFloat(settings.getString("pref_glucose_target_min", Float.toString(GLUCOSE_TARGET_MIN)));
// GLUCOSE_TARGET_MAX = Float.parseFloat(settings.getString("pref_glucose_target_max", Float.toString(GLUCOSE_TARGET_MAX)));
// }
//
// Path: app/src/main/java/de/dorianscholz/openlibre/model/GlucoseData.java
// public static float convertGlucoseMGDLToMMOL(float mgdl) {
// return mgdl / 18f;
// }
//
// Path: app/src/main/java/de/dorianscholz/openlibre/model/GlucoseData.java
// public static float convertGlucoseMMOLToMGDL(float mmol) {
// return mmol * 18f;
// }
| import android.app.Activity;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.renderscript.Float2;
import io.tidepool.api.APIClient;
import static de.dorianscholz.openlibre.OpenLibre.GLUCOSE_TARGET_MAX;
import static de.dorianscholz.openlibre.OpenLibre.GLUCOSE_TARGET_MIN;
import static de.dorianscholz.openlibre.OpenLibre.GLUCOSE_UNIT_IS_MMOL;
import static de.dorianscholz.openlibre.OpenLibre.refreshApplicationSettings;
import static de.dorianscholz.openlibre.model.GlucoseData.convertGlucoseMGDLToMMOL;
import static de.dorianscholz.openlibre.model.GlucoseData.convertGlucoseMMOLToMGDL; | package de.dorianscholz.openlibre.ui;
public class SettingsActivity extends Activity implements SharedPreferences.OnSharedPreferenceChangeListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
PreferenceManager.getDefaultSharedPreferences(this).registerOnSharedPreferenceChangeListener(this);
// Display the fragment as the main content.
getFragmentManager().beginTransaction()
.replace(android.R.id.content, new SettingsFragment())
.commit();
}
@Override
public void onSharedPreferenceChanged(SharedPreferences settings, String key) {
// when username or server changes update the key for the sync progress
if (key.equals("pref_tidepool_username") || key.equals("pref_tidepool_server")) {
// trim spaces off of email address
String tidepoolUsername = settings.getString("pref_tidepool_username", "").trim();
SharedPreferences.Editor editor = settings.edit();
editor.putString("pref_tidepool_username", tidepoolUsername);
editor.apply();
String tidepoolServer = settings.getString("pref_tidepool_server", APIClient.PRODUCTION);
SharedPreferences.Editor preferencesEditor = getApplicationContext().getSharedPreferences("tidepool", MODE_PRIVATE).edit();
preferencesEditor.putString("upload_timestamp_key", "upload_timestamp_for_" + tidepoolUsername.toLowerCase() + "_at_" + tidepoolServer);
preferencesEditor.apply();
}
if (key.equals("pref_glucose_unit_is_mmol")) {
GLUCOSE_UNIT_IS_MMOL = settings.getBoolean("pref_glucose_unit_is_mmol", GLUCOSE_UNIT_IS_MMOL);
SharedPreferences.Editor editor = settings.edit();
if (GLUCOSE_UNIT_IS_MMOL) {
editor.putString("pref_glucose_target_min", Float.toString(convertGlucoseMGDLToMMOL(GLUCOSE_TARGET_MIN)));
editor.putString("pref_glucose_target_max", Float.toString(convertGlucoseMGDLToMMOL(GLUCOSE_TARGET_MAX)));
} else { | // Path: app/src/main/java/de/dorianscholz/openlibre/OpenLibre.java
// public static float GLUCOSE_TARGET_MAX = 140;
//
// Path: app/src/main/java/de/dorianscholz/openlibre/OpenLibre.java
// public static float GLUCOSE_TARGET_MIN = 80;
//
// Path: app/src/main/java/de/dorianscholz/openlibre/OpenLibre.java
// public static boolean GLUCOSE_UNIT_IS_MMOL = false;
//
// Path: app/src/main/java/de/dorianscholz/openlibre/OpenLibre.java
// public static void refreshApplicationSettings(SharedPreferences settings) {
// // read settings values
// NFC_USE_MULTI_BLOCK_READ = settings.getBoolean("pref_nfc_use_multi_block_read", NFC_USE_MULTI_BLOCK_READ);
// GLUCOSE_UNIT_IS_MMOL = settings.getBoolean("pref_glucose_unit_is_mmol", GLUCOSE_UNIT_IS_MMOL);
// GLUCOSE_TARGET_MIN = Float.parseFloat(settings.getString("pref_glucose_target_min", Float.toString(GLUCOSE_TARGET_MIN)));
// GLUCOSE_TARGET_MAX = Float.parseFloat(settings.getString("pref_glucose_target_max", Float.toString(GLUCOSE_TARGET_MAX)));
// }
//
// Path: app/src/main/java/de/dorianscholz/openlibre/model/GlucoseData.java
// public static float convertGlucoseMGDLToMMOL(float mgdl) {
// return mgdl / 18f;
// }
//
// Path: app/src/main/java/de/dorianscholz/openlibre/model/GlucoseData.java
// public static float convertGlucoseMMOLToMGDL(float mmol) {
// return mmol * 18f;
// }
// Path: app/src/main/java/de/dorianscholz/openlibre/ui/SettingsActivity.java
import android.app.Activity;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.renderscript.Float2;
import io.tidepool.api.APIClient;
import static de.dorianscholz.openlibre.OpenLibre.GLUCOSE_TARGET_MAX;
import static de.dorianscholz.openlibre.OpenLibre.GLUCOSE_TARGET_MIN;
import static de.dorianscholz.openlibre.OpenLibre.GLUCOSE_UNIT_IS_MMOL;
import static de.dorianscholz.openlibre.OpenLibre.refreshApplicationSettings;
import static de.dorianscholz.openlibre.model.GlucoseData.convertGlucoseMGDLToMMOL;
import static de.dorianscholz.openlibre.model.GlucoseData.convertGlucoseMMOLToMGDL;
package de.dorianscholz.openlibre.ui;
public class SettingsActivity extends Activity implements SharedPreferences.OnSharedPreferenceChangeListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
PreferenceManager.getDefaultSharedPreferences(this).registerOnSharedPreferenceChangeListener(this);
// Display the fragment as the main content.
getFragmentManager().beginTransaction()
.replace(android.R.id.content, new SettingsFragment())
.commit();
}
@Override
public void onSharedPreferenceChanged(SharedPreferences settings, String key) {
// when username or server changes update the key for the sync progress
if (key.equals("pref_tidepool_username") || key.equals("pref_tidepool_server")) {
// trim spaces off of email address
String tidepoolUsername = settings.getString("pref_tidepool_username", "").trim();
SharedPreferences.Editor editor = settings.edit();
editor.putString("pref_tidepool_username", tidepoolUsername);
editor.apply();
String tidepoolServer = settings.getString("pref_tidepool_server", APIClient.PRODUCTION);
SharedPreferences.Editor preferencesEditor = getApplicationContext().getSharedPreferences("tidepool", MODE_PRIVATE).edit();
preferencesEditor.putString("upload_timestamp_key", "upload_timestamp_for_" + tidepoolUsername.toLowerCase() + "_at_" + tidepoolServer);
preferencesEditor.apply();
}
if (key.equals("pref_glucose_unit_is_mmol")) {
GLUCOSE_UNIT_IS_MMOL = settings.getBoolean("pref_glucose_unit_is_mmol", GLUCOSE_UNIT_IS_MMOL);
SharedPreferences.Editor editor = settings.edit();
if (GLUCOSE_UNIT_IS_MMOL) {
editor.putString("pref_glucose_target_min", Float.toString(convertGlucoseMGDLToMMOL(GLUCOSE_TARGET_MIN)));
editor.putString("pref_glucose_target_max", Float.toString(convertGlucoseMGDLToMMOL(GLUCOSE_TARGET_MAX)));
} else { | editor.putString("pref_glucose_target_min", Float.toString(convertGlucoseMMOLToMGDL(GLUCOSE_TARGET_MIN))); |
DorianScholz/OpenLibre | app/src/main/java/de/dorianscholz/openlibre/ui/SettingsActivity.java | // Path: app/src/main/java/de/dorianscholz/openlibre/OpenLibre.java
// public static float GLUCOSE_TARGET_MAX = 140;
//
// Path: app/src/main/java/de/dorianscholz/openlibre/OpenLibre.java
// public static float GLUCOSE_TARGET_MIN = 80;
//
// Path: app/src/main/java/de/dorianscholz/openlibre/OpenLibre.java
// public static boolean GLUCOSE_UNIT_IS_MMOL = false;
//
// Path: app/src/main/java/de/dorianscholz/openlibre/OpenLibre.java
// public static void refreshApplicationSettings(SharedPreferences settings) {
// // read settings values
// NFC_USE_MULTI_BLOCK_READ = settings.getBoolean("pref_nfc_use_multi_block_read", NFC_USE_MULTI_BLOCK_READ);
// GLUCOSE_UNIT_IS_MMOL = settings.getBoolean("pref_glucose_unit_is_mmol", GLUCOSE_UNIT_IS_MMOL);
// GLUCOSE_TARGET_MIN = Float.parseFloat(settings.getString("pref_glucose_target_min", Float.toString(GLUCOSE_TARGET_MIN)));
// GLUCOSE_TARGET_MAX = Float.parseFloat(settings.getString("pref_glucose_target_max", Float.toString(GLUCOSE_TARGET_MAX)));
// }
//
// Path: app/src/main/java/de/dorianscholz/openlibre/model/GlucoseData.java
// public static float convertGlucoseMGDLToMMOL(float mgdl) {
// return mgdl / 18f;
// }
//
// Path: app/src/main/java/de/dorianscholz/openlibre/model/GlucoseData.java
// public static float convertGlucoseMMOLToMGDL(float mmol) {
// return mmol * 18f;
// }
| import android.app.Activity;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.renderscript.Float2;
import io.tidepool.api.APIClient;
import static de.dorianscholz.openlibre.OpenLibre.GLUCOSE_TARGET_MAX;
import static de.dorianscholz.openlibre.OpenLibre.GLUCOSE_TARGET_MIN;
import static de.dorianscholz.openlibre.OpenLibre.GLUCOSE_UNIT_IS_MMOL;
import static de.dorianscholz.openlibre.OpenLibre.refreshApplicationSettings;
import static de.dorianscholz.openlibre.model.GlucoseData.convertGlucoseMGDLToMMOL;
import static de.dorianscholz.openlibre.model.GlucoseData.convertGlucoseMMOLToMGDL; |
@Override
public void onSharedPreferenceChanged(SharedPreferences settings, String key) {
// when username or server changes update the key for the sync progress
if (key.equals("pref_tidepool_username") || key.equals("pref_tidepool_server")) {
// trim spaces off of email address
String tidepoolUsername = settings.getString("pref_tidepool_username", "").trim();
SharedPreferences.Editor editor = settings.edit();
editor.putString("pref_tidepool_username", tidepoolUsername);
editor.apply();
String tidepoolServer = settings.getString("pref_tidepool_server", APIClient.PRODUCTION);
SharedPreferences.Editor preferencesEditor = getApplicationContext().getSharedPreferences("tidepool", MODE_PRIVATE).edit();
preferencesEditor.putString("upload_timestamp_key", "upload_timestamp_for_" + tidepoolUsername.toLowerCase() + "_at_" + tidepoolServer);
preferencesEditor.apply();
}
if (key.equals("pref_glucose_unit_is_mmol")) {
GLUCOSE_UNIT_IS_MMOL = settings.getBoolean("pref_glucose_unit_is_mmol", GLUCOSE_UNIT_IS_MMOL);
SharedPreferences.Editor editor = settings.edit();
if (GLUCOSE_UNIT_IS_MMOL) {
editor.putString("pref_glucose_target_min", Float.toString(convertGlucoseMGDLToMMOL(GLUCOSE_TARGET_MIN)));
editor.putString("pref_glucose_target_max", Float.toString(convertGlucoseMGDLToMMOL(GLUCOSE_TARGET_MAX)));
} else {
editor.putString("pref_glucose_target_min", Float.toString(convertGlucoseMMOLToMGDL(GLUCOSE_TARGET_MIN)));
editor.putString("pref_glucose_target_max", Float.toString(convertGlucoseMMOLToMGDL(GLUCOSE_TARGET_MAX)));
}
editor.apply(); | // Path: app/src/main/java/de/dorianscholz/openlibre/OpenLibre.java
// public static float GLUCOSE_TARGET_MAX = 140;
//
// Path: app/src/main/java/de/dorianscholz/openlibre/OpenLibre.java
// public static float GLUCOSE_TARGET_MIN = 80;
//
// Path: app/src/main/java/de/dorianscholz/openlibre/OpenLibre.java
// public static boolean GLUCOSE_UNIT_IS_MMOL = false;
//
// Path: app/src/main/java/de/dorianscholz/openlibre/OpenLibre.java
// public static void refreshApplicationSettings(SharedPreferences settings) {
// // read settings values
// NFC_USE_MULTI_BLOCK_READ = settings.getBoolean("pref_nfc_use_multi_block_read", NFC_USE_MULTI_BLOCK_READ);
// GLUCOSE_UNIT_IS_MMOL = settings.getBoolean("pref_glucose_unit_is_mmol", GLUCOSE_UNIT_IS_MMOL);
// GLUCOSE_TARGET_MIN = Float.parseFloat(settings.getString("pref_glucose_target_min", Float.toString(GLUCOSE_TARGET_MIN)));
// GLUCOSE_TARGET_MAX = Float.parseFloat(settings.getString("pref_glucose_target_max", Float.toString(GLUCOSE_TARGET_MAX)));
// }
//
// Path: app/src/main/java/de/dorianscholz/openlibre/model/GlucoseData.java
// public static float convertGlucoseMGDLToMMOL(float mgdl) {
// return mgdl / 18f;
// }
//
// Path: app/src/main/java/de/dorianscholz/openlibre/model/GlucoseData.java
// public static float convertGlucoseMMOLToMGDL(float mmol) {
// return mmol * 18f;
// }
// Path: app/src/main/java/de/dorianscholz/openlibre/ui/SettingsActivity.java
import android.app.Activity;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.renderscript.Float2;
import io.tidepool.api.APIClient;
import static de.dorianscholz.openlibre.OpenLibre.GLUCOSE_TARGET_MAX;
import static de.dorianscholz.openlibre.OpenLibre.GLUCOSE_TARGET_MIN;
import static de.dorianscholz.openlibre.OpenLibre.GLUCOSE_UNIT_IS_MMOL;
import static de.dorianscholz.openlibre.OpenLibre.refreshApplicationSettings;
import static de.dorianscholz.openlibre.model.GlucoseData.convertGlucoseMGDLToMMOL;
import static de.dorianscholz.openlibre.model.GlucoseData.convertGlucoseMMOLToMGDL;
@Override
public void onSharedPreferenceChanged(SharedPreferences settings, String key) {
// when username or server changes update the key for the sync progress
if (key.equals("pref_tidepool_username") || key.equals("pref_tidepool_server")) {
// trim spaces off of email address
String tidepoolUsername = settings.getString("pref_tidepool_username", "").trim();
SharedPreferences.Editor editor = settings.edit();
editor.putString("pref_tidepool_username", tidepoolUsername);
editor.apply();
String tidepoolServer = settings.getString("pref_tidepool_server", APIClient.PRODUCTION);
SharedPreferences.Editor preferencesEditor = getApplicationContext().getSharedPreferences("tidepool", MODE_PRIVATE).edit();
preferencesEditor.putString("upload_timestamp_key", "upload_timestamp_for_" + tidepoolUsername.toLowerCase() + "_at_" + tidepoolServer);
preferencesEditor.apply();
}
if (key.equals("pref_glucose_unit_is_mmol")) {
GLUCOSE_UNIT_IS_MMOL = settings.getBoolean("pref_glucose_unit_is_mmol", GLUCOSE_UNIT_IS_MMOL);
SharedPreferences.Editor editor = settings.edit();
if (GLUCOSE_UNIT_IS_MMOL) {
editor.putString("pref_glucose_target_min", Float.toString(convertGlucoseMGDLToMMOL(GLUCOSE_TARGET_MIN)));
editor.putString("pref_glucose_target_max", Float.toString(convertGlucoseMGDLToMMOL(GLUCOSE_TARGET_MAX)));
} else {
editor.putString("pref_glucose_target_min", Float.toString(convertGlucoseMMOLToMGDL(GLUCOSE_TARGET_MIN)));
editor.putString("pref_glucose_target_max", Float.toString(convertGlucoseMMOLToMGDL(GLUCOSE_TARGET_MAX)));
}
editor.apply(); | refreshApplicationSettings(settings); |
DorianScholz/OpenLibre | app/src/main/java/de/dorianscholz/openlibre/model/BloodGlucoseData.java | // Path: app/src/main/java/de/dorianscholz/openlibre/model/AlgorithmUtil.java
// public static final DateFormat mFormatDateTime = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
//
// Path: app/src/main/java/de/dorianscholz/openlibre/model/GlucoseData.java
// public static String formatValue(float value) {
// return GLUCOSE_UNIT_IS_MMOL ?
// new DecimalFormat("##.0").format(value) :
// new DecimalFormat("###").format(value);
// }
| import android.support.annotation.NonNull;
import java.util.Date;
import java.util.Locale;
import java.util.TimeZone;
import io.realm.RealmObject;
import io.realm.annotations.PrimaryKey;
import static de.dorianscholz.openlibre.model.AlgorithmUtil.mFormatDateTime;
import static de.dorianscholz.openlibre.model.GlucoseData.formatValue; | package de.dorianscholz.openlibre.model;
public class BloodGlucoseData extends RealmObject implements Comparable<BloodGlucoseData> {
public static final String ID = "id";
static final String GLUCOSE_LEVEL = "glucoseLevel";
public static final String DATE = "date";
public static final String TIMEZONE_OFFSET_IN_MINUTES = "timezoneOffsetInMinutes";
@PrimaryKey
private String id;
private float glucoseLevel = -1; // in mg/dl
private long date;
private int timezoneOffsetInMinutes;
public BloodGlucoseData() {}
public BloodGlucoseData(long date, float glucoseLevel) {
this.date = date;
timezoneOffsetInMinutes = TimeZone.getDefault().getOffset(System.currentTimeMillis()) / 1000 / 60;
this.glucoseLevel = glucoseLevel; | // Path: app/src/main/java/de/dorianscholz/openlibre/model/AlgorithmUtil.java
// public static final DateFormat mFormatDateTime = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
//
// Path: app/src/main/java/de/dorianscholz/openlibre/model/GlucoseData.java
// public static String formatValue(float value) {
// return GLUCOSE_UNIT_IS_MMOL ?
// new DecimalFormat("##.0").format(value) :
// new DecimalFormat("###").format(value);
// }
// Path: app/src/main/java/de/dorianscholz/openlibre/model/BloodGlucoseData.java
import android.support.annotation.NonNull;
import java.util.Date;
import java.util.Locale;
import java.util.TimeZone;
import io.realm.RealmObject;
import io.realm.annotations.PrimaryKey;
import static de.dorianscholz.openlibre.model.AlgorithmUtil.mFormatDateTime;
import static de.dorianscholz.openlibre.model.GlucoseData.formatValue;
package de.dorianscholz.openlibre.model;
public class BloodGlucoseData extends RealmObject implements Comparable<BloodGlucoseData> {
public static final String ID = "id";
static final String GLUCOSE_LEVEL = "glucoseLevel";
public static final String DATE = "date";
public static final String TIMEZONE_OFFSET_IN_MINUTES = "timezoneOffsetInMinutes";
@PrimaryKey
private String id;
private float glucoseLevel = -1; // in mg/dl
private long date;
private int timezoneOffsetInMinutes;
public BloodGlucoseData() {}
public BloodGlucoseData(long date, float glucoseLevel) {
this.date = date;
timezoneOffsetInMinutes = TimeZone.getDefault().getOffset(System.currentTimeMillis()) / 1000 / 60;
this.glucoseLevel = glucoseLevel; | id = String.format(Locale.US, "blood_%s", mFormatDateTime.format(new Date(date))); |
DorianScholz/OpenLibre | app/src/main/java/de/dorianscholz/openlibre/model/BloodGlucoseData.java | // Path: app/src/main/java/de/dorianscholz/openlibre/model/AlgorithmUtil.java
// public static final DateFormat mFormatDateTime = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
//
// Path: app/src/main/java/de/dorianscholz/openlibre/model/GlucoseData.java
// public static String formatValue(float value) {
// return GLUCOSE_UNIT_IS_MMOL ?
// new DecimalFormat("##.0").format(value) :
// new DecimalFormat("###").format(value);
// }
| import android.support.annotation.NonNull;
import java.util.Date;
import java.util.Locale;
import java.util.TimeZone;
import io.realm.RealmObject;
import io.realm.annotations.PrimaryKey;
import static de.dorianscholz.openlibre.model.AlgorithmUtil.mFormatDateTime;
import static de.dorianscholz.openlibre.model.GlucoseData.formatValue; | package de.dorianscholz.openlibre.model;
public class BloodGlucoseData extends RealmObject implements Comparable<BloodGlucoseData> {
public static final String ID = "id";
static final String GLUCOSE_LEVEL = "glucoseLevel";
public static final String DATE = "date";
public static final String TIMEZONE_OFFSET_IN_MINUTES = "timezoneOffsetInMinutes";
@PrimaryKey
private String id;
private float glucoseLevel = -1; // in mg/dl
private long date;
private int timezoneOffsetInMinutes;
public BloodGlucoseData() {}
public BloodGlucoseData(long date, float glucoseLevel) {
this.date = date;
timezoneOffsetInMinutes = TimeZone.getDefault().getOffset(System.currentTimeMillis()) / 1000 / 60;
this.glucoseLevel = glucoseLevel;
id = String.format(Locale.US, "blood_%s", mFormatDateTime.format(new Date(date)));
}
public float glucose() {
return glucoseLevel;
}
public String glucoseString() { | // Path: app/src/main/java/de/dorianscholz/openlibre/model/AlgorithmUtil.java
// public static final DateFormat mFormatDateTime = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
//
// Path: app/src/main/java/de/dorianscholz/openlibre/model/GlucoseData.java
// public static String formatValue(float value) {
// return GLUCOSE_UNIT_IS_MMOL ?
// new DecimalFormat("##.0").format(value) :
// new DecimalFormat("###").format(value);
// }
// Path: app/src/main/java/de/dorianscholz/openlibre/model/BloodGlucoseData.java
import android.support.annotation.NonNull;
import java.util.Date;
import java.util.Locale;
import java.util.TimeZone;
import io.realm.RealmObject;
import io.realm.annotations.PrimaryKey;
import static de.dorianscholz.openlibre.model.AlgorithmUtil.mFormatDateTime;
import static de.dorianscholz.openlibre.model.GlucoseData.formatValue;
package de.dorianscholz.openlibre.model;
public class BloodGlucoseData extends RealmObject implements Comparable<BloodGlucoseData> {
public static final String ID = "id";
static final String GLUCOSE_LEVEL = "glucoseLevel";
public static final String DATE = "date";
public static final String TIMEZONE_OFFSET_IN_MINUTES = "timezoneOffsetInMinutes";
@PrimaryKey
private String id;
private float glucoseLevel = -1; // in mg/dl
private long date;
private int timezoneOffsetInMinutes;
public BloodGlucoseData() {}
public BloodGlucoseData(long date, float glucoseLevel) {
this.date = date;
timezoneOffsetInMinutes = TimeZone.getDefault().getOffset(System.currentTimeMillis()) / 1000 / 60;
this.glucoseLevel = glucoseLevel;
id = String.format(Locale.US, "blood_%s", mFormatDateTime.format(new Date(date)));
}
public float glucose() {
return glucoseLevel;
}
public String glucoseString() { | return formatValue(glucose()); |
DorianScholz/OpenLibre | app/src/main/java/de/dorianscholz/openlibre/model/GlucoseData.java | // Path: app/src/main/java/de/dorianscholz/openlibre/OpenLibre.java
// public static boolean GLUCOSE_UNIT_IS_MMOL = false;
| import android.support.annotation.NonNull;
import java.text.DecimalFormat;
import java.util.Locale;
import java.util.concurrent.TimeUnit;
import io.realm.RealmObject;
import io.realm.annotations.PrimaryKey;
import static de.dorianscholz.openlibre.OpenLibre.GLUCOSE_UNIT_IS_MMOL; | this(sensor, ageInSensorMinutes, timezoneOffsetInMinutes, glucoseLevelRaw, isTrendData, sensor.getStartDate() + TimeUnit.MINUTES.toMillis(ageInSensorMinutes));
}
public static String generateId(SensorData sensor, int ageInSensorMinutes, boolean isTrendData, int glucoseLevelRaw) {
if (isTrendData) {
// a trend data value for a specific time is not fixed in its value, but can change on the next reading
// so the trend id also includes the glucose value itself, so the previous reading's data are not overwritten
return String.format(Locale.US, "trend_%s_%05d_%03d", sensor.getId(), ageInSensorMinutes, glucoseLevelRaw);
} else {
return String.format(Locale.US, "history_%s_%05d", sensor.getId(), ageInSensorMinutes);
}
}
public static float convertGlucoseMMOLToMGDL(float mmol) {
return mmol * 18f;
}
public static float convertGlucoseMGDLToMMOL(float mgdl) {
return mgdl / 18f;
}
private static float convertGlucoseRawToMGDL(float raw) {
return raw / 10f;
}
private static float convertGlucoseRawToMMOL(float raw) {
return convertGlucoseMGDLToMMOL(raw / 10f);
}
public static float convertGlucoseMGDLToDisplayUnit(float mgdl) { | // Path: app/src/main/java/de/dorianscholz/openlibre/OpenLibre.java
// public static boolean GLUCOSE_UNIT_IS_MMOL = false;
// Path: app/src/main/java/de/dorianscholz/openlibre/model/GlucoseData.java
import android.support.annotation.NonNull;
import java.text.DecimalFormat;
import java.util.Locale;
import java.util.concurrent.TimeUnit;
import io.realm.RealmObject;
import io.realm.annotations.PrimaryKey;
import static de.dorianscholz.openlibre.OpenLibre.GLUCOSE_UNIT_IS_MMOL;
this(sensor, ageInSensorMinutes, timezoneOffsetInMinutes, glucoseLevelRaw, isTrendData, sensor.getStartDate() + TimeUnit.MINUTES.toMillis(ageInSensorMinutes));
}
public static String generateId(SensorData sensor, int ageInSensorMinutes, boolean isTrendData, int glucoseLevelRaw) {
if (isTrendData) {
// a trend data value for a specific time is not fixed in its value, but can change on the next reading
// so the trend id also includes the glucose value itself, so the previous reading's data are not overwritten
return String.format(Locale.US, "trend_%s_%05d_%03d", sensor.getId(), ageInSensorMinutes, glucoseLevelRaw);
} else {
return String.format(Locale.US, "history_%s_%05d", sensor.getId(), ageInSensorMinutes);
}
}
public static float convertGlucoseMMOLToMGDL(float mmol) {
return mmol * 18f;
}
public static float convertGlucoseMGDLToMMOL(float mgdl) {
return mgdl / 18f;
}
private static float convertGlucoseRawToMGDL(float raw) {
return raw / 10f;
}
private static float convertGlucoseRawToMMOL(float raw) {
return convertGlucoseMGDLToMMOL(raw / 10f);
}
public static float convertGlucoseMGDLToDisplayUnit(float mgdl) { | return GLUCOSE_UNIT_IS_MMOL ? convertGlucoseMGDLToMMOL(mgdl) : mgdl; |
mast-group/codemining-core | src/test/java/codemining/java/codeutils/binding/BindingTester.java | // Path: src/main/java/codemining/languagetools/bindings/TokenNameBinding.java
// public class TokenNameBinding implements Serializable {
// private static final long serialVersionUID = 2020613810485746430L;
//
// /**
// * The tokens of source code.
// */
// public final List<String> sourceCodeTokens;
//
// /**
// * The positions in sourceCodeTokens that contain the given name.
// */
// public final Set<Integer> nameIndexes;
//
// /**
// * Features of the binding
// */
// public final Set<String> features;
//
// public TokenNameBinding(final Set<Integer> nameIndexes,
// final List<String> sourceCodeTokens, final Set<String> features) {
// checkArgument(nameIndexes.size() > 0);
// checkArgument(sourceCodeTokens.size() > 0);
// this.nameIndexes = Collections.unmodifiableSet(nameIndexes);
// this.sourceCodeTokens = Collections.unmodifiableList(sourceCodeTokens);
// this.features = features;
// }
//
// @Override
// public boolean equals(final Object obj) {
// if (this == obj) {
// return true;
// }
// if (obj == null) {
// return false;
// }
// if (getClass() != obj.getClass()) {
// return false;
// }
// final TokenNameBinding other = (TokenNameBinding) obj;
// return Objects.equal(nameIndexes, other.nameIndexes)
// && Objects.equal(features, other.features)
// && Objects.equal(sourceCodeTokens, other.sourceCodeTokens);
// }
//
// public String getName() {
// return sourceCodeTokens.get(nameIndexes.iterator().next());
// }
//
// @Override
// public int hashCode() {
// return Objects.hashCode(sourceCodeTokens, nameIndexes, features);
// }
//
// /**
// * Rename this name to the given binding. The source code tokens included in
// * this struct, now represent the new structure.
// *
// * @param name
// * @return
// */
// public TokenNameBinding renameTo(final String name) {
// final List<String> renamedCode = Lists.newArrayList(sourceCodeTokens);
// for (final int position : nameIndexes) {
// renamedCode.set(position, name);
// }
// return new TokenNameBinding(nameIndexes, renamedCode, features);
// }
//
// @Override
// public String toString() {
// return getName() + nameIndexes + " " + features;
// }
// }
| import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import java.util.List;
import java.util.Set;
import codemining.languagetools.bindings.TokenNameBinding;
import com.google.common.collect.Sets; | /**
*
*/
package codemining.java.codeutils.binding;
/**
* Utility class for testing bindings.
*
* @author Miltos Allamanis <[email protected]>
*
*/
public class BindingTester {
private BindingTester() {
}
| // Path: src/main/java/codemining/languagetools/bindings/TokenNameBinding.java
// public class TokenNameBinding implements Serializable {
// private static final long serialVersionUID = 2020613810485746430L;
//
// /**
// * The tokens of source code.
// */
// public final List<String> sourceCodeTokens;
//
// /**
// * The positions in sourceCodeTokens that contain the given name.
// */
// public final Set<Integer> nameIndexes;
//
// /**
// * Features of the binding
// */
// public final Set<String> features;
//
// public TokenNameBinding(final Set<Integer> nameIndexes,
// final List<String> sourceCodeTokens, final Set<String> features) {
// checkArgument(nameIndexes.size() > 0);
// checkArgument(sourceCodeTokens.size() > 0);
// this.nameIndexes = Collections.unmodifiableSet(nameIndexes);
// this.sourceCodeTokens = Collections.unmodifiableList(sourceCodeTokens);
// this.features = features;
// }
//
// @Override
// public boolean equals(final Object obj) {
// if (this == obj) {
// return true;
// }
// if (obj == null) {
// return false;
// }
// if (getClass() != obj.getClass()) {
// return false;
// }
// final TokenNameBinding other = (TokenNameBinding) obj;
// return Objects.equal(nameIndexes, other.nameIndexes)
// && Objects.equal(features, other.features)
// && Objects.equal(sourceCodeTokens, other.sourceCodeTokens);
// }
//
// public String getName() {
// return sourceCodeTokens.get(nameIndexes.iterator().next());
// }
//
// @Override
// public int hashCode() {
// return Objects.hashCode(sourceCodeTokens, nameIndexes, features);
// }
//
// /**
// * Rename this name to the given binding. The source code tokens included in
// * this struct, now represent the new structure.
// *
// * @param name
// * @return
// */
// public TokenNameBinding renameTo(final String name) {
// final List<String> renamedCode = Lists.newArrayList(sourceCodeTokens);
// for (final int position : nameIndexes) {
// renamedCode.set(position, name);
// }
// return new TokenNameBinding(nameIndexes, renamedCode, features);
// }
//
// @Override
// public String toString() {
// return getName() + nameIndexes + " " + features;
// }
// }
// Path: src/test/java/codemining/java/codeutils/binding/BindingTester.java
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import java.util.List;
import java.util.Set;
import codemining.languagetools.bindings.TokenNameBinding;
import com.google.common.collect.Sets;
/**
*
*/
package codemining.java.codeutils.binding;
/**
* Utility class for testing bindings.
*
* @author Miltos Allamanis <[email protected]>
*
*/
public class BindingTester {
private BindingTester() {
}
| public static void checkAllBindings(final List<TokenNameBinding> bindings) { |
mast-group/codemining-core | src/main/java/codemining/languagetools/TokenizerUtils.java | // Path: src/main/java/codemining/languagetools/ITokenizer.java
// public static class FullToken implements Serializable {
//
// private static final long serialVersionUID = -49456240173307314L;
//
// public static final Function<FullToken, String> TOKEN_NAME_CONVERTER = new Function<FullToken, String>() {
// @Override
// public String apply(final FullToken input) {
// return input.token;
// }
// };
//
// public final String token;
//
// public final String tokenType;
//
// public FullToken(final FullToken other) {
// token = other.token;
// tokenType = other.tokenType;
// }
//
// public FullToken(final String tokName, final String tokType) {
// token = tokName;
// tokenType = tokType;
// }
//
// @Override
// public boolean equals(final Object obj) {
// if (!(obj instanceof FullToken)) {
// return false;
// }
// final FullToken other = (FullToken) obj;
// return other.token.equals(token)
// && other.tokenType.equals(tokenType);
// }
//
// @Override
// public int hashCode() {
// return Objects.hashCode(token, tokenType);
// }
//
// @Override
// public String toString() {
// return token + " (" + tokenType + ")";
// }
//
// }
| import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkPositionIndex;
import java.lang.reflect.InvocationTargetException;
import java.util.List;
import org.apache.commons.lang.StringUtils;
import codemining.languagetools.ITokenizer.FullToken;
import codemining.util.SettingsLoader; | /**
*
*/
package codemining.languagetools;
/**
* Utility function relevant to tokenization.
*
* @author Miltos Allamanis <[email protected]>
*
*/
public class TokenizerUtils {
public static final int TAB_INDENT_SIZE = (int) SettingsLoader
.getNumericSetting("tabSize", 4);
/**
* Return the column of the given position.
*
* @param code
* @param position
* @return
*/
public static int getColumnOfPosition(final String code, final int position) {
checkPositionIndex(position, code.length());
int newLinePosition = code.substring(0, position).lastIndexOf("\n");
if (newLinePosition == -1) {
newLinePosition = 0; // Start of file.
}
final int tabCount = StringUtils.countMatches(
code.substring(newLinePosition, position), "\t");
return position - newLinePosition + (TAB_INDENT_SIZE - 1) * tabCount;
}
/**
* Crudely join tokens together.
*
* @param tokens
* @param sb
* @return
*/
public final static StringBuffer joinFullTokens( | // Path: src/main/java/codemining/languagetools/ITokenizer.java
// public static class FullToken implements Serializable {
//
// private static final long serialVersionUID = -49456240173307314L;
//
// public static final Function<FullToken, String> TOKEN_NAME_CONVERTER = new Function<FullToken, String>() {
// @Override
// public String apply(final FullToken input) {
// return input.token;
// }
// };
//
// public final String token;
//
// public final String tokenType;
//
// public FullToken(final FullToken other) {
// token = other.token;
// tokenType = other.tokenType;
// }
//
// public FullToken(final String tokName, final String tokType) {
// token = tokName;
// tokenType = tokType;
// }
//
// @Override
// public boolean equals(final Object obj) {
// if (!(obj instanceof FullToken)) {
// return false;
// }
// final FullToken other = (FullToken) obj;
// return other.token.equals(token)
// && other.tokenType.equals(tokenType);
// }
//
// @Override
// public int hashCode() {
// return Objects.hashCode(token, tokenType);
// }
//
// @Override
// public String toString() {
// return token + " (" + tokenType + ")";
// }
//
// }
// Path: src/main/java/codemining/languagetools/TokenizerUtils.java
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkPositionIndex;
import java.lang.reflect.InvocationTargetException;
import java.util.List;
import org.apache.commons.lang.StringUtils;
import codemining.languagetools.ITokenizer.FullToken;
import codemining.util.SettingsLoader;
/**
*
*/
package codemining.languagetools;
/**
* Utility function relevant to tokenization.
*
* @author Miltos Allamanis <[email protected]>
*
*/
public class TokenizerUtils {
public static final int TAB_INDENT_SIZE = (int) SettingsLoader
.getNumericSetting("tabSize", 4);
/**
* Return the column of the given position.
*
* @param code
* @param position
* @return
*/
public static int getColumnOfPosition(final String code, final int position) {
checkPositionIndex(position, code.length());
int newLinePosition = code.substring(0, position).lastIndexOf("\n");
if (newLinePosition == -1) {
newLinePosition = 0; // Start of file.
}
final int tabCount = StringUtils.countMatches(
code.substring(newLinePosition, position), "\t");
return position - newLinePosition + (TAB_INDENT_SIZE - 1) * tabCount;
}
/**
* Crudely join tokens together.
*
* @param tokens
* @param sb
* @return
*/
public final static StringBuffer joinFullTokens( | final List<FullToken> tokens, final StringBuffer sb) { |
mast-group/codemining-core | src/test/java/codemining/js/codeutils/TokenizeJavascriptCodeTest.java | // Path: src/main/java/codemining/languagetools/ITokenizer.java
// public interface ITokenizer extends Serializable {
//
// public static class FullToken implements Serializable {
//
// private static final long serialVersionUID = -49456240173307314L;
//
// public static final Function<FullToken, String> TOKEN_NAME_CONVERTER = new Function<FullToken, String>() {
// @Override
// public String apply(final FullToken input) {
// return input.token;
// }
// };
//
// public final String token;
//
// public final String tokenType;
//
// public FullToken(final FullToken other) {
// token = other.token;
// tokenType = other.tokenType;
// }
//
// public FullToken(final String tokName, final String tokType) {
// token = tokName;
// tokenType = tokType;
// }
//
// @Override
// public boolean equals(final Object obj) {
// if (!(obj instanceof FullToken)) {
// return false;
// }
// final FullToken other = (FullToken) obj;
// return other.token.equals(token)
// && other.tokenType.equals(tokenType);
// }
//
// @Override
// public int hashCode() {
// return Objects.hashCode(token, tokenType);
// }
//
// @Override
// public String toString() {
// return token + " (" + tokenType + ")";
// }
//
// }
//
// /**
// * A sentence end (constant) token
// */
// static final String SENTENCE_END = "<SENTENCE_END/>";
//
// /**
// * A sentence start (constant) token
// */
// static final String SENTENCE_START = "<SENTENCE_START>";
//
// /**
// * Return a list with the full tokens.
// *
// * @param code
// * @return
// */
// SortedMap<Integer, FullToken> fullTokenListWithPos(final char[] code);
//
// /**
// * Return a file filter, filtering the files that can be tokenized.
// *
// * @return
// *
// */
// AbstractFileFilter getFileFilter();
//
// /**
// * Return the token type that signifies that a token is an identifier.
// *
// * @return
// */
// String getIdentifierType();
//
// /**
// * Return the token types that are keywords.
// *
// * @return
// */
// Collection<String> getKeywordTypes();
//
// /**
// * Return the types the represent literals.
// *
// * @return
// */
// Collection<String> getLiteralTypes();
//
// /**
// * Return a full token given a string token.
// *
// * @param token
// * @return
// */
// FullToken getTokenFromString(final String token);
//
// /**
// * Get the list of tokens from the code.
// *
// * @param code
// * @return
// */
// List<FullToken> getTokenListFromCode(final char[] code);
//
// /**
// * Get the list of tokens from the code.
// *
// * @param code
// * @return
// */
// List<FullToken> getTokenListFromCode(final File codeFile)
// throws IOException;
//
// /**
// * Tokenize some code.
// *
// * @param code
// * the code
// * @return a list of tokens
// */
// List<String> tokenListFromCode(final char[] code);
//
// /**
// * Tokenize code given a file.
// *
// * @param codeFile
// * @return
// */
// List<String> tokenListFromCode(final File codeFile) throws IOException;
//
// /**
// * Return a list of tokens along with their positions.
// *
// * @param code
// * @return
// */
// SortedMap<Integer, String> tokenListWithPos(final char[] code);
//
// /**
// * Return a list of tokens along with their positions.
// *
// * @param file
// * @return
// * @throws IOException
// */
// SortedMap<Integer, FullToken> tokenListWithPos(File file)
// throws IOException;
//
// }
| import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.util.List;
import java.util.Map;
import org.eclipse.wst.jsdt.core.compiler.ITerminalSymbols;
import org.junit.Test;
import codemining.languagetools.ITokenizer; | package codemining.js.codeutils;
public class TokenizeJavascriptCodeTest {
private static final char[] CODE_SAMPLE1 = "var x=2;".toCharArray();
| // Path: src/main/java/codemining/languagetools/ITokenizer.java
// public interface ITokenizer extends Serializable {
//
// public static class FullToken implements Serializable {
//
// private static final long serialVersionUID = -49456240173307314L;
//
// public static final Function<FullToken, String> TOKEN_NAME_CONVERTER = new Function<FullToken, String>() {
// @Override
// public String apply(final FullToken input) {
// return input.token;
// }
// };
//
// public final String token;
//
// public final String tokenType;
//
// public FullToken(final FullToken other) {
// token = other.token;
// tokenType = other.tokenType;
// }
//
// public FullToken(final String tokName, final String tokType) {
// token = tokName;
// tokenType = tokType;
// }
//
// @Override
// public boolean equals(final Object obj) {
// if (!(obj instanceof FullToken)) {
// return false;
// }
// final FullToken other = (FullToken) obj;
// return other.token.equals(token)
// && other.tokenType.equals(tokenType);
// }
//
// @Override
// public int hashCode() {
// return Objects.hashCode(token, tokenType);
// }
//
// @Override
// public String toString() {
// return token + " (" + tokenType + ")";
// }
//
// }
//
// /**
// * A sentence end (constant) token
// */
// static final String SENTENCE_END = "<SENTENCE_END/>";
//
// /**
// * A sentence start (constant) token
// */
// static final String SENTENCE_START = "<SENTENCE_START>";
//
// /**
// * Return a list with the full tokens.
// *
// * @param code
// * @return
// */
// SortedMap<Integer, FullToken> fullTokenListWithPos(final char[] code);
//
// /**
// * Return a file filter, filtering the files that can be tokenized.
// *
// * @return
// *
// */
// AbstractFileFilter getFileFilter();
//
// /**
// * Return the token type that signifies that a token is an identifier.
// *
// * @return
// */
// String getIdentifierType();
//
// /**
// * Return the token types that are keywords.
// *
// * @return
// */
// Collection<String> getKeywordTypes();
//
// /**
// * Return the types the represent literals.
// *
// * @return
// */
// Collection<String> getLiteralTypes();
//
// /**
// * Return a full token given a string token.
// *
// * @param token
// * @return
// */
// FullToken getTokenFromString(final String token);
//
// /**
// * Get the list of tokens from the code.
// *
// * @param code
// * @return
// */
// List<FullToken> getTokenListFromCode(final char[] code);
//
// /**
// * Get the list of tokens from the code.
// *
// * @param code
// * @return
// */
// List<FullToken> getTokenListFromCode(final File codeFile)
// throws IOException;
//
// /**
// * Tokenize some code.
// *
// * @param code
// * the code
// * @return a list of tokens
// */
// List<String> tokenListFromCode(final char[] code);
//
// /**
// * Tokenize code given a file.
// *
// * @param codeFile
// * @return
// */
// List<String> tokenListFromCode(final File codeFile) throws IOException;
//
// /**
// * Return a list of tokens along with their positions.
// *
// * @param code
// * @return
// */
// SortedMap<Integer, String> tokenListWithPos(final char[] code);
//
// /**
// * Return a list of tokens along with their positions.
// *
// * @param file
// * @return
// * @throws IOException
// */
// SortedMap<Integer, FullToken> tokenListWithPos(File file)
// throws IOException;
//
// }
// Path: src/test/java/codemining/js/codeutils/TokenizeJavascriptCodeTest.java
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.util.List;
import java.util.Map;
import org.eclipse.wst.jsdt.core.compiler.ITerminalSymbols;
import org.junit.Test;
import codemining.languagetools.ITokenizer;
package codemining.js.codeutils;
public class TokenizeJavascriptCodeTest {
private static final char[] CODE_SAMPLE1 = "var x=2;".toCharArray();
| private static final String[] TOKENS_SAMPLE1 = { ITokenizer.SENTENCE_START, |
mast-group/codemining-core | src/main/java/codemining/languagetools/CodePrinter.java | // Path: src/main/java/codemining/languagetools/ITokenizer.java
// public static class FullToken implements Serializable {
//
// private static final long serialVersionUID = -49456240173307314L;
//
// public static final Function<FullToken, String> TOKEN_NAME_CONVERTER = new Function<FullToken, String>() {
// @Override
// public String apply(final FullToken input) {
// return input.token;
// }
// };
//
// public final String token;
//
// public final String tokenType;
//
// public FullToken(final FullToken other) {
// token = other.token;
// tokenType = other.tokenType;
// }
//
// public FullToken(final String tokName, final String tokType) {
// token = tokName;
// tokenType = tokType;
// }
//
// @Override
// public boolean equals(final Object obj) {
// if (!(obj instanceof FullToken)) {
// return false;
// }
// final FullToken other = (FullToken) obj;
// return other.token.equals(token)
// && other.tokenType.equals(tokenType);
// }
//
// @Override
// public int hashCode() {
// return Objects.hashCode(token, tokenType);
// }
//
// @Override
// public String toString() {
// return token + " (" + tokenType + ")";
// }
//
// }
| import java.awt.Color;
import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Map.Entry;
import java.util.SortedMap;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringEscapeUtils;
import codemining.languagetools.ITokenizer.FullToken;
import codemining.util.SettingsLoader; | appendLineDiv(buf, true);
} else {
buf.append(c);
}
}
}
private void appendLineDiv(final StringBuffer buf,
final boolean closePrevious) {
if (closePrevious) {
buf.append("<br/></div>\n");
}
buf.append("<div class='line' id='C" + lineNumber + "'>");
lineNumber++;
}
/**
* Return a StringBuffer with colored tokens as specified from the
* coloredTokens. There should be one-to-one correspondence with the actual
* tokens.
*/
public StringBuffer getHTMLwithColors(
final List<ColoredToken> coloredTokens, final File codeFile)
throws IOException, InstantiationException, IllegalAccessException {
final String code = FileUtils.readFileToString(codeFile);
lineNumber = 1;
final StringBuffer buf = new StringBuffer();
| // Path: src/main/java/codemining/languagetools/ITokenizer.java
// public static class FullToken implements Serializable {
//
// private static final long serialVersionUID = -49456240173307314L;
//
// public static final Function<FullToken, String> TOKEN_NAME_CONVERTER = new Function<FullToken, String>() {
// @Override
// public String apply(final FullToken input) {
// return input.token;
// }
// };
//
// public final String token;
//
// public final String tokenType;
//
// public FullToken(final FullToken other) {
// token = other.token;
// tokenType = other.tokenType;
// }
//
// public FullToken(final String tokName, final String tokType) {
// token = tokName;
// tokenType = tokType;
// }
//
// @Override
// public boolean equals(final Object obj) {
// if (!(obj instanceof FullToken)) {
// return false;
// }
// final FullToken other = (FullToken) obj;
// return other.token.equals(token)
// && other.tokenType.equals(tokenType);
// }
//
// @Override
// public int hashCode() {
// return Objects.hashCode(token, tokenType);
// }
//
// @Override
// public String toString() {
// return token + " (" + tokenType + ")";
// }
//
// }
// Path: src/main/java/codemining/languagetools/CodePrinter.java
import java.awt.Color;
import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Map.Entry;
import java.util.SortedMap;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringEscapeUtils;
import codemining.languagetools.ITokenizer.FullToken;
import codemining.util.SettingsLoader;
appendLineDiv(buf, true);
} else {
buf.append(c);
}
}
}
private void appendLineDiv(final StringBuffer buf,
final boolean closePrevious) {
if (closePrevious) {
buf.append("<br/></div>\n");
}
buf.append("<div class='line' id='C" + lineNumber + "'>");
lineNumber++;
}
/**
* Return a StringBuffer with colored tokens as specified from the
* coloredTokens. There should be one-to-one correspondence with the actual
* tokens.
*/
public StringBuffer getHTMLwithColors(
final List<ColoredToken> coloredTokens, final File codeFile)
throws IOException, InstantiationException, IllegalAccessException {
final String code = FileUtils.readFileToString(codeFile);
lineNumber = 1;
final StringBuffer buf = new StringBuffer();
| final SortedMap<Integer, FullToken> toks = tokenizer |
mast-group/codemining-core | src/test/java/codemining/java/codeutils/binding/JavaTypeBindingExtractorTest.java | // Path: src/test/java/codemining/java/codeutils/JavaAstExtractorTest.java
// public class JavaAstExtractorTest {
//
// String classContent;
// String methodContent;
//
// @Before
// public void setUp() throws IOException {
// classContent = FileUtils.readFileToString(new File(
// JavaAstExtractorTest.class.getClassLoader()
// .getResource("SampleClass.txt").getFile()));
//
// methodContent = FileUtils.readFileToString(new File(
// JavaAstExtractorTest.class.getClassLoader()
// .getResource("SampleMethod.txt").getFile()));
// }
//
// /**
// * Test method for
// * {@link codemining.java.codeutils.JavaASTExtractor#getBestEffortAst(java.lang.String)}
// * .
// *
// * @throws IOException
// */
// @Test
// public void testGetASTString() {
// final JavaASTExtractor ex = new JavaASTExtractor(false);
// assertTrue(classContent.length() > 0);
// final ASTNode classCU = ex.getASTNode(classContent,
// ParseType.COMPILATION_UNIT);
// assertTrue(snippetMatchesAstTokens(classContent, classCU));
//
// assertTrue(methodContent.length() > 0);
// final ASTNode methodCU = ex.getASTNode(methodContent,
// ParseType.METHOD);
// assertTrue(snippetMatchesAstTokens(methodContent, methodCU));
// }
//
// private boolean snippetMatchesAstTokens(final String snippetCode,
// final ASTNode node) {
// final JavaTokenizer tokenizer = new JavaTokenizer();
// final List<String> snippetTokens = tokenizer
// .tokenListFromCode(snippetCode.toCharArray());
// final List<String> astTokens = tokenizer.tokenListFromCode(node
// .toString().toCharArray());
// return astTokens.equals(snippetTokens);
// }
// }
//
// Path: src/main/java/codemining/languagetools/bindings/TokenNameBinding.java
// public class TokenNameBinding implements Serializable {
// private static final long serialVersionUID = 2020613810485746430L;
//
// /**
// * The tokens of source code.
// */
// public final List<String> sourceCodeTokens;
//
// /**
// * The positions in sourceCodeTokens that contain the given name.
// */
// public final Set<Integer> nameIndexes;
//
// /**
// * Features of the binding
// */
// public final Set<String> features;
//
// public TokenNameBinding(final Set<Integer> nameIndexes,
// final List<String> sourceCodeTokens, final Set<String> features) {
// checkArgument(nameIndexes.size() > 0);
// checkArgument(sourceCodeTokens.size() > 0);
// this.nameIndexes = Collections.unmodifiableSet(nameIndexes);
// this.sourceCodeTokens = Collections.unmodifiableList(sourceCodeTokens);
// this.features = features;
// }
//
// @Override
// public boolean equals(final Object obj) {
// if (this == obj) {
// return true;
// }
// if (obj == null) {
// return false;
// }
// if (getClass() != obj.getClass()) {
// return false;
// }
// final TokenNameBinding other = (TokenNameBinding) obj;
// return Objects.equal(nameIndexes, other.nameIndexes)
// && Objects.equal(features, other.features)
// && Objects.equal(sourceCodeTokens, other.sourceCodeTokens);
// }
//
// public String getName() {
// return sourceCodeTokens.get(nameIndexes.iterator().next());
// }
//
// @Override
// public int hashCode() {
// return Objects.hashCode(sourceCodeTokens, nameIndexes, features);
// }
//
// /**
// * Rename this name to the given binding. The source code tokens included in
// * this struct, now represent the new structure.
// *
// * @param name
// * @return
// */
// public TokenNameBinding renameTo(final String name) {
// final List<String> renamedCode = Lists.newArrayList(sourceCodeTokens);
// for (final int position : nameIndexes) {
// renamedCode.set(position, name);
// }
// return new TokenNameBinding(nameIndexes, renamedCode, features);
// }
//
// @Override
// public String toString() {
// return getName() + nameIndexes + " " + features;
// }
// }
| import static org.junit.Assert.assertEquals;
import java.io.File;
import java.io.IOException;
import java.util.List;
import org.apache.commons.io.FileUtils;
import org.junit.Before;
import org.junit.Test;
import codemining.java.codeutils.JavaAstExtractorTest;
import codemining.languagetools.bindings.TokenNameBinding; | package codemining.java.codeutils.binding;
public class JavaTypeBindingExtractorTest {
File classContent;
File classContent2;
String methodContent;
@Before
public void setUp() throws IOException { | // Path: src/test/java/codemining/java/codeutils/JavaAstExtractorTest.java
// public class JavaAstExtractorTest {
//
// String classContent;
// String methodContent;
//
// @Before
// public void setUp() throws IOException {
// classContent = FileUtils.readFileToString(new File(
// JavaAstExtractorTest.class.getClassLoader()
// .getResource("SampleClass.txt").getFile()));
//
// methodContent = FileUtils.readFileToString(new File(
// JavaAstExtractorTest.class.getClassLoader()
// .getResource("SampleMethod.txt").getFile()));
// }
//
// /**
// * Test method for
// * {@link codemining.java.codeutils.JavaASTExtractor#getBestEffortAst(java.lang.String)}
// * .
// *
// * @throws IOException
// */
// @Test
// public void testGetASTString() {
// final JavaASTExtractor ex = new JavaASTExtractor(false);
// assertTrue(classContent.length() > 0);
// final ASTNode classCU = ex.getASTNode(classContent,
// ParseType.COMPILATION_UNIT);
// assertTrue(snippetMatchesAstTokens(classContent, classCU));
//
// assertTrue(methodContent.length() > 0);
// final ASTNode methodCU = ex.getASTNode(methodContent,
// ParseType.METHOD);
// assertTrue(snippetMatchesAstTokens(methodContent, methodCU));
// }
//
// private boolean snippetMatchesAstTokens(final String snippetCode,
// final ASTNode node) {
// final JavaTokenizer tokenizer = new JavaTokenizer();
// final List<String> snippetTokens = tokenizer
// .tokenListFromCode(snippetCode.toCharArray());
// final List<String> astTokens = tokenizer.tokenListFromCode(node
// .toString().toCharArray());
// return astTokens.equals(snippetTokens);
// }
// }
//
// Path: src/main/java/codemining/languagetools/bindings/TokenNameBinding.java
// public class TokenNameBinding implements Serializable {
// private static final long serialVersionUID = 2020613810485746430L;
//
// /**
// * The tokens of source code.
// */
// public final List<String> sourceCodeTokens;
//
// /**
// * The positions in sourceCodeTokens that contain the given name.
// */
// public final Set<Integer> nameIndexes;
//
// /**
// * Features of the binding
// */
// public final Set<String> features;
//
// public TokenNameBinding(final Set<Integer> nameIndexes,
// final List<String> sourceCodeTokens, final Set<String> features) {
// checkArgument(nameIndexes.size() > 0);
// checkArgument(sourceCodeTokens.size() > 0);
// this.nameIndexes = Collections.unmodifiableSet(nameIndexes);
// this.sourceCodeTokens = Collections.unmodifiableList(sourceCodeTokens);
// this.features = features;
// }
//
// @Override
// public boolean equals(final Object obj) {
// if (this == obj) {
// return true;
// }
// if (obj == null) {
// return false;
// }
// if (getClass() != obj.getClass()) {
// return false;
// }
// final TokenNameBinding other = (TokenNameBinding) obj;
// return Objects.equal(nameIndexes, other.nameIndexes)
// && Objects.equal(features, other.features)
// && Objects.equal(sourceCodeTokens, other.sourceCodeTokens);
// }
//
// public String getName() {
// return sourceCodeTokens.get(nameIndexes.iterator().next());
// }
//
// @Override
// public int hashCode() {
// return Objects.hashCode(sourceCodeTokens, nameIndexes, features);
// }
//
// /**
// * Rename this name to the given binding. The source code tokens included in
// * this struct, now represent the new structure.
// *
// * @param name
// * @return
// */
// public TokenNameBinding renameTo(final String name) {
// final List<String> renamedCode = Lists.newArrayList(sourceCodeTokens);
// for (final int position : nameIndexes) {
// renamedCode.set(position, name);
// }
// return new TokenNameBinding(nameIndexes, renamedCode, features);
// }
//
// @Override
// public String toString() {
// return getName() + nameIndexes + " " + features;
// }
// }
// Path: src/test/java/codemining/java/codeutils/binding/JavaTypeBindingExtractorTest.java
import static org.junit.Assert.assertEquals;
import java.io.File;
import java.io.IOException;
import java.util.List;
import org.apache.commons.io.FileUtils;
import org.junit.Before;
import org.junit.Test;
import codemining.java.codeutils.JavaAstExtractorTest;
import codemining.languagetools.bindings.TokenNameBinding;
package codemining.java.codeutils.binding;
public class JavaTypeBindingExtractorTest {
File classContent;
File classContent2;
String methodContent;
@Before
public void setUp() throws IOException { | classContent = new File(JavaAstExtractorTest.class.getClassLoader() |
mast-group/codemining-core | src/test/java/codemining/java/codeutils/binding/JavaTypeBindingExtractorTest.java | // Path: src/test/java/codemining/java/codeutils/JavaAstExtractorTest.java
// public class JavaAstExtractorTest {
//
// String classContent;
// String methodContent;
//
// @Before
// public void setUp() throws IOException {
// classContent = FileUtils.readFileToString(new File(
// JavaAstExtractorTest.class.getClassLoader()
// .getResource("SampleClass.txt").getFile()));
//
// methodContent = FileUtils.readFileToString(new File(
// JavaAstExtractorTest.class.getClassLoader()
// .getResource("SampleMethod.txt").getFile()));
// }
//
// /**
// * Test method for
// * {@link codemining.java.codeutils.JavaASTExtractor#getBestEffortAst(java.lang.String)}
// * .
// *
// * @throws IOException
// */
// @Test
// public void testGetASTString() {
// final JavaASTExtractor ex = new JavaASTExtractor(false);
// assertTrue(classContent.length() > 0);
// final ASTNode classCU = ex.getASTNode(classContent,
// ParseType.COMPILATION_UNIT);
// assertTrue(snippetMatchesAstTokens(classContent, classCU));
//
// assertTrue(methodContent.length() > 0);
// final ASTNode methodCU = ex.getASTNode(methodContent,
// ParseType.METHOD);
// assertTrue(snippetMatchesAstTokens(methodContent, methodCU));
// }
//
// private boolean snippetMatchesAstTokens(final String snippetCode,
// final ASTNode node) {
// final JavaTokenizer tokenizer = new JavaTokenizer();
// final List<String> snippetTokens = tokenizer
// .tokenListFromCode(snippetCode.toCharArray());
// final List<String> astTokens = tokenizer.tokenListFromCode(node
// .toString().toCharArray());
// return astTokens.equals(snippetTokens);
// }
// }
//
// Path: src/main/java/codemining/languagetools/bindings/TokenNameBinding.java
// public class TokenNameBinding implements Serializable {
// private static final long serialVersionUID = 2020613810485746430L;
//
// /**
// * The tokens of source code.
// */
// public final List<String> sourceCodeTokens;
//
// /**
// * The positions in sourceCodeTokens that contain the given name.
// */
// public final Set<Integer> nameIndexes;
//
// /**
// * Features of the binding
// */
// public final Set<String> features;
//
// public TokenNameBinding(final Set<Integer> nameIndexes,
// final List<String> sourceCodeTokens, final Set<String> features) {
// checkArgument(nameIndexes.size() > 0);
// checkArgument(sourceCodeTokens.size() > 0);
// this.nameIndexes = Collections.unmodifiableSet(nameIndexes);
// this.sourceCodeTokens = Collections.unmodifiableList(sourceCodeTokens);
// this.features = features;
// }
//
// @Override
// public boolean equals(final Object obj) {
// if (this == obj) {
// return true;
// }
// if (obj == null) {
// return false;
// }
// if (getClass() != obj.getClass()) {
// return false;
// }
// final TokenNameBinding other = (TokenNameBinding) obj;
// return Objects.equal(nameIndexes, other.nameIndexes)
// && Objects.equal(features, other.features)
// && Objects.equal(sourceCodeTokens, other.sourceCodeTokens);
// }
//
// public String getName() {
// return sourceCodeTokens.get(nameIndexes.iterator().next());
// }
//
// @Override
// public int hashCode() {
// return Objects.hashCode(sourceCodeTokens, nameIndexes, features);
// }
//
// /**
// * Rename this name to the given binding. The source code tokens included in
// * this struct, now represent the new structure.
// *
// * @param name
// * @return
// */
// public TokenNameBinding renameTo(final String name) {
// final List<String> renamedCode = Lists.newArrayList(sourceCodeTokens);
// for (final int position : nameIndexes) {
// renamedCode.set(position, name);
// }
// return new TokenNameBinding(nameIndexes, renamedCode, features);
// }
//
// @Override
// public String toString() {
// return getName() + nameIndexes + " " + features;
// }
// }
| import static org.junit.Assert.assertEquals;
import java.io.File;
import java.io.IOException;
import java.util.List;
import org.apache.commons.io.FileUtils;
import org.junit.Before;
import org.junit.Test;
import codemining.java.codeutils.JavaAstExtractorTest;
import codemining.languagetools.bindings.TokenNameBinding; | package codemining.java.codeutils.binding;
public class JavaTypeBindingExtractorTest {
File classContent;
File classContent2;
String methodContent;
@Before
public void setUp() throws IOException {
classContent = new File(JavaAstExtractorTest.class.getClassLoader()
.getResource("SampleClass.txt").getFile());
classContent2 = new File(JavaAstExtractorTest.class.getClassLoader()
.getResource("SampleClass2.txt").getFile());
methodContent = FileUtils.readFileToString(new File(
JavaAstExtractorTest.class.getClassLoader()
.getResource("SampleMethod.txt").getFile()));
}
@Test
public void testClassLevelBindings() throws IOException {
final JavaTypeDeclarationBindingExtractor jame = new JavaTypeDeclarationBindingExtractor();
| // Path: src/test/java/codemining/java/codeutils/JavaAstExtractorTest.java
// public class JavaAstExtractorTest {
//
// String classContent;
// String methodContent;
//
// @Before
// public void setUp() throws IOException {
// classContent = FileUtils.readFileToString(new File(
// JavaAstExtractorTest.class.getClassLoader()
// .getResource("SampleClass.txt").getFile()));
//
// methodContent = FileUtils.readFileToString(new File(
// JavaAstExtractorTest.class.getClassLoader()
// .getResource("SampleMethod.txt").getFile()));
// }
//
// /**
// * Test method for
// * {@link codemining.java.codeutils.JavaASTExtractor#getBestEffortAst(java.lang.String)}
// * .
// *
// * @throws IOException
// */
// @Test
// public void testGetASTString() {
// final JavaASTExtractor ex = new JavaASTExtractor(false);
// assertTrue(classContent.length() > 0);
// final ASTNode classCU = ex.getASTNode(classContent,
// ParseType.COMPILATION_UNIT);
// assertTrue(snippetMatchesAstTokens(classContent, classCU));
//
// assertTrue(methodContent.length() > 0);
// final ASTNode methodCU = ex.getASTNode(methodContent,
// ParseType.METHOD);
// assertTrue(snippetMatchesAstTokens(methodContent, methodCU));
// }
//
// private boolean snippetMatchesAstTokens(final String snippetCode,
// final ASTNode node) {
// final JavaTokenizer tokenizer = new JavaTokenizer();
// final List<String> snippetTokens = tokenizer
// .tokenListFromCode(snippetCode.toCharArray());
// final List<String> astTokens = tokenizer.tokenListFromCode(node
// .toString().toCharArray());
// return astTokens.equals(snippetTokens);
// }
// }
//
// Path: src/main/java/codemining/languagetools/bindings/TokenNameBinding.java
// public class TokenNameBinding implements Serializable {
// private static final long serialVersionUID = 2020613810485746430L;
//
// /**
// * The tokens of source code.
// */
// public final List<String> sourceCodeTokens;
//
// /**
// * The positions in sourceCodeTokens that contain the given name.
// */
// public final Set<Integer> nameIndexes;
//
// /**
// * Features of the binding
// */
// public final Set<String> features;
//
// public TokenNameBinding(final Set<Integer> nameIndexes,
// final List<String> sourceCodeTokens, final Set<String> features) {
// checkArgument(nameIndexes.size() > 0);
// checkArgument(sourceCodeTokens.size() > 0);
// this.nameIndexes = Collections.unmodifiableSet(nameIndexes);
// this.sourceCodeTokens = Collections.unmodifiableList(sourceCodeTokens);
// this.features = features;
// }
//
// @Override
// public boolean equals(final Object obj) {
// if (this == obj) {
// return true;
// }
// if (obj == null) {
// return false;
// }
// if (getClass() != obj.getClass()) {
// return false;
// }
// final TokenNameBinding other = (TokenNameBinding) obj;
// return Objects.equal(nameIndexes, other.nameIndexes)
// && Objects.equal(features, other.features)
// && Objects.equal(sourceCodeTokens, other.sourceCodeTokens);
// }
//
// public String getName() {
// return sourceCodeTokens.get(nameIndexes.iterator().next());
// }
//
// @Override
// public int hashCode() {
// return Objects.hashCode(sourceCodeTokens, nameIndexes, features);
// }
//
// /**
// * Rename this name to the given binding. The source code tokens included in
// * this struct, now represent the new structure.
// *
// * @param name
// * @return
// */
// public TokenNameBinding renameTo(final String name) {
// final List<String> renamedCode = Lists.newArrayList(sourceCodeTokens);
// for (final int position : nameIndexes) {
// renamedCode.set(position, name);
// }
// return new TokenNameBinding(nameIndexes, renamedCode, features);
// }
//
// @Override
// public String toString() {
// return getName() + nameIndexes + " " + features;
// }
// }
// Path: src/test/java/codemining/java/codeutils/binding/JavaTypeBindingExtractorTest.java
import static org.junit.Assert.assertEquals;
import java.io.File;
import java.io.IOException;
import java.util.List;
import org.apache.commons.io.FileUtils;
import org.junit.Before;
import org.junit.Test;
import codemining.java.codeutils.JavaAstExtractorTest;
import codemining.languagetools.bindings.TokenNameBinding;
package codemining.java.codeutils.binding;
public class JavaTypeBindingExtractorTest {
File classContent;
File classContent2;
String methodContent;
@Before
public void setUp() throws IOException {
classContent = new File(JavaAstExtractorTest.class.getClassLoader()
.getResource("SampleClass.txt").getFile());
classContent2 = new File(JavaAstExtractorTest.class.getClassLoader()
.getResource("SampleClass2.txt").getFile());
methodContent = FileUtils.readFileToString(new File(
JavaAstExtractorTest.class.getClassLoader()
.getResource("SampleMethod.txt").getFile()));
}
@Test
public void testClassLevelBindings() throws IOException {
final JavaTypeDeclarationBindingExtractor jame = new JavaTypeDeclarationBindingExtractor();
| final List<TokenNameBinding> classTypeindings = jame |
mast-group/codemining-core | src/main/java/codemining/cpp/codeutils/CppASTAnnotatedTokenizer.java | // Path: src/main/java/codemining/languagetools/ITokenizer.java
// public interface ITokenizer extends Serializable {
//
// public static class FullToken implements Serializable {
//
// private static final long serialVersionUID = -49456240173307314L;
//
// public static final Function<FullToken, String> TOKEN_NAME_CONVERTER = new Function<FullToken, String>() {
// @Override
// public String apply(final FullToken input) {
// return input.token;
// }
// };
//
// public final String token;
//
// public final String tokenType;
//
// public FullToken(final FullToken other) {
// token = other.token;
// tokenType = other.tokenType;
// }
//
// public FullToken(final String tokName, final String tokType) {
// token = tokName;
// tokenType = tokType;
// }
//
// @Override
// public boolean equals(final Object obj) {
// if (!(obj instanceof FullToken)) {
// return false;
// }
// final FullToken other = (FullToken) obj;
// return other.token.equals(token)
// && other.tokenType.equals(tokenType);
// }
//
// @Override
// public int hashCode() {
// return Objects.hashCode(token, tokenType);
// }
//
// @Override
// public String toString() {
// return token + " (" + tokenType + ")";
// }
//
// }
//
// /**
// * A sentence end (constant) token
// */
// static final String SENTENCE_END = "<SENTENCE_END/>";
//
// /**
// * A sentence start (constant) token
// */
// static final String SENTENCE_START = "<SENTENCE_START>";
//
// /**
// * Return a list with the full tokens.
// *
// * @param code
// * @return
// */
// SortedMap<Integer, FullToken> fullTokenListWithPos(final char[] code);
//
// /**
// * Return a file filter, filtering the files that can be tokenized.
// *
// * @return
// *
// */
// AbstractFileFilter getFileFilter();
//
// /**
// * Return the token type that signifies that a token is an identifier.
// *
// * @return
// */
// String getIdentifierType();
//
// /**
// * Return the token types that are keywords.
// *
// * @return
// */
// Collection<String> getKeywordTypes();
//
// /**
// * Return the types the represent literals.
// *
// * @return
// */
// Collection<String> getLiteralTypes();
//
// /**
// * Return a full token given a string token.
// *
// * @param token
// * @return
// */
// FullToken getTokenFromString(final String token);
//
// /**
// * Get the list of tokens from the code.
// *
// * @param code
// * @return
// */
// List<FullToken> getTokenListFromCode(final char[] code);
//
// /**
// * Get the list of tokens from the code.
// *
// * @param code
// * @return
// */
// List<FullToken> getTokenListFromCode(final File codeFile)
// throws IOException;
//
// /**
// * Tokenize some code.
// *
// * @param code
// * the code
// * @return a list of tokens
// */
// List<String> tokenListFromCode(final char[] code);
//
// /**
// * Tokenize code given a file.
// *
// * @param codeFile
// * @return
// */
// List<String> tokenListFromCode(final File codeFile) throws IOException;
//
// /**
// * Return a list of tokens along with their positions.
// *
// * @param code
// * @return
// */
// SortedMap<Integer, String> tokenListWithPos(final char[] code);
//
// /**
// * Return a list of tokens along with their positions.
// *
// * @param file
// * @return
// * @throws IOException
// */
// SortedMap<Integer, FullToken> tokenListWithPos(File file)
// throws IOException;
//
// }
| import codemining.languagetools.ITokenizer; | /**
*
*/
package codemining.cpp.codeutils;
/**
* A C++ AST Annotated Tokenizer
*
* @author Miltos Allamanis <[email protected]>
*
*/
public class CppASTAnnotatedTokenizer extends AbstractCdtASTAnnotatedTokenizer {
private static final long serialVersionUID = -8016456170070671980L;
/**
*
*/
public CppASTAnnotatedTokenizer() {
super(CppASTExtractor.class, "");
}
/**
* @param base
*/ | // Path: src/main/java/codemining/languagetools/ITokenizer.java
// public interface ITokenizer extends Serializable {
//
// public static class FullToken implements Serializable {
//
// private static final long serialVersionUID = -49456240173307314L;
//
// public static final Function<FullToken, String> TOKEN_NAME_CONVERTER = new Function<FullToken, String>() {
// @Override
// public String apply(final FullToken input) {
// return input.token;
// }
// };
//
// public final String token;
//
// public final String tokenType;
//
// public FullToken(final FullToken other) {
// token = other.token;
// tokenType = other.tokenType;
// }
//
// public FullToken(final String tokName, final String tokType) {
// token = tokName;
// tokenType = tokType;
// }
//
// @Override
// public boolean equals(final Object obj) {
// if (!(obj instanceof FullToken)) {
// return false;
// }
// final FullToken other = (FullToken) obj;
// return other.token.equals(token)
// && other.tokenType.equals(tokenType);
// }
//
// @Override
// public int hashCode() {
// return Objects.hashCode(token, tokenType);
// }
//
// @Override
// public String toString() {
// return token + " (" + tokenType + ")";
// }
//
// }
//
// /**
// * A sentence end (constant) token
// */
// static final String SENTENCE_END = "<SENTENCE_END/>";
//
// /**
// * A sentence start (constant) token
// */
// static final String SENTENCE_START = "<SENTENCE_START>";
//
// /**
// * Return a list with the full tokens.
// *
// * @param code
// * @return
// */
// SortedMap<Integer, FullToken> fullTokenListWithPos(final char[] code);
//
// /**
// * Return a file filter, filtering the files that can be tokenized.
// *
// * @return
// *
// */
// AbstractFileFilter getFileFilter();
//
// /**
// * Return the token type that signifies that a token is an identifier.
// *
// * @return
// */
// String getIdentifierType();
//
// /**
// * Return the token types that are keywords.
// *
// * @return
// */
// Collection<String> getKeywordTypes();
//
// /**
// * Return the types the represent literals.
// *
// * @return
// */
// Collection<String> getLiteralTypes();
//
// /**
// * Return a full token given a string token.
// *
// * @param token
// * @return
// */
// FullToken getTokenFromString(final String token);
//
// /**
// * Get the list of tokens from the code.
// *
// * @param code
// * @return
// */
// List<FullToken> getTokenListFromCode(final char[] code);
//
// /**
// * Get the list of tokens from the code.
// *
// * @param code
// * @return
// */
// List<FullToken> getTokenListFromCode(final File codeFile)
// throws IOException;
//
// /**
// * Tokenize some code.
// *
// * @param code
// * the code
// * @return a list of tokens
// */
// List<String> tokenListFromCode(final char[] code);
//
// /**
// * Tokenize code given a file.
// *
// * @param codeFile
// * @return
// */
// List<String> tokenListFromCode(final File codeFile) throws IOException;
//
// /**
// * Return a list of tokens along with their positions.
// *
// * @param code
// * @return
// */
// SortedMap<Integer, String> tokenListWithPos(final char[] code);
//
// /**
// * Return a list of tokens along with their positions.
// *
// * @param file
// * @return
// * @throws IOException
// */
// SortedMap<Integer, FullToken> tokenListWithPos(File file)
// throws IOException;
//
// }
// Path: src/main/java/codemining/cpp/codeutils/CppASTAnnotatedTokenizer.java
import codemining.languagetools.ITokenizer;
/**
*
*/
package codemining.cpp.codeutils;
/**
* A C++ AST Annotated Tokenizer
*
* @author Miltos Allamanis <[email protected]>
*
*/
public class CppASTAnnotatedTokenizer extends AbstractCdtASTAnnotatedTokenizer {
private static final long serialVersionUID = -8016456170070671980L;
/**
*
*/
public CppASTAnnotatedTokenizer() {
super(CppASTExtractor.class, "");
}
/**
* @param base
*/ | public CppASTAnnotatedTokenizer(final ITokenizer base) { |
mast-group/codemining-core | src/main/java/codemining/cpp/codeutils/CASTAnnotatedTokenizer.java | // Path: src/main/java/codemining/languagetools/ITokenizer.java
// public interface ITokenizer extends Serializable {
//
// public static class FullToken implements Serializable {
//
// private static final long serialVersionUID = -49456240173307314L;
//
// public static final Function<FullToken, String> TOKEN_NAME_CONVERTER = new Function<FullToken, String>() {
// @Override
// public String apply(final FullToken input) {
// return input.token;
// }
// };
//
// public final String token;
//
// public final String tokenType;
//
// public FullToken(final FullToken other) {
// token = other.token;
// tokenType = other.tokenType;
// }
//
// public FullToken(final String tokName, final String tokType) {
// token = tokName;
// tokenType = tokType;
// }
//
// @Override
// public boolean equals(final Object obj) {
// if (!(obj instanceof FullToken)) {
// return false;
// }
// final FullToken other = (FullToken) obj;
// return other.token.equals(token)
// && other.tokenType.equals(tokenType);
// }
//
// @Override
// public int hashCode() {
// return Objects.hashCode(token, tokenType);
// }
//
// @Override
// public String toString() {
// return token + " (" + tokenType + ")";
// }
//
// }
//
// /**
// * A sentence end (constant) token
// */
// static final String SENTENCE_END = "<SENTENCE_END/>";
//
// /**
// * A sentence start (constant) token
// */
// static final String SENTENCE_START = "<SENTENCE_START>";
//
// /**
// * Return a list with the full tokens.
// *
// * @param code
// * @return
// */
// SortedMap<Integer, FullToken> fullTokenListWithPos(final char[] code);
//
// /**
// * Return a file filter, filtering the files that can be tokenized.
// *
// * @return
// *
// */
// AbstractFileFilter getFileFilter();
//
// /**
// * Return the token type that signifies that a token is an identifier.
// *
// * @return
// */
// String getIdentifierType();
//
// /**
// * Return the token types that are keywords.
// *
// * @return
// */
// Collection<String> getKeywordTypes();
//
// /**
// * Return the types the represent literals.
// *
// * @return
// */
// Collection<String> getLiteralTypes();
//
// /**
// * Return a full token given a string token.
// *
// * @param token
// * @return
// */
// FullToken getTokenFromString(final String token);
//
// /**
// * Get the list of tokens from the code.
// *
// * @param code
// * @return
// */
// List<FullToken> getTokenListFromCode(final char[] code);
//
// /**
// * Get the list of tokens from the code.
// *
// * @param code
// * @return
// */
// List<FullToken> getTokenListFromCode(final File codeFile)
// throws IOException;
//
// /**
// * Tokenize some code.
// *
// * @param code
// * the code
// * @return a list of tokens
// */
// List<String> tokenListFromCode(final char[] code);
//
// /**
// * Tokenize code given a file.
// *
// * @param codeFile
// * @return
// */
// List<String> tokenListFromCode(final File codeFile) throws IOException;
//
// /**
// * Return a list of tokens along with their positions.
// *
// * @param code
// * @return
// */
// SortedMap<Integer, String> tokenListWithPos(final char[] code);
//
// /**
// * Return a list of tokens along with their positions.
// *
// * @param file
// * @return
// * @throws IOException
// */
// SortedMap<Integer, FullToken> tokenListWithPos(File file)
// throws IOException;
//
// }
| import codemining.languagetools.ITokenizer; | /**
*
*/
package codemining.cpp.codeutils;
/**
* A C AST annotated tokenizer.
*
* @author Miltos Allamanis<[email protected]>
*
*/
public class CASTAnnotatedTokenizer extends AbstractCdtASTAnnotatedTokenizer {
private static final long serialVersionUID = 6395574519739472995L;
/**
* @param extractorClass
*/
public CASTAnnotatedTokenizer() {
super(CAstExtractor.class, "");
}
/**
* @param base
* @param extractorClass
*/ | // Path: src/main/java/codemining/languagetools/ITokenizer.java
// public interface ITokenizer extends Serializable {
//
// public static class FullToken implements Serializable {
//
// private static final long serialVersionUID = -49456240173307314L;
//
// public static final Function<FullToken, String> TOKEN_NAME_CONVERTER = new Function<FullToken, String>() {
// @Override
// public String apply(final FullToken input) {
// return input.token;
// }
// };
//
// public final String token;
//
// public final String tokenType;
//
// public FullToken(final FullToken other) {
// token = other.token;
// tokenType = other.tokenType;
// }
//
// public FullToken(final String tokName, final String tokType) {
// token = tokName;
// tokenType = tokType;
// }
//
// @Override
// public boolean equals(final Object obj) {
// if (!(obj instanceof FullToken)) {
// return false;
// }
// final FullToken other = (FullToken) obj;
// return other.token.equals(token)
// && other.tokenType.equals(tokenType);
// }
//
// @Override
// public int hashCode() {
// return Objects.hashCode(token, tokenType);
// }
//
// @Override
// public String toString() {
// return token + " (" + tokenType + ")";
// }
//
// }
//
// /**
// * A sentence end (constant) token
// */
// static final String SENTENCE_END = "<SENTENCE_END/>";
//
// /**
// * A sentence start (constant) token
// */
// static final String SENTENCE_START = "<SENTENCE_START>";
//
// /**
// * Return a list with the full tokens.
// *
// * @param code
// * @return
// */
// SortedMap<Integer, FullToken> fullTokenListWithPos(final char[] code);
//
// /**
// * Return a file filter, filtering the files that can be tokenized.
// *
// * @return
// *
// */
// AbstractFileFilter getFileFilter();
//
// /**
// * Return the token type that signifies that a token is an identifier.
// *
// * @return
// */
// String getIdentifierType();
//
// /**
// * Return the token types that are keywords.
// *
// * @return
// */
// Collection<String> getKeywordTypes();
//
// /**
// * Return the types the represent literals.
// *
// * @return
// */
// Collection<String> getLiteralTypes();
//
// /**
// * Return a full token given a string token.
// *
// * @param token
// * @return
// */
// FullToken getTokenFromString(final String token);
//
// /**
// * Get the list of tokens from the code.
// *
// * @param code
// * @return
// */
// List<FullToken> getTokenListFromCode(final char[] code);
//
// /**
// * Get the list of tokens from the code.
// *
// * @param code
// * @return
// */
// List<FullToken> getTokenListFromCode(final File codeFile)
// throws IOException;
//
// /**
// * Tokenize some code.
// *
// * @param code
// * the code
// * @return a list of tokens
// */
// List<String> tokenListFromCode(final char[] code);
//
// /**
// * Tokenize code given a file.
// *
// * @param codeFile
// * @return
// */
// List<String> tokenListFromCode(final File codeFile) throws IOException;
//
// /**
// * Return a list of tokens along with their positions.
// *
// * @param code
// * @return
// */
// SortedMap<Integer, String> tokenListWithPos(final char[] code);
//
// /**
// * Return a list of tokens along with their positions.
// *
// * @param file
// * @return
// * @throws IOException
// */
// SortedMap<Integer, FullToken> tokenListWithPos(File file)
// throws IOException;
//
// }
// Path: src/main/java/codemining/cpp/codeutils/CASTAnnotatedTokenizer.java
import codemining.languagetools.ITokenizer;
/**
*
*/
package codemining.cpp.codeutils;
/**
* A C AST annotated tokenizer.
*
* @author Miltos Allamanis<[email protected]>
*
*/
public class CASTAnnotatedTokenizer extends AbstractCdtASTAnnotatedTokenizer {
private static final long serialVersionUID = 6395574519739472995L;
/**
* @param extractorClass
*/
public CASTAnnotatedTokenizer() {
super(CAstExtractor.class, "");
}
/**
* @param base
* @param extractorClass
*/ | public CASTAnnotatedTokenizer(final ITokenizer base) { |
mast-group/codemining-core | src/main/java/codemining/js/codeutils/JavascriptASTExtractor.java | // Path: src/main/java/codemining/languagetools/ParseType.java
// public enum ParseType {
// COMPILATION_UNIT, CLASS_BODY, METHOD, STATEMENTS, EXPRESSION
// }
| import java.io.File;
import java.io.IOException;
import java.util.Hashtable;
import java.util.Map;
import org.apache.commons.io.FileUtils;
import org.eclipse.wst.jsdt.core.JavaScriptCore;
import org.eclipse.wst.jsdt.core.dom.AST;
import org.eclipse.wst.jsdt.core.dom.ASTNode;
import org.eclipse.wst.jsdt.core.dom.ASTParser;
import org.eclipse.wst.jsdt.core.dom.ASTVisitor;
import org.eclipse.wst.jsdt.core.dom.FunctionDeclaration;
import org.eclipse.wst.jsdt.core.dom.JavaScriptUnit;
import codemining.languagetools.ParseType; | parser.setCompilerOptions(options);
parser.setSource(sourceFile.toCharArray()); // set source
parser.setResolveBindings(useBindings);
parser.setBindingsRecovery(useBindings);
parser.setStatementsRecovery(true);
parser.setUnitName(file.getAbsolutePath());
// FIXME Need file's project loaded into Eclipse to get bindings
// which is only possible automatically if this were an Eclipse plugin
// cf. https://bugs.eclipse.org/bugs/show_bug.cgi?id=206391
// final IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
// final IProject project = root.getProject(projectName);
// parser.setProject(JavaScriptCore.create(project));
final JavaScriptUnit compilationUnit = (JavaScriptUnit) parser
.createAST(null);
return compilationUnit;
}
/**
* Get a compilation unit of the given file content.
*
* @param fileContent
* @param parseType
* @return the compilation unit
*/
public final ASTNode getAST(final String fileContent, | // Path: src/main/java/codemining/languagetools/ParseType.java
// public enum ParseType {
// COMPILATION_UNIT, CLASS_BODY, METHOD, STATEMENTS, EXPRESSION
// }
// Path: src/main/java/codemining/js/codeutils/JavascriptASTExtractor.java
import java.io.File;
import java.io.IOException;
import java.util.Hashtable;
import java.util.Map;
import org.apache.commons.io.FileUtils;
import org.eclipse.wst.jsdt.core.JavaScriptCore;
import org.eclipse.wst.jsdt.core.dom.AST;
import org.eclipse.wst.jsdt.core.dom.ASTNode;
import org.eclipse.wst.jsdt.core.dom.ASTParser;
import org.eclipse.wst.jsdt.core.dom.ASTVisitor;
import org.eclipse.wst.jsdt.core.dom.FunctionDeclaration;
import org.eclipse.wst.jsdt.core.dom.JavaScriptUnit;
import codemining.languagetools.ParseType;
parser.setCompilerOptions(options);
parser.setSource(sourceFile.toCharArray()); // set source
parser.setResolveBindings(useBindings);
parser.setBindingsRecovery(useBindings);
parser.setStatementsRecovery(true);
parser.setUnitName(file.getAbsolutePath());
// FIXME Need file's project loaded into Eclipse to get bindings
// which is only possible automatically if this were an Eclipse plugin
// cf. https://bugs.eclipse.org/bugs/show_bug.cgi?id=206391
// final IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
// final IProject project = root.getProject(projectName);
// parser.setProject(JavaScriptCore.create(project));
final JavaScriptUnit compilationUnit = (JavaScriptUnit) parser
.createAST(null);
return compilationUnit;
}
/**
* Get a compilation unit of the given file content.
*
* @param fileContent
* @param parseType
* @return the compilation unit
*/
public final ASTNode getAST(final String fileContent, | final ParseType parseType) { |
mast-group/codemining-core | src/test/java/codemining/java/codeutils/binding/JavaApproximateVariableBindingExtractorTest.java | // Path: src/test/java/codemining/java/codeutils/JavaAstExtractorTest.java
// public class JavaAstExtractorTest {
//
// String classContent;
// String methodContent;
//
// @Before
// public void setUp() throws IOException {
// classContent = FileUtils.readFileToString(new File(
// JavaAstExtractorTest.class.getClassLoader()
// .getResource("SampleClass.txt").getFile()));
//
// methodContent = FileUtils.readFileToString(new File(
// JavaAstExtractorTest.class.getClassLoader()
// .getResource("SampleMethod.txt").getFile()));
// }
//
// /**
// * Test method for
// * {@link codemining.java.codeutils.JavaASTExtractor#getBestEffortAst(java.lang.String)}
// * .
// *
// * @throws IOException
// */
// @Test
// public void testGetASTString() {
// final JavaASTExtractor ex = new JavaASTExtractor(false);
// assertTrue(classContent.length() > 0);
// final ASTNode classCU = ex.getASTNode(classContent,
// ParseType.COMPILATION_UNIT);
// assertTrue(snippetMatchesAstTokens(classContent, classCU));
//
// assertTrue(methodContent.length() > 0);
// final ASTNode methodCU = ex.getASTNode(methodContent,
// ParseType.METHOD);
// assertTrue(snippetMatchesAstTokens(methodContent, methodCU));
// }
//
// private boolean snippetMatchesAstTokens(final String snippetCode,
// final ASTNode node) {
// final JavaTokenizer tokenizer = new JavaTokenizer();
// final List<String> snippetTokens = tokenizer
// .tokenListFromCode(snippetCode.toCharArray());
// final List<String> astTokens = tokenizer.tokenListFromCode(node
// .toString().toCharArray());
// return astTokens.equals(snippetTokens);
// }
// }
//
// Path: src/main/java/codemining/languagetools/bindings/TokenNameBinding.java
// public class TokenNameBinding implements Serializable {
// private static final long serialVersionUID = 2020613810485746430L;
//
// /**
// * The tokens of source code.
// */
// public final List<String> sourceCodeTokens;
//
// /**
// * The positions in sourceCodeTokens that contain the given name.
// */
// public final Set<Integer> nameIndexes;
//
// /**
// * Features of the binding
// */
// public final Set<String> features;
//
// public TokenNameBinding(final Set<Integer> nameIndexes,
// final List<String> sourceCodeTokens, final Set<String> features) {
// checkArgument(nameIndexes.size() > 0);
// checkArgument(sourceCodeTokens.size() > 0);
// this.nameIndexes = Collections.unmodifiableSet(nameIndexes);
// this.sourceCodeTokens = Collections.unmodifiableList(sourceCodeTokens);
// this.features = features;
// }
//
// @Override
// public boolean equals(final Object obj) {
// if (this == obj) {
// return true;
// }
// if (obj == null) {
// return false;
// }
// if (getClass() != obj.getClass()) {
// return false;
// }
// final TokenNameBinding other = (TokenNameBinding) obj;
// return Objects.equal(nameIndexes, other.nameIndexes)
// && Objects.equal(features, other.features)
// && Objects.equal(sourceCodeTokens, other.sourceCodeTokens);
// }
//
// public String getName() {
// return sourceCodeTokens.get(nameIndexes.iterator().next());
// }
//
// @Override
// public int hashCode() {
// return Objects.hashCode(sourceCodeTokens, nameIndexes, features);
// }
//
// /**
// * Rename this name to the given binding. The source code tokens included in
// * this struct, now represent the new structure.
// *
// * @param name
// * @return
// */
// public TokenNameBinding renameTo(final String name) {
// final List<String> renamedCode = Lists.newArrayList(sourceCodeTokens);
// for (final int position : nameIndexes) {
// renamedCode.set(position, name);
// }
// return new TokenNameBinding(nameIndexes, renamedCode, features);
// }
//
// @Override
// public String toString() {
// return getName() + nameIndexes + " " + features;
// }
// }
| import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.io.File;
import java.io.IOException;
import java.util.Collection;
import java.util.List;
import org.apache.commons.io.FileUtils;
import org.junit.Before;
import org.junit.Test;
import codemining.java.codeutils.JavaAstExtractorTest;
import codemining.languagetools.bindings.TokenNameBinding; | package codemining.java.codeutils.binding;
public class JavaApproximateVariableBindingExtractorTest {
private static <T> void allAreContained(final Collection<T> collection,
final Collection<T> in) {
for (final T element : collection) {
assertTrue(in.contains(element));
}
}
File classContent;
File classContent2;
String methodContent;
@Before
public void setUp() throws IOException { | // Path: src/test/java/codemining/java/codeutils/JavaAstExtractorTest.java
// public class JavaAstExtractorTest {
//
// String classContent;
// String methodContent;
//
// @Before
// public void setUp() throws IOException {
// classContent = FileUtils.readFileToString(new File(
// JavaAstExtractorTest.class.getClassLoader()
// .getResource("SampleClass.txt").getFile()));
//
// methodContent = FileUtils.readFileToString(new File(
// JavaAstExtractorTest.class.getClassLoader()
// .getResource("SampleMethod.txt").getFile()));
// }
//
// /**
// * Test method for
// * {@link codemining.java.codeutils.JavaASTExtractor#getBestEffortAst(java.lang.String)}
// * .
// *
// * @throws IOException
// */
// @Test
// public void testGetASTString() {
// final JavaASTExtractor ex = new JavaASTExtractor(false);
// assertTrue(classContent.length() > 0);
// final ASTNode classCU = ex.getASTNode(classContent,
// ParseType.COMPILATION_UNIT);
// assertTrue(snippetMatchesAstTokens(classContent, classCU));
//
// assertTrue(methodContent.length() > 0);
// final ASTNode methodCU = ex.getASTNode(methodContent,
// ParseType.METHOD);
// assertTrue(snippetMatchesAstTokens(methodContent, methodCU));
// }
//
// private boolean snippetMatchesAstTokens(final String snippetCode,
// final ASTNode node) {
// final JavaTokenizer tokenizer = new JavaTokenizer();
// final List<String> snippetTokens = tokenizer
// .tokenListFromCode(snippetCode.toCharArray());
// final List<String> astTokens = tokenizer.tokenListFromCode(node
// .toString().toCharArray());
// return astTokens.equals(snippetTokens);
// }
// }
//
// Path: src/main/java/codemining/languagetools/bindings/TokenNameBinding.java
// public class TokenNameBinding implements Serializable {
// private static final long serialVersionUID = 2020613810485746430L;
//
// /**
// * The tokens of source code.
// */
// public final List<String> sourceCodeTokens;
//
// /**
// * The positions in sourceCodeTokens that contain the given name.
// */
// public final Set<Integer> nameIndexes;
//
// /**
// * Features of the binding
// */
// public final Set<String> features;
//
// public TokenNameBinding(final Set<Integer> nameIndexes,
// final List<String> sourceCodeTokens, final Set<String> features) {
// checkArgument(nameIndexes.size() > 0);
// checkArgument(sourceCodeTokens.size() > 0);
// this.nameIndexes = Collections.unmodifiableSet(nameIndexes);
// this.sourceCodeTokens = Collections.unmodifiableList(sourceCodeTokens);
// this.features = features;
// }
//
// @Override
// public boolean equals(final Object obj) {
// if (this == obj) {
// return true;
// }
// if (obj == null) {
// return false;
// }
// if (getClass() != obj.getClass()) {
// return false;
// }
// final TokenNameBinding other = (TokenNameBinding) obj;
// return Objects.equal(nameIndexes, other.nameIndexes)
// && Objects.equal(features, other.features)
// && Objects.equal(sourceCodeTokens, other.sourceCodeTokens);
// }
//
// public String getName() {
// return sourceCodeTokens.get(nameIndexes.iterator().next());
// }
//
// @Override
// public int hashCode() {
// return Objects.hashCode(sourceCodeTokens, nameIndexes, features);
// }
//
// /**
// * Rename this name to the given binding. The source code tokens included in
// * this struct, now represent the new structure.
// *
// * @param name
// * @return
// */
// public TokenNameBinding renameTo(final String name) {
// final List<String> renamedCode = Lists.newArrayList(sourceCodeTokens);
// for (final int position : nameIndexes) {
// renamedCode.set(position, name);
// }
// return new TokenNameBinding(nameIndexes, renamedCode, features);
// }
//
// @Override
// public String toString() {
// return getName() + nameIndexes + " " + features;
// }
// }
// Path: src/test/java/codemining/java/codeutils/binding/JavaApproximateVariableBindingExtractorTest.java
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.io.File;
import java.io.IOException;
import java.util.Collection;
import java.util.List;
import org.apache.commons.io.FileUtils;
import org.junit.Before;
import org.junit.Test;
import codemining.java.codeutils.JavaAstExtractorTest;
import codemining.languagetools.bindings.TokenNameBinding;
package codemining.java.codeutils.binding;
public class JavaApproximateVariableBindingExtractorTest {
private static <T> void allAreContained(final Collection<T> collection,
final Collection<T> in) {
for (final T element : collection) {
assertTrue(in.contains(element));
}
}
File classContent;
File classContent2;
String methodContent;
@Before
public void setUp() throws IOException { | classContent = new File(JavaAstExtractorTest.class.getClassLoader() |
mast-group/codemining-core | src/test/java/codemining/java/codeutils/binding/JavaApproximateVariableBindingExtractorTest.java | // Path: src/test/java/codemining/java/codeutils/JavaAstExtractorTest.java
// public class JavaAstExtractorTest {
//
// String classContent;
// String methodContent;
//
// @Before
// public void setUp() throws IOException {
// classContent = FileUtils.readFileToString(new File(
// JavaAstExtractorTest.class.getClassLoader()
// .getResource("SampleClass.txt").getFile()));
//
// methodContent = FileUtils.readFileToString(new File(
// JavaAstExtractorTest.class.getClassLoader()
// .getResource("SampleMethod.txt").getFile()));
// }
//
// /**
// * Test method for
// * {@link codemining.java.codeutils.JavaASTExtractor#getBestEffortAst(java.lang.String)}
// * .
// *
// * @throws IOException
// */
// @Test
// public void testGetASTString() {
// final JavaASTExtractor ex = new JavaASTExtractor(false);
// assertTrue(classContent.length() > 0);
// final ASTNode classCU = ex.getASTNode(classContent,
// ParseType.COMPILATION_UNIT);
// assertTrue(snippetMatchesAstTokens(classContent, classCU));
//
// assertTrue(methodContent.length() > 0);
// final ASTNode methodCU = ex.getASTNode(methodContent,
// ParseType.METHOD);
// assertTrue(snippetMatchesAstTokens(methodContent, methodCU));
// }
//
// private boolean snippetMatchesAstTokens(final String snippetCode,
// final ASTNode node) {
// final JavaTokenizer tokenizer = new JavaTokenizer();
// final List<String> snippetTokens = tokenizer
// .tokenListFromCode(snippetCode.toCharArray());
// final List<String> astTokens = tokenizer.tokenListFromCode(node
// .toString().toCharArray());
// return astTokens.equals(snippetTokens);
// }
// }
//
// Path: src/main/java/codemining/languagetools/bindings/TokenNameBinding.java
// public class TokenNameBinding implements Serializable {
// private static final long serialVersionUID = 2020613810485746430L;
//
// /**
// * The tokens of source code.
// */
// public final List<String> sourceCodeTokens;
//
// /**
// * The positions in sourceCodeTokens that contain the given name.
// */
// public final Set<Integer> nameIndexes;
//
// /**
// * Features of the binding
// */
// public final Set<String> features;
//
// public TokenNameBinding(final Set<Integer> nameIndexes,
// final List<String> sourceCodeTokens, final Set<String> features) {
// checkArgument(nameIndexes.size() > 0);
// checkArgument(sourceCodeTokens.size() > 0);
// this.nameIndexes = Collections.unmodifiableSet(nameIndexes);
// this.sourceCodeTokens = Collections.unmodifiableList(sourceCodeTokens);
// this.features = features;
// }
//
// @Override
// public boolean equals(final Object obj) {
// if (this == obj) {
// return true;
// }
// if (obj == null) {
// return false;
// }
// if (getClass() != obj.getClass()) {
// return false;
// }
// final TokenNameBinding other = (TokenNameBinding) obj;
// return Objects.equal(nameIndexes, other.nameIndexes)
// && Objects.equal(features, other.features)
// && Objects.equal(sourceCodeTokens, other.sourceCodeTokens);
// }
//
// public String getName() {
// return sourceCodeTokens.get(nameIndexes.iterator().next());
// }
//
// @Override
// public int hashCode() {
// return Objects.hashCode(sourceCodeTokens, nameIndexes, features);
// }
//
// /**
// * Rename this name to the given binding. The source code tokens included in
// * this struct, now represent the new structure.
// *
// * @param name
// * @return
// */
// public TokenNameBinding renameTo(final String name) {
// final List<String> renamedCode = Lists.newArrayList(sourceCodeTokens);
// for (final int position : nameIndexes) {
// renamedCode.set(position, name);
// }
// return new TokenNameBinding(nameIndexes, renamedCode, features);
// }
//
// @Override
// public String toString() {
// return getName() + nameIndexes + " " + features;
// }
// }
| import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.io.File;
import java.io.IOException;
import java.util.Collection;
import java.util.List;
import org.apache.commons.io.FileUtils;
import org.junit.Before;
import org.junit.Test;
import codemining.java.codeutils.JavaAstExtractorTest;
import codemining.languagetools.bindings.TokenNameBinding; | package codemining.java.codeutils.binding;
public class JavaApproximateVariableBindingExtractorTest {
private static <T> void allAreContained(final Collection<T> collection,
final Collection<T> in) {
for (final T element : collection) {
assertTrue(in.contains(element));
}
}
File classContent;
File classContent2;
String methodContent;
@Before
public void setUp() throws IOException {
classContent = new File(JavaAstExtractorTest.class.getClassLoader()
.getResource("SampleClass.txt").getFile());
classContent2 = new File(JavaAstExtractorTest.class.getClassLoader()
.getResource("SampleClass2.txt").getFile());
methodContent = FileUtils.readFileToString(new File(
JavaAstExtractorTest.class.getClassLoader()
.getResource("SampleMethod.txt").getFile()));
}
@Test
public void testClassBindings() throws IOException {
final JavaApproximateVariableBindingExtractor jabe = new JavaApproximateVariableBindingExtractor();
final JavaExactVariableBindingsExtractor jbe = new JavaExactVariableBindingsExtractor();
| // Path: src/test/java/codemining/java/codeutils/JavaAstExtractorTest.java
// public class JavaAstExtractorTest {
//
// String classContent;
// String methodContent;
//
// @Before
// public void setUp() throws IOException {
// classContent = FileUtils.readFileToString(new File(
// JavaAstExtractorTest.class.getClassLoader()
// .getResource("SampleClass.txt").getFile()));
//
// methodContent = FileUtils.readFileToString(new File(
// JavaAstExtractorTest.class.getClassLoader()
// .getResource("SampleMethod.txt").getFile()));
// }
//
// /**
// * Test method for
// * {@link codemining.java.codeutils.JavaASTExtractor#getBestEffortAst(java.lang.String)}
// * .
// *
// * @throws IOException
// */
// @Test
// public void testGetASTString() {
// final JavaASTExtractor ex = new JavaASTExtractor(false);
// assertTrue(classContent.length() > 0);
// final ASTNode classCU = ex.getASTNode(classContent,
// ParseType.COMPILATION_UNIT);
// assertTrue(snippetMatchesAstTokens(classContent, classCU));
//
// assertTrue(methodContent.length() > 0);
// final ASTNode methodCU = ex.getASTNode(methodContent,
// ParseType.METHOD);
// assertTrue(snippetMatchesAstTokens(methodContent, methodCU));
// }
//
// private boolean snippetMatchesAstTokens(final String snippetCode,
// final ASTNode node) {
// final JavaTokenizer tokenizer = new JavaTokenizer();
// final List<String> snippetTokens = tokenizer
// .tokenListFromCode(snippetCode.toCharArray());
// final List<String> astTokens = tokenizer.tokenListFromCode(node
// .toString().toCharArray());
// return astTokens.equals(snippetTokens);
// }
// }
//
// Path: src/main/java/codemining/languagetools/bindings/TokenNameBinding.java
// public class TokenNameBinding implements Serializable {
// private static final long serialVersionUID = 2020613810485746430L;
//
// /**
// * The tokens of source code.
// */
// public final List<String> sourceCodeTokens;
//
// /**
// * The positions in sourceCodeTokens that contain the given name.
// */
// public final Set<Integer> nameIndexes;
//
// /**
// * Features of the binding
// */
// public final Set<String> features;
//
// public TokenNameBinding(final Set<Integer> nameIndexes,
// final List<String> sourceCodeTokens, final Set<String> features) {
// checkArgument(nameIndexes.size() > 0);
// checkArgument(sourceCodeTokens.size() > 0);
// this.nameIndexes = Collections.unmodifiableSet(nameIndexes);
// this.sourceCodeTokens = Collections.unmodifiableList(sourceCodeTokens);
// this.features = features;
// }
//
// @Override
// public boolean equals(final Object obj) {
// if (this == obj) {
// return true;
// }
// if (obj == null) {
// return false;
// }
// if (getClass() != obj.getClass()) {
// return false;
// }
// final TokenNameBinding other = (TokenNameBinding) obj;
// return Objects.equal(nameIndexes, other.nameIndexes)
// && Objects.equal(features, other.features)
// && Objects.equal(sourceCodeTokens, other.sourceCodeTokens);
// }
//
// public String getName() {
// return sourceCodeTokens.get(nameIndexes.iterator().next());
// }
//
// @Override
// public int hashCode() {
// return Objects.hashCode(sourceCodeTokens, nameIndexes, features);
// }
//
// /**
// * Rename this name to the given binding. The source code tokens included in
// * this struct, now represent the new structure.
// *
// * @param name
// * @return
// */
// public TokenNameBinding renameTo(final String name) {
// final List<String> renamedCode = Lists.newArrayList(sourceCodeTokens);
// for (final int position : nameIndexes) {
// renamedCode.set(position, name);
// }
// return new TokenNameBinding(nameIndexes, renamedCode, features);
// }
//
// @Override
// public String toString() {
// return getName() + nameIndexes + " " + features;
// }
// }
// Path: src/test/java/codemining/java/codeutils/binding/JavaApproximateVariableBindingExtractorTest.java
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.io.File;
import java.io.IOException;
import java.util.Collection;
import java.util.List;
import org.apache.commons.io.FileUtils;
import org.junit.Before;
import org.junit.Test;
import codemining.java.codeutils.JavaAstExtractorTest;
import codemining.languagetools.bindings.TokenNameBinding;
package codemining.java.codeutils.binding;
public class JavaApproximateVariableBindingExtractorTest {
private static <T> void allAreContained(final Collection<T> collection,
final Collection<T> in) {
for (final T element : collection) {
assertTrue(in.contains(element));
}
}
File classContent;
File classContent2;
String methodContent;
@Before
public void setUp() throws IOException {
classContent = new File(JavaAstExtractorTest.class.getClassLoader()
.getResource("SampleClass.txt").getFile());
classContent2 = new File(JavaAstExtractorTest.class.getClassLoader()
.getResource("SampleClass2.txt").getFile());
methodContent = FileUtils.readFileToString(new File(
JavaAstExtractorTest.class.getClassLoader()
.getResource("SampleMethod.txt").getFile()));
}
@Test
public void testClassBindings() throws IOException {
final JavaApproximateVariableBindingExtractor jabe = new JavaApproximateVariableBindingExtractor();
final JavaExactVariableBindingsExtractor jbe = new JavaExactVariableBindingsExtractor();
| final List<TokenNameBinding> classVariableBindings = jabe |
mast-group/codemining-core | src/main/java/codemining/java/codeutils/scopes/AllScopeExtractor.java | // Path: src/main/java/codemining/languagetools/IScopeExtractor.java
// public interface IScopeExtractor {
// Multimap<Scope, String> getFromFile(final File file) throws IOException;
//
// Multimap<Scope, String> getFromNode(final ASTNode node);
//
// Multimap<Scope, String> getFromString(final String code,
// final ParseType parseType);
// }
//
// Path: src/main/java/codemining/languagetools/ParseType.java
// public enum ParseType {
// COMPILATION_UNIT, CLASS_BODY, METHOD, STATEMENTS, EXPRESSION
// }
//
// Path: src/main/java/codemining/languagetools/Scope.java
// public class Scope implements Comparable<Scope> {
//
// public enum ScopeType {
// SCOPE_CLASS, SCOPE_LOCAL, SCOPE_METHOD
// }
//
// public final String code;
//
// public final ScopeType scopeType;
//
// public final String type;
//
// public final int astNodeType;
// public final int astParentNodeType;
//
// public Scope(final String code, final ScopeType scopeType,
// final String type, final int astNodeType,
// final int astParentNodeType) {
// this.code = code;
// this.scopeType = scopeType;
// this.type = type;
// this.astNodeType = astNodeType;
// this.astParentNodeType = astParentNodeType;
// }
//
// @Override
// public int compareTo(final Scope other) {
// return ComparisonChain.start().compare(code, other.code)
// .compare(scopeType, other.scopeType).compare(type, other.type)
// .compare(astNodeType, other.astNodeType)
// .compare(astParentNodeType, other.astParentNodeType).result();
// }
//
// @Override
// public boolean equals(final Object obj) {
// if (!(obj instanceof Scope)) {
// return false;
// }
// final Scope other = (Scope) obj;
// return other.code.equals(code) && other.scopeType == scopeType
// && other.astNodeType == astNodeType
// && other.astParentNodeType == astParentNodeType
// && other.type.equals(type);
// }
//
// @Override
// public int hashCode() {
// return Objects.hashCode(code, scopeType, type, astNodeType,
// astParentNodeType);
// }
//
// @Override
// public String toString() {
// return scopeType + " " + code;
// }
// }
| import static com.google.common.base.Preconditions.checkArgument;
import java.io.File;
import java.io.IOException;
import java.util.List;
import org.eclipse.jdt.core.dom.ASTNode;
import codemining.languagetools.IScopeExtractor;
import codemining.languagetools.ParseType;
import codemining.languagetools.Scope;
import com.google.common.collect.Lists;
import com.google.common.collect.Multimap;
import com.google.common.collect.TreeMultimap; | /**
*
*/
package codemining.java.codeutils.scopes;
/**
* Aggregate all extractors.
*
* @author Miltos Allamanis <[email protected]>
*
*/
public class AllScopeExtractor {
public static final class AllScopeSnippetExtractor implements | // Path: src/main/java/codemining/languagetools/IScopeExtractor.java
// public interface IScopeExtractor {
// Multimap<Scope, String> getFromFile(final File file) throws IOException;
//
// Multimap<Scope, String> getFromNode(final ASTNode node);
//
// Multimap<Scope, String> getFromString(final String code,
// final ParseType parseType);
// }
//
// Path: src/main/java/codemining/languagetools/ParseType.java
// public enum ParseType {
// COMPILATION_UNIT, CLASS_BODY, METHOD, STATEMENTS, EXPRESSION
// }
//
// Path: src/main/java/codemining/languagetools/Scope.java
// public class Scope implements Comparable<Scope> {
//
// public enum ScopeType {
// SCOPE_CLASS, SCOPE_LOCAL, SCOPE_METHOD
// }
//
// public final String code;
//
// public final ScopeType scopeType;
//
// public final String type;
//
// public final int astNodeType;
// public final int astParentNodeType;
//
// public Scope(final String code, final ScopeType scopeType,
// final String type, final int astNodeType,
// final int astParentNodeType) {
// this.code = code;
// this.scopeType = scopeType;
// this.type = type;
// this.astNodeType = astNodeType;
// this.astParentNodeType = astParentNodeType;
// }
//
// @Override
// public int compareTo(final Scope other) {
// return ComparisonChain.start().compare(code, other.code)
// .compare(scopeType, other.scopeType).compare(type, other.type)
// .compare(astNodeType, other.astNodeType)
// .compare(astParentNodeType, other.astParentNodeType).result();
// }
//
// @Override
// public boolean equals(final Object obj) {
// if (!(obj instanceof Scope)) {
// return false;
// }
// final Scope other = (Scope) obj;
// return other.code.equals(code) && other.scopeType == scopeType
// && other.astNodeType == astNodeType
// && other.astParentNodeType == astParentNodeType
// && other.type.equals(type);
// }
//
// @Override
// public int hashCode() {
// return Objects.hashCode(code, scopeType, type, astNodeType,
// astParentNodeType);
// }
//
// @Override
// public String toString() {
// return scopeType + " " + code;
// }
// }
// Path: src/main/java/codemining/java/codeutils/scopes/AllScopeExtractor.java
import static com.google.common.base.Preconditions.checkArgument;
import java.io.File;
import java.io.IOException;
import java.util.List;
import org.eclipse.jdt.core.dom.ASTNode;
import codemining.languagetools.IScopeExtractor;
import codemining.languagetools.ParseType;
import codemining.languagetools.Scope;
import com.google.common.collect.Lists;
import com.google.common.collect.Multimap;
import com.google.common.collect.TreeMultimap;
/**
*
*/
package codemining.java.codeutils.scopes;
/**
* Aggregate all extractors.
*
* @author Miltos Allamanis <[email protected]>
*
*/
public class AllScopeExtractor {
public static final class AllScopeSnippetExtractor implements | IScopeExtractor { |
mast-group/codemining-core | src/main/java/codemining/java/codeutils/scopes/AllScopeExtractor.java | // Path: src/main/java/codemining/languagetools/IScopeExtractor.java
// public interface IScopeExtractor {
// Multimap<Scope, String> getFromFile(final File file) throws IOException;
//
// Multimap<Scope, String> getFromNode(final ASTNode node);
//
// Multimap<Scope, String> getFromString(final String code,
// final ParseType parseType);
// }
//
// Path: src/main/java/codemining/languagetools/ParseType.java
// public enum ParseType {
// COMPILATION_UNIT, CLASS_BODY, METHOD, STATEMENTS, EXPRESSION
// }
//
// Path: src/main/java/codemining/languagetools/Scope.java
// public class Scope implements Comparable<Scope> {
//
// public enum ScopeType {
// SCOPE_CLASS, SCOPE_LOCAL, SCOPE_METHOD
// }
//
// public final String code;
//
// public final ScopeType scopeType;
//
// public final String type;
//
// public final int astNodeType;
// public final int astParentNodeType;
//
// public Scope(final String code, final ScopeType scopeType,
// final String type, final int astNodeType,
// final int astParentNodeType) {
// this.code = code;
// this.scopeType = scopeType;
// this.type = type;
// this.astNodeType = astNodeType;
// this.astParentNodeType = astParentNodeType;
// }
//
// @Override
// public int compareTo(final Scope other) {
// return ComparisonChain.start().compare(code, other.code)
// .compare(scopeType, other.scopeType).compare(type, other.type)
// .compare(astNodeType, other.astNodeType)
// .compare(astParentNodeType, other.astParentNodeType).result();
// }
//
// @Override
// public boolean equals(final Object obj) {
// if (!(obj instanceof Scope)) {
// return false;
// }
// final Scope other = (Scope) obj;
// return other.code.equals(code) && other.scopeType == scopeType
// && other.astNodeType == astNodeType
// && other.astParentNodeType == astParentNodeType
// && other.type.equals(type);
// }
//
// @Override
// public int hashCode() {
// return Objects.hashCode(code, scopeType, type, astNodeType,
// astParentNodeType);
// }
//
// @Override
// public String toString() {
// return scopeType + " " + code;
// }
// }
| import static com.google.common.base.Preconditions.checkArgument;
import java.io.File;
import java.io.IOException;
import java.util.List;
import org.eclipse.jdt.core.dom.ASTNode;
import codemining.languagetools.IScopeExtractor;
import codemining.languagetools.ParseType;
import codemining.languagetools.Scope;
import com.google.common.collect.Lists;
import com.google.common.collect.Multimap;
import com.google.common.collect.TreeMultimap; | true));
allExtractors
.add(new TypenameScopeExtractor.TypenameSnippetExtractor(
true));
}
public AllScopeSnippetExtractor(final boolean variables,
final boolean methods, final boolean types) {
allExtractors = Lists.newArrayList();
checkArgument(variables | methods | types,
"At least one option must be set");
if (variables) {
allExtractors
.add(new VariableScopeExtractor.VariableScopeSnippetExtractor());
}
if (methods) {
allExtractors
.add(new MethodScopeExtractor.MethodScopeSnippetExtractor(
true));
}
if (types) {
allExtractors
.add(new TypenameScopeExtractor.TypenameSnippetExtractor(
true));
}
}
private final List<IScopeExtractor> allExtractors;
@Override | // Path: src/main/java/codemining/languagetools/IScopeExtractor.java
// public interface IScopeExtractor {
// Multimap<Scope, String> getFromFile(final File file) throws IOException;
//
// Multimap<Scope, String> getFromNode(final ASTNode node);
//
// Multimap<Scope, String> getFromString(final String code,
// final ParseType parseType);
// }
//
// Path: src/main/java/codemining/languagetools/ParseType.java
// public enum ParseType {
// COMPILATION_UNIT, CLASS_BODY, METHOD, STATEMENTS, EXPRESSION
// }
//
// Path: src/main/java/codemining/languagetools/Scope.java
// public class Scope implements Comparable<Scope> {
//
// public enum ScopeType {
// SCOPE_CLASS, SCOPE_LOCAL, SCOPE_METHOD
// }
//
// public final String code;
//
// public final ScopeType scopeType;
//
// public final String type;
//
// public final int astNodeType;
// public final int astParentNodeType;
//
// public Scope(final String code, final ScopeType scopeType,
// final String type, final int astNodeType,
// final int astParentNodeType) {
// this.code = code;
// this.scopeType = scopeType;
// this.type = type;
// this.astNodeType = astNodeType;
// this.astParentNodeType = astParentNodeType;
// }
//
// @Override
// public int compareTo(final Scope other) {
// return ComparisonChain.start().compare(code, other.code)
// .compare(scopeType, other.scopeType).compare(type, other.type)
// .compare(astNodeType, other.astNodeType)
// .compare(astParentNodeType, other.astParentNodeType).result();
// }
//
// @Override
// public boolean equals(final Object obj) {
// if (!(obj instanceof Scope)) {
// return false;
// }
// final Scope other = (Scope) obj;
// return other.code.equals(code) && other.scopeType == scopeType
// && other.astNodeType == astNodeType
// && other.astParentNodeType == astParentNodeType
// && other.type.equals(type);
// }
//
// @Override
// public int hashCode() {
// return Objects.hashCode(code, scopeType, type, astNodeType,
// astParentNodeType);
// }
//
// @Override
// public String toString() {
// return scopeType + " " + code;
// }
// }
// Path: src/main/java/codemining/java/codeutils/scopes/AllScopeExtractor.java
import static com.google.common.base.Preconditions.checkArgument;
import java.io.File;
import java.io.IOException;
import java.util.List;
import org.eclipse.jdt.core.dom.ASTNode;
import codemining.languagetools.IScopeExtractor;
import codemining.languagetools.ParseType;
import codemining.languagetools.Scope;
import com.google.common.collect.Lists;
import com.google.common.collect.Multimap;
import com.google.common.collect.TreeMultimap;
true));
allExtractors
.add(new TypenameScopeExtractor.TypenameSnippetExtractor(
true));
}
public AllScopeSnippetExtractor(final boolean variables,
final boolean methods, final boolean types) {
allExtractors = Lists.newArrayList();
checkArgument(variables | methods | types,
"At least one option must be set");
if (variables) {
allExtractors
.add(new VariableScopeExtractor.VariableScopeSnippetExtractor());
}
if (methods) {
allExtractors
.add(new MethodScopeExtractor.MethodScopeSnippetExtractor(
true));
}
if (types) {
allExtractors
.add(new TypenameScopeExtractor.TypenameSnippetExtractor(
true));
}
}
private final List<IScopeExtractor> allExtractors;
@Override | public Multimap<Scope, String> getFromFile(final File file) |
mast-group/codemining-core | src/main/java/codemining/java/codeutils/scopes/AllScopeExtractor.java | // Path: src/main/java/codemining/languagetools/IScopeExtractor.java
// public interface IScopeExtractor {
// Multimap<Scope, String> getFromFile(final File file) throws IOException;
//
// Multimap<Scope, String> getFromNode(final ASTNode node);
//
// Multimap<Scope, String> getFromString(final String code,
// final ParseType parseType);
// }
//
// Path: src/main/java/codemining/languagetools/ParseType.java
// public enum ParseType {
// COMPILATION_UNIT, CLASS_BODY, METHOD, STATEMENTS, EXPRESSION
// }
//
// Path: src/main/java/codemining/languagetools/Scope.java
// public class Scope implements Comparable<Scope> {
//
// public enum ScopeType {
// SCOPE_CLASS, SCOPE_LOCAL, SCOPE_METHOD
// }
//
// public final String code;
//
// public final ScopeType scopeType;
//
// public final String type;
//
// public final int astNodeType;
// public final int astParentNodeType;
//
// public Scope(final String code, final ScopeType scopeType,
// final String type, final int astNodeType,
// final int astParentNodeType) {
// this.code = code;
// this.scopeType = scopeType;
// this.type = type;
// this.astNodeType = astNodeType;
// this.astParentNodeType = astParentNodeType;
// }
//
// @Override
// public int compareTo(final Scope other) {
// return ComparisonChain.start().compare(code, other.code)
// .compare(scopeType, other.scopeType).compare(type, other.type)
// .compare(astNodeType, other.astNodeType)
// .compare(astParentNodeType, other.astParentNodeType).result();
// }
//
// @Override
// public boolean equals(final Object obj) {
// if (!(obj instanceof Scope)) {
// return false;
// }
// final Scope other = (Scope) obj;
// return other.code.equals(code) && other.scopeType == scopeType
// && other.astNodeType == astNodeType
// && other.astParentNodeType == astParentNodeType
// && other.type.equals(type);
// }
//
// @Override
// public int hashCode() {
// return Objects.hashCode(code, scopeType, type, astNodeType,
// astParentNodeType);
// }
//
// @Override
// public String toString() {
// return scopeType + " " + code;
// }
// }
| import static com.google.common.base.Preconditions.checkArgument;
import java.io.File;
import java.io.IOException;
import java.util.List;
import org.eclipse.jdt.core.dom.ASTNode;
import codemining.languagetools.IScopeExtractor;
import codemining.languagetools.ParseType;
import codemining.languagetools.Scope;
import com.google.common.collect.Lists;
import com.google.common.collect.Multimap;
import com.google.common.collect.TreeMultimap; | if (types) {
allExtractors
.add(new TypenameScopeExtractor.TypenameSnippetExtractor(
true));
}
}
private final List<IScopeExtractor> allExtractors;
@Override
public Multimap<Scope, String> getFromFile(final File file)
throws IOException {
final Multimap<Scope, String> scopes = TreeMultimap.create();
for (final IScopeExtractor extractor : allExtractors) {
scopes.putAll(extractor.getFromFile(file));
}
return scopes;
}
@Override
public Multimap<Scope, String> getFromNode(ASTNode node) {
final Multimap<Scope, String> scopes = TreeMultimap.create();
for (final IScopeExtractor extractor : allExtractors) {
scopes.putAll(extractor.getFromNode(node));
}
return scopes;
}
@Override
public Multimap<Scope, String> getFromString(final String file, | // Path: src/main/java/codemining/languagetools/IScopeExtractor.java
// public interface IScopeExtractor {
// Multimap<Scope, String> getFromFile(final File file) throws IOException;
//
// Multimap<Scope, String> getFromNode(final ASTNode node);
//
// Multimap<Scope, String> getFromString(final String code,
// final ParseType parseType);
// }
//
// Path: src/main/java/codemining/languagetools/ParseType.java
// public enum ParseType {
// COMPILATION_UNIT, CLASS_BODY, METHOD, STATEMENTS, EXPRESSION
// }
//
// Path: src/main/java/codemining/languagetools/Scope.java
// public class Scope implements Comparable<Scope> {
//
// public enum ScopeType {
// SCOPE_CLASS, SCOPE_LOCAL, SCOPE_METHOD
// }
//
// public final String code;
//
// public final ScopeType scopeType;
//
// public final String type;
//
// public final int astNodeType;
// public final int astParentNodeType;
//
// public Scope(final String code, final ScopeType scopeType,
// final String type, final int astNodeType,
// final int astParentNodeType) {
// this.code = code;
// this.scopeType = scopeType;
// this.type = type;
// this.astNodeType = astNodeType;
// this.astParentNodeType = astParentNodeType;
// }
//
// @Override
// public int compareTo(final Scope other) {
// return ComparisonChain.start().compare(code, other.code)
// .compare(scopeType, other.scopeType).compare(type, other.type)
// .compare(astNodeType, other.astNodeType)
// .compare(astParentNodeType, other.astParentNodeType).result();
// }
//
// @Override
// public boolean equals(final Object obj) {
// if (!(obj instanceof Scope)) {
// return false;
// }
// final Scope other = (Scope) obj;
// return other.code.equals(code) && other.scopeType == scopeType
// && other.astNodeType == astNodeType
// && other.astParentNodeType == astParentNodeType
// && other.type.equals(type);
// }
//
// @Override
// public int hashCode() {
// return Objects.hashCode(code, scopeType, type, astNodeType,
// astParentNodeType);
// }
//
// @Override
// public String toString() {
// return scopeType + " " + code;
// }
// }
// Path: src/main/java/codemining/java/codeutils/scopes/AllScopeExtractor.java
import static com.google.common.base.Preconditions.checkArgument;
import java.io.File;
import java.io.IOException;
import java.util.List;
import org.eclipse.jdt.core.dom.ASTNode;
import codemining.languagetools.IScopeExtractor;
import codemining.languagetools.ParseType;
import codemining.languagetools.Scope;
import com.google.common.collect.Lists;
import com.google.common.collect.Multimap;
import com.google.common.collect.TreeMultimap;
if (types) {
allExtractors
.add(new TypenameScopeExtractor.TypenameSnippetExtractor(
true));
}
}
private final List<IScopeExtractor> allExtractors;
@Override
public Multimap<Scope, String> getFromFile(final File file)
throws IOException {
final Multimap<Scope, String> scopes = TreeMultimap.create();
for (final IScopeExtractor extractor : allExtractors) {
scopes.putAll(extractor.getFromFile(file));
}
return scopes;
}
@Override
public Multimap<Scope, String> getFromNode(ASTNode node) {
final Multimap<Scope, String> scopes = TreeMultimap.create();
for (final IScopeExtractor extractor : allExtractors) {
scopes.putAll(extractor.getFromNode(node));
}
return scopes;
}
@Override
public Multimap<Scope, String> getFromString(final String file, | final ParseType parseType) { |
mast-group/codemining-core | src/test/java/codemining/js/codeutils/JavascriptASTExtractorTest.java | // Path: src/main/java/codemining/languagetools/ParseType.java
// public enum ParseType {
// COMPILATION_UNIT, CLASS_BODY, METHOD, STATEMENTS, EXPRESSION
// }
| import static org.junit.Assert.assertTrue;
import java.io.File;
import java.io.IOException;
import java.util.List;
import org.apache.commons.io.FileUtils;
import org.eclipse.wst.jsdt.core.dom.ASTNode;
import org.junit.Before;
import org.junit.Test;
import codemining.languagetools.ParseType; | /**
*
*/
package codemining.js.codeutils;
/**
* @author Miltos Allamanis <[email protected]>
*
*/
// FIXME Javascript AST parser is quite buggy: For SampleJavascript the === is
// printed as + and for SampleJavascript2 it prints a random semicolon at line 7
// Is this just a buggy toString method issue? Tests commented out until fixed.
public class JavascriptASTExtractorTest {
String classContent;
String methodContent;
@Before
public void setUp() throws IOException {
classContent = FileUtils.readFileToString(new File(
JavascriptASTExtractorTest.class.getClassLoader()
.getResource("SampleJavascript2.txt").getFile()));
methodContent = FileUtils.readFileToString(new File(
JavascriptASTExtractorTest.class.getClassLoader()
.getResource("SampleJavascript.txt").getFile()));
}
/**
* Test method for
* {@link codemining.java.codeutils.JavaASTExtractor#getBestEffortAst(java.lang.String)}
* .
*
* @throws IOException
*/
@Test
public void testGetASTString() {
final JavascriptASTExtractor ex = new JavascriptASTExtractor(false);
assertTrue(classContent.length() > 0);
final ASTNode classCU = ex.getASTNode(classContent, | // Path: src/main/java/codemining/languagetools/ParseType.java
// public enum ParseType {
// COMPILATION_UNIT, CLASS_BODY, METHOD, STATEMENTS, EXPRESSION
// }
// Path: src/test/java/codemining/js/codeutils/JavascriptASTExtractorTest.java
import static org.junit.Assert.assertTrue;
import java.io.File;
import java.io.IOException;
import java.util.List;
import org.apache.commons.io.FileUtils;
import org.eclipse.wst.jsdt.core.dom.ASTNode;
import org.junit.Before;
import org.junit.Test;
import codemining.languagetools.ParseType;
/**
*
*/
package codemining.js.codeutils;
/**
* @author Miltos Allamanis <[email protected]>
*
*/
// FIXME Javascript AST parser is quite buggy: For SampleJavascript the === is
// printed as + and for SampleJavascript2 it prints a random semicolon at line 7
// Is this just a buggy toString method issue? Tests commented out until fixed.
public class JavascriptASTExtractorTest {
String classContent;
String methodContent;
@Before
public void setUp() throws IOException {
classContent = FileUtils.readFileToString(new File(
JavascriptASTExtractorTest.class.getClassLoader()
.getResource("SampleJavascript2.txt").getFile()));
methodContent = FileUtils.readFileToString(new File(
JavascriptASTExtractorTest.class.getClassLoader()
.getResource("SampleJavascript.txt").getFile()));
}
/**
* Test method for
* {@link codemining.java.codeutils.JavaASTExtractor#getBestEffortAst(java.lang.String)}
* .
*
* @throws IOException
*/
@Test
public void testGetASTString() {
final JavascriptASTExtractor ex = new JavascriptASTExtractor(false);
assertTrue(classContent.length() > 0);
final ASTNode classCU = ex.getASTNode(classContent, | ParseType.COMPILATION_UNIT); |
mast-group/codemining-core | src/test/java/codemining/java/codeutils/binding/JavaExactVariableBindingsExtractorTest.java | // Path: src/test/java/codemining/java/codeutils/JavaAstExtractorTest.java
// public class JavaAstExtractorTest {
//
// String classContent;
// String methodContent;
//
// @Before
// public void setUp() throws IOException {
// classContent = FileUtils.readFileToString(new File(
// JavaAstExtractorTest.class.getClassLoader()
// .getResource("SampleClass.txt").getFile()));
//
// methodContent = FileUtils.readFileToString(new File(
// JavaAstExtractorTest.class.getClassLoader()
// .getResource("SampleMethod.txt").getFile()));
// }
//
// /**
// * Test method for
// * {@link codemining.java.codeutils.JavaASTExtractor#getBestEffortAst(java.lang.String)}
// * .
// *
// * @throws IOException
// */
// @Test
// public void testGetASTString() {
// final JavaASTExtractor ex = new JavaASTExtractor(false);
// assertTrue(classContent.length() > 0);
// final ASTNode classCU = ex.getASTNode(classContent,
// ParseType.COMPILATION_UNIT);
// assertTrue(snippetMatchesAstTokens(classContent, classCU));
//
// assertTrue(methodContent.length() > 0);
// final ASTNode methodCU = ex.getASTNode(methodContent,
// ParseType.METHOD);
// assertTrue(snippetMatchesAstTokens(methodContent, methodCU));
// }
//
// private boolean snippetMatchesAstTokens(final String snippetCode,
// final ASTNode node) {
// final JavaTokenizer tokenizer = new JavaTokenizer();
// final List<String> snippetTokens = tokenizer
// .tokenListFromCode(snippetCode.toCharArray());
// final List<String> astTokens = tokenizer.tokenListFromCode(node
// .toString().toCharArray());
// return astTokens.equals(snippetTokens);
// }
// }
//
// Path: src/main/java/codemining/languagetools/bindings/TokenNameBinding.java
// public class TokenNameBinding implements Serializable {
// private static final long serialVersionUID = 2020613810485746430L;
//
// /**
// * The tokens of source code.
// */
// public final List<String> sourceCodeTokens;
//
// /**
// * The positions in sourceCodeTokens that contain the given name.
// */
// public final Set<Integer> nameIndexes;
//
// /**
// * Features of the binding
// */
// public final Set<String> features;
//
// public TokenNameBinding(final Set<Integer> nameIndexes,
// final List<String> sourceCodeTokens, final Set<String> features) {
// checkArgument(nameIndexes.size() > 0);
// checkArgument(sourceCodeTokens.size() > 0);
// this.nameIndexes = Collections.unmodifiableSet(nameIndexes);
// this.sourceCodeTokens = Collections.unmodifiableList(sourceCodeTokens);
// this.features = features;
// }
//
// @Override
// public boolean equals(final Object obj) {
// if (this == obj) {
// return true;
// }
// if (obj == null) {
// return false;
// }
// if (getClass() != obj.getClass()) {
// return false;
// }
// final TokenNameBinding other = (TokenNameBinding) obj;
// return Objects.equal(nameIndexes, other.nameIndexes)
// && Objects.equal(features, other.features)
// && Objects.equal(sourceCodeTokens, other.sourceCodeTokens);
// }
//
// public String getName() {
// return sourceCodeTokens.get(nameIndexes.iterator().next());
// }
//
// @Override
// public int hashCode() {
// return Objects.hashCode(sourceCodeTokens, nameIndexes, features);
// }
//
// /**
// * Rename this name to the given binding. The source code tokens included in
// * this struct, now represent the new structure.
// *
// * @param name
// * @return
// */
// public TokenNameBinding renameTo(final String name) {
// final List<String> renamedCode = Lists.newArrayList(sourceCodeTokens);
// for (final int position : nameIndexes) {
// renamedCode.set(position, name);
// }
// return new TokenNameBinding(nameIndexes, renamedCode, features);
// }
//
// @Override
// public String toString() {
// return getName() + nameIndexes + " " + features;
// }
// }
| import static org.junit.Assert.assertEquals;
import java.io.File;
import java.io.IOException;
import java.util.List;
import org.junit.Before;
import org.junit.Test;
import codemining.java.codeutils.JavaAstExtractorTest;
import codemining.languagetools.bindings.TokenNameBinding; | package codemining.java.codeutils.binding;
public class JavaExactVariableBindingsExtractorTest {
File classContent;
File classContent2;
@Before
public void setUp() throws IOException { | // Path: src/test/java/codemining/java/codeutils/JavaAstExtractorTest.java
// public class JavaAstExtractorTest {
//
// String classContent;
// String methodContent;
//
// @Before
// public void setUp() throws IOException {
// classContent = FileUtils.readFileToString(new File(
// JavaAstExtractorTest.class.getClassLoader()
// .getResource("SampleClass.txt").getFile()));
//
// methodContent = FileUtils.readFileToString(new File(
// JavaAstExtractorTest.class.getClassLoader()
// .getResource("SampleMethod.txt").getFile()));
// }
//
// /**
// * Test method for
// * {@link codemining.java.codeutils.JavaASTExtractor#getBestEffortAst(java.lang.String)}
// * .
// *
// * @throws IOException
// */
// @Test
// public void testGetASTString() {
// final JavaASTExtractor ex = new JavaASTExtractor(false);
// assertTrue(classContent.length() > 0);
// final ASTNode classCU = ex.getASTNode(classContent,
// ParseType.COMPILATION_UNIT);
// assertTrue(snippetMatchesAstTokens(classContent, classCU));
//
// assertTrue(methodContent.length() > 0);
// final ASTNode methodCU = ex.getASTNode(methodContent,
// ParseType.METHOD);
// assertTrue(snippetMatchesAstTokens(methodContent, methodCU));
// }
//
// private boolean snippetMatchesAstTokens(final String snippetCode,
// final ASTNode node) {
// final JavaTokenizer tokenizer = new JavaTokenizer();
// final List<String> snippetTokens = tokenizer
// .tokenListFromCode(snippetCode.toCharArray());
// final List<String> astTokens = tokenizer.tokenListFromCode(node
// .toString().toCharArray());
// return astTokens.equals(snippetTokens);
// }
// }
//
// Path: src/main/java/codemining/languagetools/bindings/TokenNameBinding.java
// public class TokenNameBinding implements Serializable {
// private static final long serialVersionUID = 2020613810485746430L;
//
// /**
// * The tokens of source code.
// */
// public final List<String> sourceCodeTokens;
//
// /**
// * The positions in sourceCodeTokens that contain the given name.
// */
// public final Set<Integer> nameIndexes;
//
// /**
// * Features of the binding
// */
// public final Set<String> features;
//
// public TokenNameBinding(final Set<Integer> nameIndexes,
// final List<String> sourceCodeTokens, final Set<String> features) {
// checkArgument(nameIndexes.size() > 0);
// checkArgument(sourceCodeTokens.size() > 0);
// this.nameIndexes = Collections.unmodifiableSet(nameIndexes);
// this.sourceCodeTokens = Collections.unmodifiableList(sourceCodeTokens);
// this.features = features;
// }
//
// @Override
// public boolean equals(final Object obj) {
// if (this == obj) {
// return true;
// }
// if (obj == null) {
// return false;
// }
// if (getClass() != obj.getClass()) {
// return false;
// }
// final TokenNameBinding other = (TokenNameBinding) obj;
// return Objects.equal(nameIndexes, other.nameIndexes)
// && Objects.equal(features, other.features)
// && Objects.equal(sourceCodeTokens, other.sourceCodeTokens);
// }
//
// public String getName() {
// return sourceCodeTokens.get(nameIndexes.iterator().next());
// }
//
// @Override
// public int hashCode() {
// return Objects.hashCode(sourceCodeTokens, nameIndexes, features);
// }
//
// /**
// * Rename this name to the given binding. The source code tokens included in
// * this struct, now represent the new structure.
// *
// * @param name
// * @return
// */
// public TokenNameBinding renameTo(final String name) {
// final List<String> renamedCode = Lists.newArrayList(sourceCodeTokens);
// for (final int position : nameIndexes) {
// renamedCode.set(position, name);
// }
// return new TokenNameBinding(nameIndexes, renamedCode, features);
// }
//
// @Override
// public String toString() {
// return getName() + nameIndexes + " " + features;
// }
// }
// Path: src/test/java/codemining/java/codeutils/binding/JavaExactVariableBindingsExtractorTest.java
import static org.junit.Assert.assertEquals;
import java.io.File;
import java.io.IOException;
import java.util.List;
import org.junit.Before;
import org.junit.Test;
import codemining.java.codeutils.JavaAstExtractorTest;
import codemining.languagetools.bindings.TokenNameBinding;
package codemining.java.codeutils.binding;
public class JavaExactVariableBindingsExtractorTest {
File classContent;
File classContent2;
@Before
public void setUp() throws IOException { | classContent = new File(JavaAstExtractorTest.class.getClassLoader() |
mast-group/codemining-core | src/test/java/codemining/java/codeutils/binding/JavaExactVariableBindingsExtractorTest.java | // Path: src/test/java/codemining/java/codeutils/JavaAstExtractorTest.java
// public class JavaAstExtractorTest {
//
// String classContent;
// String methodContent;
//
// @Before
// public void setUp() throws IOException {
// classContent = FileUtils.readFileToString(new File(
// JavaAstExtractorTest.class.getClassLoader()
// .getResource("SampleClass.txt").getFile()));
//
// methodContent = FileUtils.readFileToString(new File(
// JavaAstExtractorTest.class.getClassLoader()
// .getResource("SampleMethod.txt").getFile()));
// }
//
// /**
// * Test method for
// * {@link codemining.java.codeutils.JavaASTExtractor#getBestEffortAst(java.lang.String)}
// * .
// *
// * @throws IOException
// */
// @Test
// public void testGetASTString() {
// final JavaASTExtractor ex = new JavaASTExtractor(false);
// assertTrue(classContent.length() > 0);
// final ASTNode classCU = ex.getASTNode(classContent,
// ParseType.COMPILATION_UNIT);
// assertTrue(snippetMatchesAstTokens(classContent, classCU));
//
// assertTrue(methodContent.length() > 0);
// final ASTNode methodCU = ex.getASTNode(methodContent,
// ParseType.METHOD);
// assertTrue(snippetMatchesAstTokens(methodContent, methodCU));
// }
//
// private boolean snippetMatchesAstTokens(final String snippetCode,
// final ASTNode node) {
// final JavaTokenizer tokenizer = new JavaTokenizer();
// final List<String> snippetTokens = tokenizer
// .tokenListFromCode(snippetCode.toCharArray());
// final List<String> astTokens = tokenizer.tokenListFromCode(node
// .toString().toCharArray());
// return astTokens.equals(snippetTokens);
// }
// }
//
// Path: src/main/java/codemining/languagetools/bindings/TokenNameBinding.java
// public class TokenNameBinding implements Serializable {
// private static final long serialVersionUID = 2020613810485746430L;
//
// /**
// * The tokens of source code.
// */
// public final List<String> sourceCodeTokens;
//
// /**
// * The positions in sourceCodeTokens that contain the given name.
// */
// public final Set<Integer> nameIndexes;
//
// /**
// * Features of the binding
// */
// public final Set<String> features;
//
// public TokenNameBinding(final Set<Integer> nameIndexes,
// final List<String> sourceCodeTokens, final Set<String> features) {
// checkArgument(nameIndexes.size() > 0);
// checkArgument(sourceCodeTokens.size() > 0);
// this.nameIndexes = Collections.unmodifiableSet(nameIndexes);
// this.sourceCodeTokens = Collections.unmodifiableList(sourceCodeTokens);
// this.features = features;
// }
//
// @Override
// public boolean equals(final Object obj) {
// if (this == obj) {
// return true;
// }
// if (obj == null) {
// return false;
// }
// if (getClass() != obj.getClass()) {
// return false;
// }
// final TokenNameBinding other = (TokenNameBinding) obj;
// return Objects.equal(nameIndexes, other.nameIndexes)
// && Objects.equal(features, other.features)
// && Objects.equal(sourceCodeTokens, other.sourceCodeTokens);
// }
//
// public String getName() {
// return sourceCodeTokens.get(nameIndexes.iterator().next());
// }
//
// @Override
// public int hashCode() {
// return Objects.hashCode(sourceCodeTokens, nameIndexes, features);
// }
//
// /**
// * Rename this name to the given binding. The source code tokens included in
// * this struct, now represent the new structure.
// *
// * @param name
// * @return
// */
// public TokenNameBinding renameTo(final String name) {
// final List<String> renamedCode = Lists.newArrayList(sourceCodeTokens);
// for (final int position : nameIndexes) {
// renamedCode.set(position, name);
// }
// return new TokenNameBinding(nameIndexes, renamedCode, features);
// }
//
// @Override
// public String toString() {
// return getName() + nameIndexes + " " + features;
// }
// }
| import static org.junit.Assert.assertEquals;
import java.io.File;
import java.io.IOException;
import java.util.List;
import org.junit.Before;
import org.junit.Test;
import codemining.java.codeutils.JavaAstExtractorTest;
import codemining.languagetools.bindings.TokenNameBinding; | package codemining.java.codeutils.binding;
public class JavaExactVariableBindingsExtractorTest {
File classContent;
File classContent2;
@Before
public void setUp() throws IOException {
classContent = new File(JavaAstExtractorTest.class.getClassLoader()
.getResource("SampleClass.txt").getFile());
classContent2 = new File(JavaAstExtractorTest.class.getClassLoader()
.getResource("SampleClass2.txt").getFile());
}
@Test
public void testClassBindings() throws IOException {
final JavaExactVariableBindingsExtractor jbe = new JavaExactVariableBindingsExtractor(); | // Path: src/test/java/codemining/java/codeutils/JavaAstExtractorTest.java
// public class JavaAstExtractorTest {
//
// String classContent;
// String methodContent;
//
// @Before
// public void setUp() throws IOException {
// classContent = FileUtils.readFileToString(new File(
// JavaAstExtractorTest.class.getClassLoader()
// .getResource("SampleClass.txt").getFile()));
//
// methodContent = FileUtils.readFileToString(new File(
// JavaAstExtractorTest.class.getClassLoader()
// .getResource("SampleMethod.txt").getFile()));
// }
//
// /**
// * Test method for
// * {@link codemining.java.codeutils.JavaASTExtractor#getBestEffortAst(java.lang.String)}
// * .
// *
// * @throws IOException
// */
// @Test
// public void testGetASTString() {
// final JavaASTExtractor ex = new JavaASTExtractor(false);
// assertTrue(classContent.length() > 0);
// final ASTNode classCU = ex.getASTNode(classContent,
// ParseType.COMPILATION_UNIT);
// assertTrue(snippetMatchesAstTokens(classContent, classCU));
//
// assertTrue(methodContent.length() > 0);
// final ASTNode methodCU = ex.getASTNode(methodContent,
// ParseType.METHOD);
// assertTrue(snippetMatchesAstTokens(methodContent, methodCU));
// }
//
// private boolean snippetMatchesAstTokens(final String snippetCode,
// final ASTNode node) {
// final JavaTokenizer tokenizer = new JavaTokenizer();
// final List<String> snippetTokens = tokenizer
// .tokenListFromCode(snippetCode.toCharArray());
// final List<String> astTokens = tokenizer.tokenListFromCode(node
// .toString().toCharArray());
// return astTokens.equals(snippetTokens);
// }
// }
//
// Path: src/main/java/codemining/languagetools/bindings/TokenNameBinding.java
// public class TokenNameBinding implements Serializable {
// private static final long serialVersionUID = 2020613810485746430L;
//
// /**
// * The tokens of source code.
// */
// public final List<String> sourceCodeTokens;
//
// /**
// * The positions in sourceCodeTokens that contain the given name.
// */
// public final Set<Integer> nameIndexes;
//
// /**
// * Features of the binding
// */
// public final Set<String> features;
//
// public TokenNameBinding(final Set<Integer> nameIndexes,
// final List<String> sourceCodeTokens, final Set<String> features) {
// checkArgument(nameIndexes.size() > 0);
// checkArgument(sourceCodeTokens.size() > 0);
// this.nameIndexes = Collections.unmodifiableSet(nameIndexes);
// this.sourceCodeTokens = Collections.unmodifiableList(sourceCodeTokens);
// this.features = features;
// }
//
// @Override
// public boolean equals(final Object obj) {
// if (this == obj) {
// return true;
// }
// if (obj == null) {
// return false;
// }
// if (getClass() != obj.getClass()) {
// return false;
// }
// final TokenNameBinding other = (TokenNameBinding) obj;
// return Objects.equal(nameIndexes, other.nameIndexes)
// && Objects.equal(features, other.features)
// && Objects.equal(sourceCodeTokens, other.sourceCodeTokens);
// }
//
// public String getName() {
// return sourceCodeTokens.get(nameIndexes.iterator().next());
// }
//
// @Override
// public int hashCode() {
// return Objects.hashCode(sourceCodeTokens, nameIndexes, features);
// }
//
// /**
// * Rename this name to the given binding. The source code tokens included in
// * this struct, now represent the new structure.
// *
// * @param name
// * @return
// */
// public TokenNameBinding renameTo(final String name) {
// final List<String> renamedCode = Lists.newArrayList(sourceCodeTokens);
// for (final int position : nameIndexes) {
// renamedCode.set(position, name);
// }
// return new TokenNameBinding(nameIndexes, renamedCode, features);
// }
//
// @Override
// public String toString() {
// return getName() + nameIndexes + " " + features;
// }
// }
// Path: src/test/java/codemining/java/codeutils/binding/JavaExactVariableBindingsExtractorTest.java
import static org.junit.Assert.assertEquals;
import java.io.File;
import java.io.IOException;
import java.util.List;
import org.junit.Before;
import org.junit.Test;
import codemining.java.codeutils.JavaAstExtractorTest;
import codemining.languagetools.bindings.TokenNameBinding;
package codemining.java.codeutils.binding;
public class JavaExactVariableBindingsExtractorTest {
File classContent;
File classContent2;
@Before
public void setUp() throws IOException {
classContent = new File(JavaAstExtractorTest.class.getClassLoader()
.getResource("SampleClass.txt").getFile());
classContent2 = new File(JavaAstExtractorTest.class.getClassLoader()
.getResource("SampleClass2.txt").getFile());
}
@Test
public void testClassBindings() throws IOException {
final JavaExactVariableBindingsExtractor jbe = new JavaExactVariableBindingsExtractor(); | final List<TokenNameBinding> classVariableBindings = jbe |
mast-group/codemining-core | src/test/java/codemining/java/codeutils/JavaApproximateTypeInferencerTest.java | // Path: src/main/java/codemining/languagetools/ParseType.java
// public enum ParseType {
// COMPILATION_UNIT, CLASS_BODY, METHOD, STATEMENTS, EXPRESSION
// }
| import static org.junit.Assert.assertEquals;
import java.io.File;
import java.io.IOException;
import java.util.Map;
import org.apache.commons.io.FileUtils;
import org.junit.Before;
import org.junit.Test;
import codemining.languagetools.ParseType; | package codemining.java.codeutils;
public class JavaApproximateTypeInferencerTest {
String classContent;
@Before
public void setUp() throws IOException {
classContent = FileUtils.readFileToString(new File(
JavaAstExtractorTest.class.getClassLoader()
.getResource("SampleClass3.txt").getFile()));
}
@Test
public void test() {
JavaASTExtractor ex = new JavaASTExtractor(false);
JavaApproximateTypeInferencer jati = new JavaApproximateTypeInferencer( | // Path: src/main/java/codemining/languagetools/ParseType.java
// public enum ParseType {
// COMPILATION_UNIT, CLASS_BODY, METHOD, STATEMENTS, EXPRESSION
// }
// Path: src/test/java/codemining/java/codeutils/JavaApproximateTypeInferencerTest.java
import static org.junit.Assert.assertEquals;
import java.io.File;
import java.io.IOException;
import java.util.Map;
import org.apache.commons.io.FileUtils;
import org.junit.Before;
import org.junit.Test;
import codemining.languagetools.ParseType;
package codemining.java.codeutils;
public class JavaApproximateTypeInferencerTest {
String classContent;
@Before
public void setUp() throws IOException {
classContent = FileUtils.readFileToString(new File(
JavaAstExtractorTest.class.getClassLoader()
.getResource("SampleClass3.txt").getFile()));
}
@Test
public void test() {
JavaASTExtractor ex = new JavaASTExtractor(false);
JavaApproximateTypeInferencer jati = new JavaApproximateTypeInferencer( | ex.getAST(classContent, ParseType.COMPILATION_UNIT)); |
mast-group/codemining-core | src/test/java/codemining/languagetools/TokenizerUtilsTest.java | // Path: src/test/java/codemining/java/codeutils/JavaAstExtractorTest.java
// public class JavaAstExtractorTest {
//
// String classContent;
// String methodContent;
//
// @Before
// public void setUp() throws IOException {
// classContent = FileUtils.readFileToString(new File(
// JavaAstExtractorTest.class.getClassLoader()
// .getResource("SampleClass.txt").getFile()));
//
// methodContent = FileUtils.readFileToString(new File(
// JavaAstExtractorTest.class.getClassLoader()
// .getResource("SampleMethod.txt").getFile()));
// }
//
// /**
// * Test method for
// * {@link codemining.java.codeutils.JavaASTExtractor#getBestEffortAst(java.lang.String)}
// * .
// *
// * @throws IOException
// */
// @Test
// public void testGetASTString() {
// final JavaASTExtractor ex = new JavaASTExtractor(false);
// assertTrue(classContent.length() > 0);
// final ASTNode classCU = ex.getASTNode(classContent,
// ParseType.COMPILATION_UNIT);
// assertTrue(snippetMatchesAstTokens(classContent, classCU));
//
// assertTrue(methodContent.length() > 0);
// final ASTNode methodCU = ex.getASTNode(methodContent,
// ParseType.METHOD);
// assertTrue(snippetMatchesAstTokens(methodContent, methodCU));
// }
//
// private boolean snippetMatchesAstTokens(final String snippetCode,
// final ASTNode node) {
// final JavaTokenizer tokenizer = new JavaTokenizer();
// final List<String> snippetTokens = tokenizer
// .tokenListFromCode(snippetCode.toCharArray());
// final List<String> astTokens = tokenizer.tokenListFromCode(node
// .toString().toCharArray());
// return astTokens.equals(snippetTokens);
// }
// }
| import static org.junit.Assert.assertEquals;
import java.io.File;
import java.io.IOException;
import org.apache.commons.io.FileUtils;
import org.junit.Before;
import org.junit.Test;
import codemining.java.codeutils.JavaAstExtractorTest; | /**
*
*/
package codemining.languagetools;
/**
* @author Miltos Allamanis <[email protected]>
*
*/
public class TokenizerUtilsTest {
private String classContent;
@Before
public void setUp() throws IOException {
classContent = FileUtils.readFileToString(new File( | // Path: src/test/java/codemining/java/codeutils/JavaAstExtractorTest.java
// public class JavaAstExtractorTest {
//
// String classContent;
// String methodContent;
//
// @Before
// public void setUp() throws IOException {
// classContent = FileUtils.readFileToString(new File(
// JavaAstExtractorTest.class.getClassLoader()
// .getResource("SampleClass.txt").getFile()));
//
// methodContent = FileUtils.readFileToString(new File(
// JavaAstExtractorTest.class.getClassLoader()
// .getResource("SampleMethod.txt").getFile()));
// }
//
// /**
// * Test method for
// * {@link codemining.java.codeutils.JavaASTExtractor#getBestEffortAst(java.lang.String)}
// * .
// *
// * @throws IOException
// */
// @Test
// public void testGetASTString() {
// final JavaASTExtractor ex = new JavaASTExtractor(false);
// assertTrue(classContent.length() > 0);
// final ASTNode classCU = ex.getASTNode(classContent,
// ParseType.COMPILATION_UNIT);
// assertTrue(snippetMatchesAstTokens(classContent, classCU));
//
// assertTrue(methodContent.length() > 0);
// final ASTNode methodCU = ex.getASTNode(methodContent,
// ParseType.METHOD);
// assertTrue(snippetMatchesAstTokens(methodContent, methodCU));
// }
//
// private boolean snippetMatchesAstTokens(final String snippetCode,
// final ASTNode node) {
// final JavaTokenizer tokenizer = new JavaTokenizer();
// final List<String> snippetTokens = tokenizer
// .tokenListFromCode(snippetCode.toCharArray());
// final List<String> astTokens = tokenizer.tokenListFromCode(node
// .toString().toCharArray());
// return astTokens.equals(snippetTokens);
// }
// }
// Path: src/test/java/codemining/languagetools/TokenizerUtilsTest.java
import static org.junit.Assert.assertEquals;
import java.io.File;
import java.io.IOException;
import org.apache.commons.io.FileUtils;
import org.junit.Before;
import org.junit.Test;
import codemining.java.codeutils.JavaAstExtractorTest;
/**
*
*/
package codemining.languagetools;
/**
* @author Miltos Allamanis <[email protected]>
*
*/
public class TokenizerUtilsTest {
private String classContent;
@Before
public void setUp() throws IOException {
classContent = FileUtils.readFileToString(new File( | JavaAstExtractorTest.class.getClassLoader() |
mast-group/codemining-core | src/main/java/codemining/java/codeutils/scopes/ScopesTUI.java | // Path: src/main/java/codemining/java/codeutils/scopes/AllScopeExtractor.java
// public static final class AllScopeSnippetExtractor implements
// IScopeExtractor {
//
// public AllScopeSnippetExtractor() {
// allExtractors = Lists.newArrayList();
// allExtractors
// .add(new VariableScopeExtractor.VariableScopeSnippetExtractor());
// allExtractors
// .add(new MethodScopeExtractor.MethodScopeSnippetExtractor(
// true));
// allExtractors
// .add(new TypenameScopeExtractor.TypenameSnippetExtractor(
// true));
// }
//
// public AllScopeSnippetExtractor(final boolean variables,
// final boolean methods, final boolean types) {
// allExtractors = Lists.newArrayList();
// checkArgument(variables | methods | types,
// "At least one option must be set");
// if (variables) {
// allExtractors
// .add(new VariableScopeExtractor.VariableScopeSnippetExtractor());
// }
// if (methods) {
// allExtractors
// .add(new MethodScopeExtractor.MethodScopeSnippetExtractor(
// true));
// }
// if (types) {
// allExtractors
// .add(new TypenameScopeExtractor.TypenameSnippetExtractor(
// true));
// }
// }
//
// private final List<IScopeExtractor> allExtractors;
//
// @Override
// public Multimap<Scope, String> getFromFile(final File file)
// throws IOException {
// final Multimap<Scope, String> scopes = TreeMultimap.create();
// for (final IScopeExtractor extractor : allExtractors) {
// scopes.putAll(extractor.getFromFile(file));
// }
// return scopes;
// }
//
// @Override
// public Multimap<Scope, String> getFromNode(ASTNode node) {
// final Multimap<Scope, String> scopes = TreeMultimap.create();
// for (final IScopeExtractor extractor : allExtractors) {
// scopes.putAll(extractor.getFromNode(node));
// }
// return scopes;
// }
//
// @Override
// public Multimap<Scope, String> getFromString(final String file,
// final ParseType parseType) {
// final Multimap<Scope, String> scopes = TreeMultimap.create();
// for (final IScopeExtractor extractor : allExtractors) {
// scopes.putAll(extractor.getFromString(file, parseType));
// }
// return scopes;
// }
// }
//
// Path: src/main/java/codemining/languagetools/IScopeExtractor.java
// public interface IScopeExtractor {
// Multimap<Scope, String> getFromFile(final File file) throws IOException;
//
// Multimap<Scope, String> getFromNode(final ASTNode node);
//
// Multimap<Scope, String> getFromString(final String code,
// final ParseType parseType);
// }
| import java.io.File;
import java.io.IOException;
import codemining.java.codeutils.scopes.AllScopeExtractor.AllScopeSnippetExtractor;
import codemining.languagetools.IScopeExtractor; | package codemining.java.codeutils.scopes;
public class ScopesTUI {
/**
* @param name
* @return
* @throws UnsupportedOperationException
*/
public static IScopeExtractor getScopeExtractorByName(final String name)
throws UnsupportedOperationException {
final IScopeExtractor scopeExtractor;
if (name.equals("variable")) {
scopeExtractor = new VariableScopeExtractor.VariableScopeSnippetExtractor();
} else if (name.equals("method")) {
scopeExtractor = new MethodScopeExtractor.MethodScopeSnippetExtractor(
true);
} else if (name.equals("type")) {
scopeExtractor = new TypenameScopeExtractor.TypenameSnippetExtractor(
true);
} else if (name.equals("all")) { | // Path: src/main/java/codemining/java/codeutils/scopes/AllScopeExtractor.java
// public static final class AllScopeSnippetExtractor implements
// IScopeExtractor {
//
// public AllScopeSnippetExtractor() {
// allExtractors = Lists.newArrayList();
// allExtractors
// .add(new VariableScopeExtractor.VariableScopeSnippetExtractor());
// allExtractors
// .add(new MethodScopeExtractor.MethodScopeSnippetExtractor(
// true));
// allExtractors
// .add(new TypenameScopeExtractor.TypenameSnippetExtractor(
// true));
// }
//
// public AllScopeSnippetExtractor(final boolean variables,
// final boolean methods, final boolean types) {
// allExtractors = Lists.newArrayList();
// checkArgument(variables | methods | types,
// "At least one option must be set");
// if (variables) {
// allExtractors
// .add(new VariableScopeExtractor.VariableScopeSnippetExtractor());
// }
// if (methods) {
// allExtractors
// .add(new MethodScopeExtractor.MethodScopeSnippetExtractor(
// true));
// }
// if (types) {
// allExtractors
// .add(new TypenameScopeExtractor.TypenameSnippetExtractor(
// true));
// }
// }
//
// private final List<IScopeExtractor> allExtractors;
//
// @Override
// public Multimap<Scope, String> getFromFile(final File file)
// throws IOException {
// final Multimap<Scope, String> scopes = TreeMultimap.create();
// for (final IScopeExtractor extractor : allExtractors) {
// scopes.putAll(extractor.getFromFile(file));
// }
// return scopes;
// }
//
// @Override
// public Multimap<Scope, String> getFromNode(ASTNode node) {
// final Multimap<Scope, String> scopes = TreeMultimap.create();
// for (final IScopeExtractor extractor : allExtractors) {
// scopes.putAll(extractor.getFromNode(node));
// }
// return scopes;
// }
//
// @Override
// public Multimap<Scope, String> getFromString(final String file,
// final ParseType parseType) {
// final Multimap<Scope, String> scopes = TreeMultimap.create();
// for (final IScopeExtractor extractor : allExtractors) {
// scopes.putAll(extractor.getFromString(file, parseType));
// }
// return scopes;
// }
// }
//
// Path: src/main/java/codemining/languagetools/IScopeExtractor.java
// public interface IScopeExtractor {
// Multimap<Scope, String> getFromFile(final File file) throws IOException;
//
// Multimap<Scope, String> getFromNode(final ASTNode node);
//
// Multimap<Scope, String> getFromString(final String code,
// final ParseType parseType);
// }
// Path: src/main/java/codemining/java/codeutils/scopes/ScopesTUI.java
import java.io.File;
import java.io.IOException;
import codemining.java.codeutils.scopes.AllScopeExtractor.AllScopeSnippetExtractor;
import codemining.languagetools.IScopeExtractor;
package codemining.java.codeutils.scopes;
public class ScopesTUI {
/**
* @param name
* @return
* @throws UnsupportedOperationException
*/
public static IScopeExtractor getScopeExtractorByName(final String name)
throws UnsupportedOperationException {
final IScopeExtractor scopeExtractor;
if (name.equals("variable")) {
scopeExtractor = new VariableScopeExtractor.VariableScopeSnippetExtractor();
} else if (name.equals("method")) {
scopeExtractor = new MethodScopeExtractor.MethodScopeSnippetExtractor(
true);
} else if (name.equals("type")) {
scopeExtractor = new TypenameScopeExtractor.TypenameSnippetExtractor(
true);
} else if (name.equals("all")) { | scopeExtractor = new AllScopeSnippetExtractor(); |
mast-group/codemining-core | src/test/java/codemining/js/codeutils/binding/JavascriptExactVariableBindingsExtractorTest.java | // Path: src/test/java/codemining/java/codeutils/binding/BindingTester.java
// public class BindingTester {
//
// private BindingTester() {
// }
//
// public static void checkAllBindings(final List<TokenNameBinding> bindings) {
// final Set<Integer> indexes = Sets.newHashSet();
// for (final TokenNameBinding binding : bindings) {
// BindingTester.checkBinding(binding);
// assertFalse("Indexes appear only once",
// indexes.removeAll(binding.nameIndexes));
// indexes.addAll(binding.nameIndexes);
// }
// }
//
// public static void checkBinding(final TokenNameBinding binding) {
// final String tokenName = binding.sourceCodeTokens
// .get(binding.nameIndexes.iterator().next());
// for (final int idx : binding.nameIndexes) {
// assertEquals(tokenName, binding.sourceCodeTokens.get(idx));
// }
// };
// }
//
// Path: src/test/java/codemining/js/codeutils/JavascriptASTExtractorTest.java
// public class JavascriptASTExtractorTest {
//
// String classContent;
// String methodContent;
//
// @Before
// public void setUp() throws IOException {
// classContent = FileUtils.readFileToString(new File(
// JavascriptASTExtractorTest.class.getClassLoader()
// .getResource("SampleJavascript2.txt").getFile()));
//
// methodContent = FileUtils.readFileToString(new File(
// JavascriptASTExtractorTest.class.getClassLoader()
// .getResource("SampleJavascript.txt").getFile()));
// }
//
// /**
// * Test method for
// * {@link codemining.java.codeutils.JavaASTExtractor#getBestEffortAst(java.lang.String)}
// * .
// *
// * @throws IOException
// */
// @Test
// public void testGetASTString() {
// final JavascriptASTExtractor ex = new JavascriptASTExtractor(false);
// assertTrue(classContent.length() > 0);
// final ASTNode classCU = ex.getASTNode(classContent,
// ParseType.COMPILATION_UNIT);
// // assertTrue(snippetMatchesAstTokens(classContent, classCU));
//
// assertTrue(methodContent.length() > 0);
// final ASTNode methodCU = ex.getASTNode(methodContent, ParseType.METHOD);
// // assertTrue(snippetMatchesAstTokens(methodContent, methodCU));
// }
//
// private boolean snippetMatchesAstTokens(final String snippetCode,
// final ASTNode node) {
// final JavascriptTokenizer tokenizer = new JavascriptTokenizer();
// final List<String> snippetTokens = tokenizer
// .tokenListFromCode(snippetCode.toCharArray());
// final List<String> astTokens = tokenizer.tokenListFromCode(node
// .toString().toCharArray());
// return astTokens.equals(snippetTokens);
// }
// }
//
// Path: src/main/java/codemining/languagetools/bindings/TokenNameBinding.java
// public class TokenNameBinding implements Serializable {
// private static final long serialVersionUID = 2020613810485746430L;
//
// /**
// * The tokens of source code.
// */
// public final List<String> sourceCodeTokens;
//
// /**
// * The positions in sourceCodeTokens that contain the given name.
// */
// public final Set<Integer> nameIndexes;
//
// /**
// * Features of the binding
// */
// public final Set<String> features;
//
// public TokenNameBinding(final Set<Integer> nameIndexes,
// final List<String> sourceCodeTokens, final Set<String> features) {
// checkArgument(nameIndexes.size() > 0);
// checkArgument(sourceCodeTokens.size() > 0);
// this.nameIndexes = Collections.unmodifiableSet(nameIndexes);
// this.sourceCodeTokens = Collections.unmodifiableList(sourceCodeTokens);
// this.features = features;
// }
//
// @Override
// public boolean equals(final Object obj) {
// if (this == obj) {
// return true;
// }
// if (obj == null) {
// return false;
// }
// if (getClass() != obj.getClass()) {
// return false;
// }
// final TokenNameBinding other = (TokenNameBinding) obj;
// return Objects.equal(nameIndexes, other.nameIndexes)
// && Objects.equal(features, other.features)
// && Objects.equal(sourceCodeTokens, other.sourceCodeTokens);
// }
//
// public String getName() {
// return sourceCodeTokens.get(nameIndexes.iterator().next());
// }
//
// @Override
// public int hashCode() {
// return Objects.hashCode(sourceCodeTokens, nameIndexes, features);
// }
//
// /**
// * Rename this name to the given binding. The source code tokens included in
// * this struct, now represent the new structure.
// *
// * @param name
// * @return
// */
// public TokenNameBinding renameTo(final String name) {
// final List<String> renamedCode = Lists.newArrayList(sourceCodeTokens);
// for (final int position : nameIndexes) {
// renamedCode.set(position, name);
// }
// return new TokenNameBinding(nameIndexes, renamedCode, features);
// }
//
// @Override
// public String toString() {
// return getName() + nameIndexes + " " + features;
// }
// }
| import java.io.File;
import java.io.IOException;
import java.util.List;
import org.junit.Before;
import org.junit.Test;
import codemining.java.codeutils.binding.BindingTester;
import codemining.js.codeutils.JavascriptASTExtractorTest;
import codemining.languagetools.bindings.TokenNameBinding; | package codemining.js.codeutils.binding;
// FIXME Tests commented out until binding resolution is fixed
public class JavascriptExactVariableBindingsExtractorTest {
File classContent;
File classContent2;
@Before
public void setUp() throws IOException { | // Path: src/test/java/codemining/java/codeutils/binding/BindingTester.java
// public class BindingTester {
//
// private BindingTester() {
// }
//
// public static void checkAllBindings(final List<TokenNameBinding> bindings) {
// final Set<Integer> indexes = Sets.newHashSet();
// for (final TokenNameBinding binding : bindings) {
// BindingTester.checkBinding(binding);
// assertFalse("Indexes appear only once",
// indexes.removeAll(binding.nameIndexes));
// indexes.addAll(binding.nameIndexes);
// }
// }
//
// public static void checkBinding(final TokenNameBinding binding) {
// final String tokenName = binding.sourceCodeTokens
// .get(binding.nameIndexes.iterator().next());
// for (final int idx : binding.nameIndexes) {
// assertEquals(tokenName, binding.sourceCodeTokens.get(idx));
// }
// };
// }
//
// Path: src/test/java/codemining/js/codeutils/JavascriptASTExtractorTest.java
// public class JavascriptASTExtractorTest {
//
// String classContent;
// String methodContent;
//
// @Before
// public void setUp() throws IOException {
// classContent = FileUtils.readFileToString(new File(
// JavascriptASTExtractorTest.class.getClassLoader()
// .getResource("SampleJavascript2.txt").getFile()));
//
// methodContent = FileUtils.readFileToString(new File(
// JavascriptASTExtractorTest.class.getClassLoader()
// .getResource("SampleJavascript.txt").getFile()));
// }
//
// /**
// * Test method for
// * {@link codemining.java.codeutils.JavaASTExtractor#getBestEffortAst(java.lang.String)}
// * .
// *
// * @throws IOException
// */
// @Test
// public void testGetASTString() {
// final JavascriptASTExtractor ex = new JavascriptASTExtractor(false);
// assertTrue(classContent.length() > 0);
// final ASTNode classCU = ex.getASTNode(classContent,
// ParseType.COMPILATION_UNIT);
// // assertTrue(snippetMatchesAstTokens(classContent, classCU));
//
// assertTrue(methodContent.length() > 0);
// final ASTNode methodCU = ex.getASTNode(methodContent, ParseType.METHOD);
// // assertTrue(snippetMatchesAstTokens(methodContent, methodCU));
// }
//
// private boolean snippetMatchesAstTokens(final String snippetCode,
// final ASTNode node) {
// final JavascriptTokenizer tokenizer = new JavascriptTokenizer();
// final List<String> snippetTokens = tokenizer
// .tokenListFromCode(snippetCode.toCharArray());
// final List<String> astTokens = tokenizer.tokenListFromCode(node
// .toString().toCharArray());
// return astTokens.equals(snippetTokens);
// }
// }
//
// Path: src/main/java/codemining/languagetools/bindings/TokenNameBinding.java
// public class TokenNameBinding implements Serializable {
// private static final long serialVersionUID = 2020613810485746430L;
//
// /**
// * The tokens of source code.
// */
// public final List<String> sourceCodeTokens;
//
// /**
// * The positions in sourceCodeTokens that contain the given name.
// */
// public final Set<Integer> nameIndexes;
//
// /**
// * Features of the binding
// */
// public final Set<String> features;
//
// public TokenNameBinding(final Set<Integer> nameIndexes,
// final List<String> sourceCodeTokens, final Set<String> features) {
// checkArgument(nameIndexes.size() > 0);
// checkArgument(sourceCodeTokens.size() > 0);
// this.nameIndexes = Collections.unmodifiableSet(nameIndexes);
// this.sourceCodeTokens = Collections.unmodifiableList(sourceCodeTokens);
// this.features = features;
// }
//
// @Override
// public boolean equals(final Object obj) {
// if (this == obj) {
// return true;
// }
// if (obj == null) {
// return false;
// }
// if (getClass() != obj.getClass()) {
// return false;
// }
// final TokenNameBinding other = (TokenNameBinding) obj;
// return Objects.equal(nameIndexes, other.nameIndexes)
// && Objects.equal(features, other.features)
// && Objects.equal(sourceCodeTokens, other.sourceCodeTokens);
// }
//
// public String getName() {
// return sourceCodeTokens.get(nameIndexes.iterator().next());
// }
//
// @Override
// public int hashCode() {
// return Objects.hashCode(sourceCodeTokens, nameIndexes, features);
// }
//
// /**
// * Rename this name to the given binding. The source code tokens included in
// * this struct, now represent the new structure.
// *
// * @param name
// * @return
// */
// public TokenNameBinding renameTo(final String name) {
// final List<String> renamedCode = Lists.newArrayList(sourceCodeTokens);
// for (final int position : nameIndexes) {
// renamedCode.set(position, name);
// }
// return new TokenNameBinding(nameIndexes, renamedCode, features);
// }
//
// @Override
// public String toString() {
// return getName() + nameIndexes + " " + features;
// }
// }
// Path: src/test/java/codemining/js/codeutils/binding/JavascriptExactVariableBindingsExtractorTest.java
import java.io.File;
import java.io.IOException;
import java.util.List;
import org.junit.Before;
import org.junit.Test;
import codemining.java.codeutils.binding.BindingTester;
import codemining.js.codeutils.JavascriptASTExtractorTest;
import codemining.languagetools.bindings.TokenNameBinding;
package codemining.js.codeutils.binding;
// FIXME Tests commented out until binding resolution is fixed
public class JavascriptExactVariableBindingsExtractorTest {
File classContent;
File classContent2;
@Before
public void setUp() throws IOException { | classContent = new File(JavascriptASTExtractorTest.class |
mast-group/codemining-core | src/test/java/codemining/java/codeutils/binding/JavaMethodBindingExtractorTest.java | // Path: src/test/java/codemining/java/codeutils/JavaAstExtractorTest.java
// public class JavaAstExtractorTest {
//
// String classContent;
// String methodContent;
//
// @Before
// public void setUp() throws IOException {
// classContent = FileUtils.readFileToString(new File(
// JavaAstExtractorTest.class.getClassLoader()
// .getResource("SampleClass.txt").getFile()));
//
// methodContent = FileUtils.readFileToString(new File(
// JavaAstExtractorTest.class.getClassLoader()
// .getResource("SampleMethod.txt").getFile()));
// }
//
// /**
// * Test method for
// * {@link codemining.java.codeutils.JavaASTExtractor#getBestEffortAst(java.lang.String)}
// * .
// *
// * @throws IOException
// */
// @Test
// public void testGetASTString() {
// final JavaASTExtractor ex = new JavaASTExtractor(false);
// assertTrue(classContent.length() > 0);
// final ASTNode classCU = ex.getASTNode(classContent,
// ParseType.COMPILATION_UNIT);
// assertTrue(snippetMatchesAstTokens(classContent, classCU));
//
// assertTrue(methodContent.length() > 0);
// final ASTNode methodCU = ex.getASTNode(methodContent,
// ParseType.METHOD);
// assertTrue(snippetMatchesAstTokens(methodContent, methodCU));
// }
//
// private boolean snippetMatchesAstTokens(final String snippetCode,
// final ASTNode node) {
// final JavaTokenizer tokenizer = new JavaTokenizer();
// final List<String> snippetTokens = tokenizer
// .tokenListFromCode(snippetCode.toCharArray());
// final List<String> astTokens = tokenizer.tokenListFromCode(node
// .toString().toCharArray());
// return astTokens.equals(snippetTokens);
// }
// }
//
// Path: src/main/java/codemining/languagetools/bindings/TokenNameBinding.java
// public class TokenNameBinding implements Serializable {
// private static final long serialVersionUID = 2020613810485746430L;
//
// /**
// * The tokens of source code.
// */
// public final List<String> sourceCodeTokens;
//
// /**
// * The positions in sourceCodeTokens that contain the given name.
// */
// public final Set<Integer> nameIndexes;
//
// /**
// * Features of the binding
// */
// public final Set<String> features;
//
// public TokenNameBinding(final Set<Integer> nameIndexes,
// final List<String> sourceCodeTokens, final Set<String> features) {
// checkArgument(nameIndexes.size() > 0);
// checkArgument(sourceCodeTokens.size() > 0);
// this.nameIndexes = Collections.unmodifiableSet(nameIndexes);
// this.sourceCodeTokens = Collections.unmodifiableList(sourceCodeTokens);
// this.features = features;
// }
//
// @Override
// public boolean equals(final Object obj) {
// if (this == obj) {
// return true;
// }
// if (obj == null) {
// return false;
// }
// if (getClass() != obj.getClass()) {
// return false;
// }
// final TokenNameBinding other = (TokenNameBinding) obj;
// return Objects.equal(nameIndexes, other.nameIndexes)
// && Objects.equal(features, other.features)
// && Objects.equal(sourceCodeTokens, other.sourceCodeTokens);
// }
//
// public String getName() {
// return sourceCodeTokens.get(nameIndexes.iterator().next());
// }
//
// @Override
// public int hashCode() {
// return Objects.hashCode(sourceCodeTokens, nameIndexes, features);
// }
//
// /**
// * Rename this name to the given binding. The source code tokens included in
// * this struct, now represent the new structure.
// *
// * @param name
// * @return
// */
// public TokenNameBinding renameTo(final String name) {
// final List<String> renamedCode = Lists.newArrayList(sourceCodeTokens);
// for (final int position : nameIndexes) {
// renamedCode.set(position, name);
// }
// return new TokenNameBinding(nameIndexes, renamedCode, features);
// }
//
// @Override
// public String toString() {
// return getName() + nameIndexes + " " + features;
// }
// }
| import static org.junit.Assert.assertEquals;
import java.io.File;
import java.io.IOException;
import java.util.List;
import org.apache.commons.io.FileUtils;
import org.junit.Before;
import org.junit.Test;
import codemining.java.codeutils.JavaAstExtractorTest;
import codemining.languagetools.bindings.TokenNameBinding; | /**
*
*/
package codemining.java.codeutils.binding;
public class JavaMethodBindingExtractorTest {
File classContent;
File classContent2;
String methodContent;
@Before
public void setUp() throws IOException { | // Path: src/test/java/codemining/java/codeutils/JavaAstExtractorTest.java
// public class JavaAstExtractorTest {
//
// String classContent;
// String methodContent;
//
// @Before
// public void setUp() throws IOException {
// classContent = FileUtils.readFileToString(new File(
// JavaAstExtractorTest.class.getClassLoader()
// .getResource("SampleClass.txt").getFile()));
//
// methodContent = FileUtils.readFileToString(new File(
// JavaAstExtractorTest.class.getClassLoader()
// .getResource("SampleMethod.txt").getFile()));
// }
//
// /**
// * Test method for
// * {@link codemining.java.codeutils.JavaASTExtractor#getBestEffortAst(java.lang.String)}
// * .
// *
// * @throws IOException
// */
// @Test
// public void testGetASTString() {
// final JavaASTExtractor ex = new JavaASTExtractor(false);
// assertTrue(classContent.length() > 0);
// final ASTNode classCU = ex.getASTNode(classContent,
// ParseType.COMPILATION_UNIT);
// assertTrue(snippetMatchesAstTokens(classContent, classCU));
//
// assertTrue(methodContent.length() > 0);
// final ASTNode methodCU = ex.getASTNode(methodContent,
// ParseType.METHOD);
// assertTrue(snippetMatchesAstTokens(methodContent, methodCU));
// }
//
// private boolean snippetMatchesAstTokens(final String snippetCode,
// final ASTNode node) {
// final JavaTokenizer tokenizer = new JavaTokenizer();
// final List<String> snippetTokens = tokenizer
// .tokenListFromCode(snippetCode.toCharArray());
// final List<String> astTokens = tokenizer.tokenListFromCode(node
// .toString().toCharArray());
// return astTokens.equals(snippetTokens);
// }
// }
//
// Path: src/main/java/codemining/languagetools/bindings/TokenNameBinding.java
// public class TokenNameBinding implements Serializable {
// private static final long serialVersionUID = 2020613810485746430L;
//
// /**
// * The tokens of source code.
// */
// public final List<String> sourceCodeTokens;
//
// /**
// * The positions in sourceCodeTokens that contain the given name.
// */
// public final Set<Integer> nameIndexes;
//
// /**
// * Features of the binding
// */
// public final Set<String> features;
//
// public TokenNameBinding(final Set<Integer> nameIndexes,
// final List<String> sourceCodeTokens, final Set<String> features) {
// checkArgument(nameIndexes.size() > 0);
// checkArgument(sourceCodeTokens.size() > 0);
// this.nameIndexes = Collections.unmodifiableSet(nameIndexes);
// this.sourceCodeTokens = Collections.unmodifiableList(sourceCodeTokens);
// this.features = features;
// }
//
// @Override
// public boolean equals(final Object obj) {
// if (this == obj) {
// return true;
// }
// if (obj == null) {
// return false;
// }
// if (getClass() != obj.getClass()) {
// return false;
// }
// final TokenNameBinding other = (TokenNameBinding) obj;
// return Objects.equal(nameIndexes, other.nameIndexes)
// && Objects.equal(features, other.features)
// && Objects.equal(sourceCodeTokens, other.sourceCodeTokens);
// }
//
// public String getName() {
// return sourceCodeTokens.get(nameIndexes.iterator().next());
// }
//
// @Override
// public int hashCode() {
// return Objects.hashCode(sourceCodeTokens, nameIndexes, features);
// }
//
// /**
// * Rename this name to the given binding. The source code tokens included in
// * this struct, now represent the new structure.
// *
// * @param name
// * @return
// */
// public TokenNameBinding renameTo(final String name) {
// final List<String> renamedCode = Lists.newArrayList(sourceCodeTokens);
// for (final int position : nameIndexes) {
// renamedCode.set(position, name);
// }
// return new TokenNameBinding(nameIndexes, renamedCode, features);
// }
//
// @Override
// public String toString() {
// return getName() + nameIndexes + " " + features;
// }
// }
// Path: src/test/java/codemining/java/codeutils/binding/JavaMethodBindingExtractorTest.java
import static org.junit.Assert.assertEquals;
import java.io.File;
import java.io.IOException;
import java.util.List;
import org.apache.commons.io.FileUtils;
import org.junit.Before;
import org.junit.Test;
import codemining.java.codeutils.JavaAstExtractorTest;
import codemining.languagetools.bindings.TokenNameBinding;
/**
*
*/
package codemining.java.codeutils.binding;
public class JavaMethodBindingExtractorTest {
File classContent;
File classContent2;
String methodContent;
@Before
public void setUp() throws IOException { | classContent = new File(JavaAstExtractorTest.class.getClassLoader() |
mast-group/codemining-core | src/test/java/codemining/java/codeutils/binding/JavaMethodBindingExtractorTest.java | // Path: src/test/java/codemining/java/codeutils/JavaAstExtractorTest.java
// public class JavaAstExtractorTest {
//
// String classContent;
// String methodContent;
//
// @Before
// public void setUp() throws IOException {
// classContent = FileUtils.readFileToString(new File(
// JavaAstExtractorTest.class.getClassLoader()
// .getResource("SampleClass.txt").getFile()));
//
// methodContent = FileUtils.readFileToString(new File(
// JavaAstExtractorTest.class.getClassLoader()
// .getResource("SampleMethod.txt").getFile()));
// }
//
// /**
// * Test method for
// * {@link codemining.java.codeutils.JavaASTExtractor#getBestEffortAst(java.lang.String)}
// * .
// *
// * @throws IOException
// */
// @Test
// public void testGetASTString() {
// final JavaASTExtractor ex = new JavaASTExtractor(false);
// assertTrue(classContent.length() > 0);
// final ASTNode classCU = ex.getASTNode(classContent,
// ParseType.COMPILATION_UNIT);
// assertTrue(snippetMatchesAstTokens(classContent, classCU));
//
// assertTrue(methodContent.length() > 0);
// final ASTNode methodCU = ex.getASTNode(methodContent,
// ParseType.METHOD);
// assertTrue(snippetMatchesAstTokens(methodContent, methodCU));
// }
//
// private boolean snippetMatchesAstTokens(final String snippetCode,
// final ASTNode node) {
// final JavaTokenizer tokenizer = new JavaTokenizer();
// final List<String> snippetTokens = tokenizer
// .tokenListFromCode(snippetCode.toCharArray());
// final List<String> astTokens = tokenizer.tokenListFromCode(node
// .toString().toCharArray());
// return astTokens.equals(snippetTokens);
// }
// }
//
// Path: src/main/java/codemining/languagetools/bindings/TokenNameBinding.java
// public class TokenNameBinding implements Serializable {
// private static final long serialVersionUID = 2020613810485746430L;
//
// /**
// * The tokens of source code.
// */
// public final List<String> sourceCodeTokens;
//
// /**
// * The positions in sourceCodeTokens that contain the given name.
// */
// public final Set<Integer> nameIndexes;
//
// /**
// * Features of the binding
// */
// public final Set<String> features;
//
// public TokenNameBinding(final Set<Integer> nameIndexes,
// final List<String> sourceCodeTokens, final Set<String> features) {
// checkArgument(nameIndexes.size() > 0);
// checkArgument(sourceCodeTokens.size() > 0);
// this.nameIndexes = Collections.unmodifiableSet(nameIndexes);
// this.sourceCodeTokens = Collections.unmodifiableList(sourceCodeTokens);
// this.features = features;
// }
//
// @Override
// public boolean equals(final Object obj) {
// if (this == obj) {
// return true;
// }
// if (obj == null) {
// return false;
// }
// if (getClass() != obj.getClass()) {
// return false;
// }
// final TokenNameBinding other = (TokenNameBinding) obj;
// return Objects.equal(nameIndexes, other.nameIndexes)
// && Objects.equal(features, other.features)
// && Objects.equal(sourceCodeTokens, other.sourceCodeTokens);
// }
//
// public String getName() {
// return sourceCodeTokens.get(nameIndexes.iterator().next());
// }
//
// @Override
// public int hashCode() {
// return Objects.hashCode(sourceCodeTokens, nameIndexes, features);
// }
//
// /**
// * Rename this name to the given binding. The source code tokens included in
// * this struct, now represent the new structure.
// *
// * @param name
// * @return
// */
// public TokenNameBinding renameTo(final String name) {
// final List<String> renamedCode = Lists.newArrayList(sourceCodeTokens);
// for (final int position : nameIndexes) {
// renamedCode.set(position, name);
// }
// return new TokenNameBinding(nameIndexes, renamedCode, features);
// }
//
// @Override
// public String toString() {
// return getName() + nameIndexes + " " + features;
// }
// }
| import static org.junit.Assert.assertEquals;
import java.io.File;
import java.io.IOException;
import java.util.List;
import org.apache.commons.io.FileUtils;
import org.junit.Before;
import org.junit.Test;
import codemining.java.codeutils.JavaAstExtractorTest;
import codemining.languagetools.bindings.TokenNameBinding; | /**
*
*/
package codemining.java.codeutils.binding;
public class JavaMethodBindingExtractorTest {
File classContent;
File classContent2;
String methodContent;
@Before
public void setUp() throws IOException {
classContent = new File(JavaAstExtractorTest.class.getClassLoader()
.getResource("SampleClass.txt").getFile());
classContent2 = new File(JavaAstExtractorTest.class.getClassLoader()
.getResource("SampleClass2.txt").getFile());
methodContent = FileUtils.readFileToString(new File(
JavaAstExtractorTest.class.getClassLoader()
.getResource("SampleMethod.txt").getFile()));
}
@Test
public void testClassLevelBindings() throws IOException {
final JavaMethodInvocationBindingExtractor jame = new JavaMethodInvocationBindingExtractor();
| // Path: src/test/java/codemining/java/codeutils/JavaAstExtractorTest.java
// public class JavaAstExtractorTest {
//
// String classContent;
// String methodContent;
//
// @Before
// public void setUp() throws IOException {
// classContent = FileUtils.readFileToString(new File(
// JavaAstExtractorTest.class.getClassLoader()
// .getResource("SampleClass.txt").getFile()));
//
// methodContent = FileUtils.readFileToString(new File(
// JavaAstExtractorTest.class.getClassLoader()
// .getResource("SampleMethod.txt").getFile()));
// }
//
// /**
// * Test method for
// * {@link codemining.java.codeutils.JavaASTExtractor#getBestEffortAst(java.lang.String)}
// * .
// *
// * @throws IOException
// */
// @Test
// public void testGetASTString() {
// final JavaASTExtractor ex = new JavaASTExtractor(false);
// assertTrue(classContent.length() > 0);
// final ASTNode classCU = ex.getASTNode(classContent,
// ParseType.COMPILATION_UNIT);
// assertTrue(snippetMatchesAstTokens(classContent, classCU));
//
// assertTrue(methodContent.length() > 0);
// final ASTNode methodCU = ex.getASTNode(methodContent,
// ParseType.METHOD);
// assertTrue(snippetMatchesAstTokens(methodContent, methodCU));
// }
//
// private boolean snippetMatchesAstTokens(final String snippetCode,
// final ASTNode node) {
// final JavaTokenizer tokenizer = new JavaTokenizer();
// final List<String> snippetTokens = tokenizer
// .tokenListFromCode(snippetCode.toCharArray());
// final List<String> astTokens = tokenizer.tokenListFromCode(node
// .toString().toCharArray());
// return astTokens.equals(snippetTokens);
// }
// }
//
// Path: src/main/java/codemining/languagetools/bindings/TokenNameBinding.java
// public class TokenNameBinding implements Serializable {
// private static final long serialVersionUID = 2020613810485746430L;
//
// /**
// * The tokens of source code.
// */
// public final List<String> sourceCodeTokens;
//
// /**
// * The positions in sourceCodeTokens that contain the given name.
// */
// public final Set<Integer> nameIndexes;
//
// /**
// * Features of the binding
// */
// public final Set<String> features;
//
// public TokenNameBinding(final Set<Integer> nameIndexes,
// final List<String> sourceCodeTokens, final Set<String> features) {
// checkArgument(nameIndexes.size() > 0);
// checkArgument(sourceCodeTokens.size() > 0);
// this.nameIndexes = Collections.unmodifiableSet(nameIndexes);
// this.sourceCodeTokens = Collections.unmodifiableList(sourceCodeTokens);
// this.features = features;
// }
//
// @Override
// public boolean equals(final Object obj) {
// if (this == obj) {
// return true;
// }
// if (obj == null) {
// return false;
// }
// if (getClass() != obj.getClass()) {
// return false;
// }
// final TokenNameBinding other = (TokenNameBinding) obj;
// return Objects.equal(nameIndexes, other.nameIndexes)
// && Objects.equal(features, other.features)
// && Objects.equal(sourceCodeTokens, other.sourceCodeTokens);
// }
//
// public String getName() {
// return sourceCodeTokens.get(nameIndexes.iterator().next());
// }
//
// @Override
// public int hashCode() {
// return Objects.hashCode(sourceCodeTokens, nameIndexes, features);
// }
//
// /**
// * Rename this name to the given binding. The source code tokens included in
// * this struct, now represent the new structure.
// *
// * @param name
// * @return
// */
// public TokenNameBinding renameTo(final String name) {
// final List<String> renamedCode = Lists.newArrayList(sourceCodeTokens);
// for (final int position : nameIndexes) {
// renamedCode.set(position, name);
// }
// return new TokenNameBinding(nameIndexes, renamedCode, features);
// }
//
// @Override
// public String toString() {
// return getName() + nameIndexes + " " + features;
// }
// }
// Path: src/test/java/codemining/java/codeutils/binding/JavaMethodBindingExtractorTest.java
import static org.junit.Assert.assertEquals;
import java.io.File;
import java.io.IOException;
import java.util.List;
import org.apache.commons.io.FileUtils;
import org.junit.Before;
import org.junit.Test;
import codemining.java.codeutils.JavaAstExtractorTest;
import codemining.languagetools.bindings.TokenNameBinding;
/**
*
*/
package codemining.java.codeutils.binding;
public class JavaMethodBindingExtractorTest {
File classContent;
File classContent2;
String methodContent;
@Before
public void setUp() throws IOException {
classContent = new File(JavaAstExtractorTest.class.getClassLoader()
.getResource("SampleClass.txt").getFile());
classContent2 = new File(JavaAstExtractorTest.class.getClassLoader()
.getResource("SampleClass2.txt").getFile());
methodContent = FileUtils.readFileToString(new File(
JavaAstExtractorTest.class.getClassLoader()
.getResource("SampleMethod.txt").getFile()));
}
@Test
public void testClassLevelBindings() throws IOException {
final JavaMethodInvocationBindingExtractor jame = new JavaMethodInvocationBindingExtractor();
| final List<TokenNameBinding> classMethodBindings = jame |
Vazkii/Emotes | MODSRC/vazkii/emotes/client/emote/base/EmoteBase.java | // Path: MODSRC/vazkii/emotes/client/ClientProxy.java
// public class ClientProxy extends CommonProxy {
//
// public static float time = 0F;
// public static float delta = 0F;
//
// @Override
// public void init() {
// super.init();
// Tween.registerAccessor(ModelBiped.class, new ModelAccessor());
// FMLCommonHandler.instance().bus().register(this);
//
// initEmotes();
// }
//
// @Override
// public void handlePacket(PacketEmote message) {
// World world = Minecraft.getMinecraft().theWorld;
// EntityPlayer player = world.getPlayerEntityByName(message.playerName);
// if(player != null) {
// if(message.emoteName.equals("list"))
// player.addChatComponentMessage(EmoteHandler.buildEmoteListStr());
// else EmoteHandler.putEmote(player, message.emoteName);
// }
// }
//
// private void initEmotes() {
// EmoteHandler.emoteMap.put("airguitar", EmoteAirGuitar.class);
// EmoteHandler.emoteMap.put("balance", EmoteBalance.class);
// EmoteHandler.emoteMap.put("cheer", EmoteCheer.class);
// EmoteHandler.emoteMap.put("clap", EmoteClap.class);
// EmoteHandler.emoteMap.put("exorcist", EmoteExorcist.class);
// EmoteHandler.emoteMap.put("facepalm", EmoteFacepalm.class);
// EmoteHandler.emoteMap.put("gangnamstyle", EmoteGangnamStyle.class);
// EmoteHandler.emoteMap.put("headbang", EmoteHeadbang.class);
// EmoteHandler.emoteMap.put("levitate", EmoteLevitate.class);
// EmoteHandler.emoteMap.put("no", EmoteNo.class);
// EmoteHandler.emoteMap.put("point", EmotePoint.class);
// EmoteHandler.emoteMap.put("run", EmoteRun.class);
// EmoteHandler.emoteMap.put("salute", EmoteSalute.class);
// EmoteHandler.emoteMap.put("shaftheadtilt", EmoteShaftHeadTilt.class);
// EmoteHandler.emoteMap.put("shrug", EmoteShrug.class);
// EmoteHandler.emoteMap.put("stand", EmoteStand.class);
// EmoteHandler.emoteMap.put("think", EmoteThink.class);
// EmoteHandler.emoteMap.put("wave", EmoteWave.class);
// EmoteHandler.emoteMap.put("yes", EmoteYes.class);
// EmoteHandler.emoteMap.put("zombie", EmoteZombie.class);
// }
//
// @SubscribeEvent
// public void onRenderStart(RenderTickEvent event) {
// if(event.phase == Phase.START) {
// float ctime = (float) Math.floor(time) + event.renderTickTime;
// delta = (ctime - time) * 50;
// time = ctime;
// EmoteHandler.clearPlayerList();
// }
// }
//
// @SubscribeEvent
// public void onTick(ClientTickEvent event) {
// if(event.phase == Phase.START)
// time = (float) Math.ceil(time);
// }
// }
| import net.minecraft.client.model.ModelBiped;
import net.minecraft.entity.player.EntityPlayer;
import vazkii.emotes.client.ClientProxy;
import aurelienribon.tweenengine.BaseTween;
import aurelienribon.tweenengine.Timeline;
import aurelienribon.tweenengine.TweenCallback;
import aurelienribon.tweenengine.TweenManager; |
private boolean done = false;
public EmoteBase(EntityPlayer player, ModelBiped model, ModelBiped armorModel, ModelBiped armorLegsModel) {
emoteManager = new TweenManager();
state = new EmoteState(this);
this.model = model;
this.armorModel = armorModel;
this.armorLegsModel = armorLegsModel;
startTimeline(player, model, true);
startTimeline(player, armorModel, false);
startTimeline(player, armorLegsModel, false);
}
void startTimeline(EntityPlayer player, ModelBiped model, boolean callback) {
Timeline timeline = getTimeline(player, model).start(emoteManager);
if(callback)
timeline.setCallback(new FinishCallback());
}
public abstract Timeline getTimeline(EntityPlayer player, ModelBiped model);
public abstract boolean usesBodyPart(int part);
public void update(boolean doUpdate) {
state.load(model);
state.load(armorModel);
state.load(armorLegsModel);
if(doUpdate) { | // Path: MODSRC/vazkii/emotes/client/ClientProxy.java
// public class ClientProxy extends CommonProxy {
//
// public static float time = 0F;
// public static float delta = 0F;
//
// @Override
// public void init() {
// super.init();
// Tween.registerAccessor(ModelBiped.class, new ModelAccessor());
// FMLCommonHandler.instance().bus().register(this);
//
// initEmotes();
// }
//
// @Override
// public void handlePacket(PacketEmote message) {
// World world = Minecraft.getMinecraft().theWorld;
// EntityPlayer player = world.getPlayerEntityByName(message.playerName);
// if(player != null) {
// if(message.emoteName.equals("list"))
// player.addChatComponentMessage(EmoteHandler.buildEmoteListStr());
// else EmoteHandler.putEmote(player, message.emoteName);
// }
// }
//
// private void initEmotes() {
// EmoteHandler.emoteMap.put("airguitar", EmoteAirGuitar.class);
// EmoteHandler.emoteMap.put("balance", EmoteBalance.class);
// EmoteHandler.emoteMap.put("cheer", EmoteCheer.class);
// EmoteHandler.emoteMap.put("clap", EmoteClap.class);
// EmoteHandler.emoteMap.put("exorcist", EmoteExorcist.class);
// EmoteHandler.emoteMap.put("facepalm", EmoteFacepalm.class);
// EmoteHandler.emoteMap.put("gangnamstyle", EmoteGangnamStyle.class);
// EmoteHandler.emoteMap.put("headbang", EmoteHeadbang.class);
// EmoteHandler.emoteMap.put("levitate", EmoteLevitate.class);
// EmoteHandler.emoteMap.put("no", EmoteNo.class);
// EmoteHandler.emoteMap.put("point", EmotePoint.class);
// EmoteHandler.emoteMap.put("run", EmoteRun.class);
// EmoteHandler.emoteMap.put("salute", EmoteSalute.class);
// EmoteHandler.emoteMap.put("shaftheadtilt", EmoteShaftHeadTilt.class);
// EmoteHandler.emoteMap.put("shrug", EmoteShrug.class);
// EmoteHandler.emoteMap.put("stand", EmoteStand.class);
// EmoteHandler.emoteMap.put("think", EmoteThink.class);
// EmoteHandler.emoteMap.put("wave", EmoteWave.class);
// EmoteHandler.emoteMap.put("yes", EmoteYes.class);
// EmoteHandler.emoteMap.put("zombie", EmoteZombie.class);
// }
//
// @SubscribeEvent
// public void onRenderStart(RenderTickEvent event) {
// if(event.phase == Phase.START) {
// float ctime = (float) Math.floor(time) + event.renderTickTime;
// delta = (ctime - time) * 50;
// time = ctime;
// EmoteHandler.clearPlayerList();
// }
// }
//
// @SubscribeEvent
// public void onTick(ClientTickEvent event) {
// if(event.phase == Phase.START)
// time = (float) Math.ceil(time);
// }
// }
// Path: MODSRC/vazkii/emotes/client/emote/base/EmoteBase.java
import net.minecraft.client.model.ModelBiped;
import net.minecraft.entity.player.EntityPlayer;
import vazkii.emotes.client.ClientProxy;
import aurelienribon.tweenengine.BaseTween;
import aurelienribon.tweenengine.Timeline;
import aurelienribon.tweenengine.TweenCallback;
import aurelienribon.tweenengine.TweenManager;
private boolean done = false;
public EmoteBase(EntityPlayer player, ModelBiped model, ModelBiped armorModel, ModelBiped armorLegsModel) {
emoteManager = new TweenManager();
state = new EmoteState(this);
this.model = model;
this.armorModel = armorModel;
this.armorLegsModel = armorLegsModel;
startTimeline(player, model, true);
startTimeline(player, armorModel, false);
startTimeline(player, armorLegsModel, false);
}
void startTimeline(EntityPlayer player, ModelBiped model, boolean callback) {
Timeline timeline = getTimeline(player, model).start(emoteManager);
if(callback)
timeline.setCallback(new FinishCallback());
}
public abstract Timeline getTimeline(EntityPlayer player, ModelBiped model);
public abstract boolean usesBodyPart(int part);
public void update(boolean doUpdate) {
state.load(model);
state.load(armorModel);
state.load(armorLegsModel);
if(doUpdate) { | emoteManager.update(ClientProxy.delta); |
Vazkii/Emotes | MODSRC/vazkii/emotes/common/CommandEmote.java | // Path: MODSRC/vazkii/emotes/common/network/PacketEmote.java
// public class PacketEmote implements IMessage, IMessageHandler<PacketEmote, IMessage> {
//
// public String emoteName;
// public String playerName;
//
// public PacketEmote() { }
//
// public PacketEmote(String name, String player) {
// this.emoteName = name;
// this.playerName = player;
// }
//
// @Override
// public void fromBytes(ByteBuf buffer) {
// PacketBuffer packet = new PacketBuffer(buffer);
// try {
// emoteName = packet.readStringFromBuffer(32);
// playerName = packet.readStringFromBuffer(32);
// } catch (IOException e) {
// e.printStackTrace();
// }
// }
//
// @Override
// public void toBytes(ByteBuf buffer) {
// PacketBuffer packet = new PacketBuffer(buffer);
// try {
// packet.writeStringToBuffer(emoteName);
// packet.writeStringToBuffer(playerName);
// } catch (IOException e) {
// e.printStackTrace();
// }
// }
//
// @Override
// public IMessage onMessage(PacketEmote message, MessageContext context) {
// Emotes.proxy.handlePacket(message);
// return null;
// }
//
// }
//
// Path: MODSRC/vazkii/emotes/common/network/PacketHandler.java
// public class PacketHandler {
//
// public static final SimpleNetworkWrapper INSTANCE = NetworkRegistry.INSTANCE.newSimpleChannel("vEmotes");
//
// public static void init() {
// INSTANCE.registerMessage(PacketEmote.class, PacketEmote.class, 0, Side.CLIENT);
// }
//
// }
| import net.minecraft.command.CommandBase;
import net.minecraft.command.ICommandSender;
import net.minecraft.entity.player.EntityPlayer;
import vazkii.emotes.common.network.PacketEmote;
import vazkii.emotes.common.network.PacketHandler; | package vazkii.emotes.common;
public class CommandEmote extends CommandBase {
@Override
public String getCommandName() {
return "emote";
}
@Override
public String getCommandUsage(ICommandSender p_71518_1_) {
return "<emote>";
}
@Override
public void processCommand(ICommandSender sender, String[] args) {
if(args.length > 0 && sender instanceof EntityPlayer) | // Path: MODSRC/vazkii/emotes/common/network/PacketEmote.java
// public class PacketEmote implements IMessage, IMessageHandler<PacketEmote, IMessage> {
//
// public String emoteName;
// public String playerName;
//
// public PacketEmote() { }
//
// public PacketEmote(String name, String player) {
// this.emoteName = name;
// this.playerName = player;
// }
//
// @Override
// public void fromBytes(ByteBuf buffer) {
// PacketBuffer packet = new PacketBuffer(buffer);
// try {
// emoteName = packet.readStringFromBuffer(32);
// playerName = packet.readStringFromBuffer(32);
// } catch (IOException e) {
// e.printStackTrace();
// }
// }
//
// @Override
// public void toBytes(ByteBuf buffer) {
// PacketBuffer packet = new PacketBuffer(buffer);
// try {
// packet.writeStringToBuffer(emoteName);
// packet.writeStringToBuffer(playerName);
// } catch (IOException e) {
// e.printStackTrace();
// }
// }
//
// @Override
// public IMessage onMessage(PacketEmote message, MessageContext context) {
// Emotes.proxy.handlePacket(message);
// return null;
// }
//
// }
//
// Path: MODSRC/vazkii/emotes/common/network/PacketHandler.java
// public class PacketHandler {
//
// public static final SimpleNetworkWrapper INSTANCE = NetworkRegistry.INSTANCE.newSimpleChannel("vEmotes");
//
// public static void init() {
// INSTANCE.registerMessage(PacketEmote.class, PacketEmote.class, 0, Side.CLIENT);
// }
//
// }
// Path: MODSRC/vazkii/emotes/common/CommandEmote.java
import net.minecraft.command.CommandBase;
import net.minecraft.command.ICommandSender;
import net.minecraft.entity.player.EntityPlayer;
import vazkii.emotes.common.network.PacketEmote;
import vazkii.emotes.common.network.PacketHandler;
package vazkii.emotes.common;
public class CommandEmote extends CommandBase {
@Override
public String getCommandName() {
return "emote";
}
@Override
public String getCommandUsage(ICommandSender p_71518_1_) {
return "<emote>";
}
@Override
public void processCommand(ICommandSender sender, String[] args) {
if(args.length > 0 && sender instanceof EntityPlayer) | PacketHandler.INSTANCE.sendToAll(new PacketEmote(args[0], sender.getCommandSenderName())); |
Vazkii/Emotes | MODSRC/vazkii/emotes/common/CommandEmote.java | // Path: MODSRC/vazkii/emotes/common/network/PacketEmote.java
// public class PacketEmote implements IMessage, IMessageHandler<PacketEmote, IMessage> {
//
// public String emoteName;
// public String playerName;
//
// public PacketEmote() { }
//
// public PacketEmote(String name, String player) {
// this.emoteName = name;
// this.playerName = player;
// }
//
// @Override
// public void fromBytes(ByteBuf buffer) {
// PacketBuffer packet = new PacketBuffer(buffer);
// try {
// emoteName = packet.readStringFromBuffer(32);
// playerName = packet.readStringFromBuffer(32);
// } catch (IOException e) {
// e.printStackTrace();
// }
// }
//
// @Override
// public void toBytes(ByteBuf buffer) {
// PacketBuffer packet = new PacketBuffer(buffer);
// try {
// packet.writeStringToBuffer(emoteName);
// packet.writeStringToBuffer(playerName);
// } catch (IOException e) {
// e.printStackTrace();
// }
// }
//
// @Override
// public IMessage onMessage(PacketEmote message, MessageContext context) {
// Emotes.proxy.handlePacket(message);
// return null;
// }
//
// }
//
// Path: MODSRC/vazkii/emotes/common/network/PacketHandler.java
// public class PacketHandler {
//
// public static final SimpleNetworkWrapper INSTANCE = NetworkRegistry.INSTANCE.newSimpleChannel("vEmotes");
//
// public static void init() {
// INSTANCE.registerMessage(PacketEmote.class, PacketEmote.class, 0, Side.CLIENT);
// }
//
// }
| import net.minecraft.command.CommandBase;
import net.minecraft.command.ICommandSender;
import net.minecraft.entity.player.EntityPlayer;
import vazkii.emotes.common.network.PacketEmote;
import vazkii.emotes.common.network.PacketHandler; | package vazkii.emotes.common;
public class CommandEmote extends CommandBase {
@Override
public String getCommandName() {
return "emote";
}
@Override
public String getCommandUsage(ICommandSender p_71518_1_) {
return "<emote>";
}
@Override
public void processCommand(ICommandSender sender, String[] args) {
if(args.length > 0 && sender instanceof EntityPlayer) | // Path: MODSRC/vazkii/emotes/common/network/PacketEmote.java
// public class PacketEmote implements IMessage, IMessageHandler<PacketEmote, IMessage> {
//
// public String emoteName;
// public String playerName;
//
// public PacketEmote() { }
//
// public PacketEmote(String name, String player) {
// this.emoteName = name;
// this.playerName = player;
// }
//
// @Override
// public void fromBytes(ByteBuf buffer) {
// PacketBuffer packet = new PacketBuffer(buffer);
// try {
// emoteName = packet.readStringFromBuffer(32);
// playerName = packet.readStringFromBuffer(32);
// } catch (IOException e) {
// e.printStackTrace();
// }
// }
//
// @Override
// public void toBytes(ByteBuf buffer) {
// PacketBuffer packet = new PacketBuffer(buffer);
// try {
// packet.writeStringToBuffer(emoteName);
// packet.writeStringToBuffer(playerName);
// } catch (IOException e) {
// e.printStackTrace();
// }
// }
//
// @Override
// public IMessage onMessage(PacketEmote message, MessageContext context) {
// Emotes.proxy.handlePacket(message);
// return null;
// }
//
// }
//
// Path: MODSRC/vazkii/emotes/common/network/PacketHandler.java
// public class PacketHandler {
//
// public static final SimpleNetworkWrapper INSTANCE = NetworkRegistry.INSTANCE.newSimpleChannel("vEmotes");
//
// public static void init() {
// INSTANCE.registerMessage(PacketEmote.class, PacketEmote.class, 0, Side.CLIENT);
// }
//
// }
// Path: MODSRC/vazkii/emotes/common/CommandEmote.java
import net.minecraft.command.CommandBase;
import net.minecraft.command.ICommandSender;
import net.minecraft.entity.player.EntityPlayer;
import vazkii.emotes.common.network.PacketEmote;
import vazkii.emotes.common.network.PacketHandler;
package vazkii.emotes.common;
public class CommandEmote extends CommandBase {
@Override
public String getCommandName() {
return "emote";
}
@Override
public String getCommandUsage(ICommandSender p_71518_1_) {
return "<emote>";
}
@Override
public void processCommand(ICommandSender sender, String[] args) {
if(args.length > 0 && sender instanceof EntityPlayer) | PacketHandler.INSTANCE.sendToAll(new PacketEmote(args[0], sender.getCommandSenderName())); |
Vazkii/Emotes | MODSRC/vazkii/emotes/common/network/PacketEmote.java | // Path: MODSRC/vazkii/emotes/common/Emotes.java
// @Mod(modid = "Emotes", name = "Emotes", version = "1.0")
// public class Emotes {
//
// @SidedProxy(clientSide = "vazkii.emotes.client.ClientProxy", serverSide = "vazkii.emotes.common.CommonProxy")
// public static CommonProxy proxy;
//
// @EventHandler
// public void init(FMLInitializationEvent event) {
// proxy.init();
// }
//
// @EventHandler
// public void serverStarting(FMLServerStartingEvent event) {
// event.registerServerCommand(new CommandEmote());
// }
//
// }
| import io.netty.buffer.ByteBuf;
import java.io.IOException;
import net.minecraft.network.PacketBuffer;
import vazkii.emotes.common.Emotes;
import cpw.mods.fml.common.network.simpleimpl.IMessage;
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
import cpw.mods.fml.common.network.simpleimpl.MessageContext; |
public PacketEmote(String name, String player) {
this.emoteName = name;
this.playerName = player;
}
@Override
public void fromBytes(ByteBuf buffer) {
PacketBuffer packet = new PacketBuffer(buffer);
try {
emoteName = packet.readStringFromBuffer(32);
playerName = packet.readStringFromBuffer(32);
} catch (IOException e) {
e.printStackTrace();
}
}
@Override
public void toBytes(ByteBuf buffer) {
PacketBuffer packet = new PacketBuffer(buffer);
try {
packet.writeStringToBuffer(emoteName);
packet.writeStringToBuffer(playerName);
} catch (IOException e) {
e.printStackTrace();
}
}
@Override
public IMessage onMessage(PacketEmote message, MessageContext context) { | // Path: MODSRC/vazkii/emotes/common/Emotes.java
// @Mod(modid = "Emotes", name = "Emotes", version = "1.0")
// public class Emotes {
//
// @SidedProxy(clientSide = "vazkii.emotes.client.ClientProxy", serverSide = "vazkii.emotes.common.CommonProxy")
// public static CommonProxy proxy;
//
// @EventHandler
// public void init(FMLInitializationEvent event) {
// proxy.init();
// }
//
// @EventHandler
// public void serverStarting(FMLServerStartingEvent event) {
// event.registerServerCommand(new CommandEmote());
// }
//
// }
// Path: MODSRC/vazkii/emotes/common/network/PacketEmote.java
import io.netty.buffer.ByteBuf;
import java.io.IOException;
import net.minecraft.network.PacketBuffer;
import vazkii.emotes.common.Emotes;
import cpw.mods.fml.common.network.simpleimpl.IMessage;
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
public PacketEmote(String name, String player) {
this.emoteName = name;
this.playerName = player;
}
@Override
public void fromBytes(ByteBuf buffer) {
PacketBuffer packet = new PacketBuffer(buffer);
try {
emoteName = packet.readStringFromBuffer(32);
playerName = packet.readStringFromBuffer(32);
} catch (IOException e) {
e.printStackTrace();
}
}
@Override
public void toBytes(ByteBuf buffer) {
PacketBuffer packet = new PacketBuffer(buffer);
try {
packet.writeStringToBuffer(emoteName);
packet.writeStringToBuffer(playerName);
} catch (IOException e) {
e.printStackTrace();
}
}
@Override
public IMessage onMessage(PacketEmote message, MessageContext context) { | Emotes.proxy.handlePacket(message); |
Vazkii/Emotes | MODSRC/vazkii/emotes/common/CommonProxy.java | // Path: MODSRC/vazkii/emotes/common/network/PacketEmote.java
// public class PacketEmote implements IMessage, IMessageHandler<PacketEmote, IMessage> {
//
// public String emoteName;
// public String playerName;
//
// public PacketEmote() { }
//
// public PacketEmote(String name, String player) {
// this.emoteName = name;
// this.playerName = player;
// }
//
// @Override
// public void fromBytes(ByteBuf buffer) {
// PacketBuffer packet = new PacketBuffer(buffer);
// try {
// emoteName = packet.readStringFromBuffer(32);
// playerName = packet.readStringFromBuffer(32);
// } catch (IOException e) {
// e.printStackTrace();
// }
// }
//
// @Override
// public void toBytes(ByteBuf buffer) {
// PacketBuffer packet = new PacketBuffer(buffer);
// try {
// packet.writeStringToBuffer(emoteName);
// packet.writeStringToBuffer(playerName);
// } catch (IOException e) {
// e.printStackTrace();
// }
// }
//
// @Override
// public IMessage onMessage(PacketEmote message, MessageContext context) {
// Emotes.proxy.handlePacket(message);
// return null;
// }
//
// }
//
// Path: MODSRC/vazkii/emotes/common/network/PacketHandler.java
// public class PacketHandler {
//
// public static final SimpleNetworkWrapper INSTANCE = NetworkRegistry.INSTANCE.newSimpleChannel("vEmotes");
//
// public static void init() {
// INSTANCE.registerMessage(PacketEmote.class, PacketEmote.class, 0, Side.CLIENT);
// }
//
// }
| import vazkii.emotes.common.network.PacketEmote;
import vazkii.emotes.common.network.PacketHandler; | package vazkii.emotes.common;
public class CommonProxy {
public void init() { | // Path: MODSRC/vazkii/emotes/common/network/PacketEmote.java
// public class PacketEmote implements IMessage, IMessageHandler<PacketEmote, IMessage> {
//
// public String emoteName;
// public String playerName;
//
// public PacketEmote() { }
//
// public PacketEmote(String name, String player) {
// this.emoteName = name;
// this.playerName = player;
// }
//
// @Override
// public void fromBytes(ByteBuf buffer) {
// PacketBuffer packet = new PacketBuffer(buffer);
// try {
// emoteName = packet.readStringFromBuffer(32);
// playerName = packet.readStringFromBuffer(32);
// } catch (IOException e) {
// e.printStackTrace();
// }
// }
//
// @Override
// public void toBytes(ByteBuf buffer) {
// PacketBuffer packet = new PacketBuffer(buffer);
// try {
// packet.writeStringToBuffer(emoteName);
// packet.writeStringToBuffer(playerName);
// } catch (IOException e) {
// e.printStackTrace();
// }
// }
//
// @Override
// public IMessage onMessage(PacketEmote message, MessageContext context) {
// Emotes.proxy.handlePacket(message);
// return null;
// }
//
// }
//
// Path: MODSRC/vazkii/emotes/common/network/PacketHandler.java
// public class PacketHandler {
//
// public static final SimpleNetworkWrapper INSTANCE = NetworkRegistry.INSTANCE.newSimpleChannel("vEmotes");
//
// public static void init() {
// INSTANCE.registerMessage(PacketEmote.class, PacketEmote.class, 0, Side.CLIENT);
// }
//
// }
// Path: MODSRC/vazkii/emotes/common/CommonProxy.java
import vazkii.emotes.common.network.PacketEmote;
import vazkii.emotes.common.network.PacketHandler;
package vazkii.emotes.common;
public class CommonProxy {
public void init() { | PacketHandler.init(); |
Vazkii/Emotes | MODSRC/vazkii/emotes/common/CommonProxy.java | // Path: MODSRC/vazkii/emotes/common/network/PacketEmote.java
// public class PacketEmote implements IMessage, IMessageHandler<PacketEmote, IMessage> {
//
// public String emoteName;
// public String playerName;
//
// public PacketEmote() { }
//
// public PacketEmote(String name, String player) {
// this.emoteName = name;
// this.playerName = player;
// }
//
// @Override
// public void fromBytes(ByteBuf buffer) {
// PacketBuffer packet = new PacketBuffer(buffer);
// try {
// emoteName = packet.readStringFromBuffer(32);
// playerName = packet.readStringFromBuffer(32);
// } catch (IOException e) {
// e.printStackTrace();
// }
// }
//
// @Override
// public void toBytes(ByteBuf buffer) {
// PacketBuffer packet = new PacketBuffer(buffer);
// try {
// packet.writeStringToBuffer(emoteName);
// packet.writeStringToBuffer(playerName);
// } catch (IOException e) {
// e.printStackTrace();
// }
// }
//
// @Override
// public IMessage onMessage(PacketEmote message, MessageContext context) {
// Emotes.proxy.handlePacket(message);
// return null;
// }
//
// }
//
// Path: MODSRC/vazkii/emotes/common/network/PacketHandler.java
// public class PacketHandler {
//
// public static final SimpleNetworkWrapper INSTANCE = NetworkRegistry.INSTANCE.newSimpleChannel("vEmotes");
//
// public static void init() {
// INSTANCE.registerMessage(PacketEmote.class, PacketEmote.class, 0, Side.CLIENT);
// }
//
// }
| import vazkii.emotes.common.network.PacketEmote;
import vazkii.emotes.common.network.PacketHandler; | package vazkii.emotes.common;
public class CommonProxy {
public void init() {
PacketHandler.init();
}
| // Path: MODSRC/vazkii/emotes/common/network/PacketEmote.java
// public class PacketEmote implements IMessage, IMessageHandler<PacketEmote, IMessage> {
//
// public String emoteName;
// public String playerName;
//
// public PacketEmote() { }
//
// public PacketEmote(String name, String player) {
// this.emoteName = name;
// this.playerName = player;
// }
//
// @Override
// public void fromBytes(ByteBuf buffer) {
// PacketBuffer packet = new PacketBuffer(buffer);
// try {
// emoteName = packet.readStringFromBuffer(32);
// playerName = packet.readStringFromBuffer(32);
// } catch (IOException e) {
// e.printStackTrace();
// }
// }
//
// @Override
// public void toBytes(ByteBuf buffer) {
// PacketBuffer packet = new PacketBuffer(buffer);
// try {
// packet.writeStringToBuffer(emoteName);
// packet.writeStringToBuffer(playerName);
// } catch (IOException e) {
// e.printStackTrace();
// }
// }
//
// @Override
// public IMessage onMessage(PacketEmote message, MessageContext context) {
// Emotes.proxy.handlePacket(message);
// return null;
// }
//
// }
//
// Path: MODSRC/vazkii/emotes/common/network/PacketHandler.java
// public class PacketHandler {
//
// public static final SimpleNetworkWrapper INSTANCE = NetworkRegistry.INSTANCE.newSimpleChannel("vEmotes");
//
// public static void init() {
// INSTANCE.registerMessage(PacketEmote.class, PacketEmote.class, 0, Side.CLIENT);
// }
//
// }
// Path: MODSRC/vazkii/emotes/common/CommonProxy.java
import vazkii.emotes.common.network.PacketEmote;
import vazkii.emotes.common.network.PacketHandler;
package vazkii.emotes.common;
public class CommonProxy {
public void init() {
PacketHandler.init();
}
| public void handlePacket(PacketEmote message) { |
samskivert/pythagoras | src/main/java/pythagoras/d/Matrix3.java | // Path: src/gwt/java/pythagoras/util/Platform.java
// public class Platform
// {
// /**
// * Returns a hash code for the supplied float value.
// */
// public static int hashCode (float f1) {
// return (int)f1; // alas nothing better can be done in JavaScript
// }
//
// /**
// * Returns a hash code for the supplied double value.
// */
// public static int hashCode (double d1) {
// return (int)d1; // alas nothing better can be done in JavaScript
// }
//
// /**
// * Clones the supplied array of bytes.
// */
// public static native byte[] clone (byte[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of ints.
// */
// public static native int[] clone (int[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of floats.
// */
// public static native float[] clone (float[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of doubles.
// */
// public static native double[] clone (double[] values) /*-{
// return values.slice(0);
// }-*/;
// }
//
// Path: src/main/java/pythagoras/util/SingularMatrixException.java
// public class SingularMatrixException extends RuntimeException
// {
// private static final long serialVersionUID = -4744745375693073952L;
//
// /**
// * Creates a new exception.
// */
// public SingularMatrixException () {
// }
//
// /**
// * Creates a new exception with the provided message.
// */
// public SingularMatrixException (String message) {
// super(message);
// }
// }
| import pythagoras.util.Platform;
import pythagoras.util.SingularMatrixException;
import java.io.Serializable;
import java.nio.DoubleBuffer; |
@Override // from IMatrix3
public Matrix3 multAffine (IMatrix3 other, Matrix3 result) {
double m00 = this.m00, m01 = this.m01;
double m10 = this.m10, m11 = this.m11;
double m20 = this.m20, m21 = this.m21;
double om00 = other.m00(), om01 = other.m01();
double om10 = other.m10(), om11 = other.m11();
double om20 = other.m20(), om21 = other.m21();
return result.set(m00*om00 + m10*om01,
m00*om10 + m10*om11,
m00*om20 + m10*om21 + m20,
m01*om00 + m11*om01,
m01*om10 + m11*om11,
m01*om20 + m11*om21 + m21,
0f, 0f, 1f);
}
@Override // from IMatrix3
public Matrix3 invert () {
return invert(new Matrix3());
}
/**
* {@inheritDoc} This code is based on the examples in the
* <a href="http://www.j3d.org/matrix_faq/matrfaq_latest.html">Matrix and Quaternion FAQ</a>.
*/
@Override // from IMatrix3 | // Path: src/gwt/java/pythagoras/util/Platform.java
// public class Platform
// {
// /**
// * Returns a hash code for the supplied float value.
// */
// public static int hashCode (float f1) {
// return (int)f1; // alas nothing better can be done in JavaScript
// }
//
// /**
// * Returns a hash code for the supplied double value.
// */
// public static int hashCode (double d1) {
// return (int)d1; // alas nothing better can be done in JavaScript
// }
//
// /**
// * Clones the supplied array of bytes.
// */
// public static native byte[] clone (byte[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of ints.
// */
// public static native int[] clone (int[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of floats.
// */
// public static native float[] clone (float[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of doubles.
// */
// public static native double[] clone (double[] values) /*-{
// return values.slice(0);
// }-*/;
// }
//
// Path: src/main/java/pythagoras/util/SingularMatrixException.java
// public class SingularMatrixException extends RuntimeException
// {
// private static final long serialVersionUID = -4744745375693073952L;
//
// /**
// * Creates a new exception.
// */
// public SingularMatrixException () {
// }
//
// /**
// * Creates a new exception with the provided message.
// */
// public SingularMatrixException (String message) {
// super(message);
// }
// }
// Path: src/main/java/pythagoras/d/Matrix3.java
import pythagoras.util.Platform;
import pythagoras.util.SingularMatrixException;
import java.io.Serializable;
import java.nio.DoubleBuffer;
@Override // from IMatrix3
public Matrix3 multAffine (IMatrix3 other, Matrix3 result) {
double m00 = this.m00, m01 = this.m01;
double m10 = this.m10, m11 = this.m11;
double m20 = this.m20, m21 = this.m21;
double om00 = other.m00(), om01 = other.m01();
double om10 = other.m10(), om11 = other.m11();
double om20 = other.m20(), om21 = other.m21();
return result.set(m00*om00 + m10*om01,
m00*om10 + m10*om11,
m00*om20 + m10*om21 + m20,
m01*om00 + m11*om01,
m01*om10 + m11*om11,
m01*om20 + m11*om21 + m21,
0f, 0f, 1f);
}
@Override // from IMatrix3
public Matrix3 invert () {
return invert(new Matrix3());
}
/**
* {@inheritDoc} This code is based on the examples in the
* <a href="http://www.j3d.org/matrix_faq/matrfaq_latest.html">Matrix and Quaternion FAQ</a>.
*/
@Override // from IMatrix3 | public Matrix3 invert (Matrix3 result) throws SingularMatrixException { |
samskivert/pythagoras | src/main/java/pythagoras/d/Matrix3.java | // Path: src/gwt/java/pythagoras/util/Platform.java
// public class Platform
// {
// /**
// * Returns a hash code for the supplied float value.
// */
// public static int hashCode (float f1) {
// return (int)f1; // alas nothing better can be done in JavaScript
// }
//
// /**
// * Returns a hash code for the supplied double value.
// */
// public static int hashCode (double d1) {
// return (int)d1; // alas nothing better can be done in JavaScript
// }
//
// /**
// * Clones the supplied array of bytes.
// */
// public static native byte[] clone (byte[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of ints.
// */
// public static native int[] clone (int[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of floats.
// */
// public static native float[] clone (float[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of doubles.
// */
// public static native double[] clone (double[] values) /*-{
// return values.slice(0);
// }-*/;
// }
//
// Path: src/main/java/pythagoras/util/SingularMatrixException.java
// public class SingularMatrixException extends RuntimeException
// {
// private static final long serialVersionUID = -4744745375693073952L;
//
// /**
// * Creates a new exception.
// */
// public SingularMatrixException () {
// }
//
// /**
// * Creates a new exception with the provided message.
// */
// public SingularMatrixException (String message) {
// super(message);
// }
// }
| import pythagoras.util.Platform;
import pythagoras.util.SingularMatrixException;
import java.io.Serializable;
import java.nio.DoubleBuffer; | return Math.atan2(n01, n00);
}
@Override // from IMatrix3
public Vector extractScale () {
return extractScale(new Vector());
}
@Override // from IMatrix3
public Vector extractScale (Vector result) {
double m00 = this.m00, m01 = this.m01, m10 = this.m10, m11 = this.m11;
return result.set(Math.sqrt(m00*m00 + m01*m01),
Math.sqrt(m10*m10 + m11*m11));
}
@Override // from IMatrix3
public double approximateUniformScale () {
double cp = m00*m11 - m01*m10;
return (cp < 0f) ? -Math.sqrt(-cp) : Math.sqrt(cp);
}
@Override
public String toString () {
return ("[[" + m00 + ", " + m10 + ", " + m20 + "], " +
"[" + m01 + ", " + m11 + ", " + m21 + "], " +
"[" + m02 + ", " + m12 + ", " + m22 + "]]");
}
@Override
public int hashCode () { | // Path: src/gwt/java/pythagoras/util/Platform.java
// public class Platform
// {
// /**
// * Returns a hash code for the supplied float value.
// */
// public static int hashCode (float f1) {
// return (int)f1; // alas nothing better can be done in JavaScript
// }
//
// /**
// * Returns a hash code for the supplied double value.
// */
// public static int hashCode (double d1) {
// return (int)d1; // alas nothing better can be done in JavaScript
// }
//
// /**
// * Clones the supplied array of bytes.
// */
// public static native byte[] clone (byte[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of ints.
// */
// public static native int[] clone (int[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of floats.
// */
// public static native float[] clone (float[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of doubles.
// */
// public static native double[] clone (double[] values) /*-{
// return values.slice(0);
// }-*/;
// }
//
// Path: src/main/java/pythagoras/util/SingularMatrixException.java
// public class SingularMatrixException extends RuntimeException
// {
// private static final long serialVersionUID = -4744745375693073952L;
//
// /**
// * Creates a new exception.
// */
// public SingularMatrixException () {
// }
//
// /**
// * Creates a new exception with the provided message.
// */
// public SingularMatrixException (String message) {
// super(message);
// }
// }
// Path: src/main/java/pythagoras/d/Matrix3.java
import pythagoras.util.Platform;
import pythagoras.util.SingularMatrixException;
import java.io.Serializable;
import java.nio.DoubleBuffer;
return Math.atan2(n01, n00);
}
@Override // from IMatrix3
public Vector extractScale () {
return extractScale(new Vector());
}
@Override // from IMatrix3
public Vector extractScale (Vector result) {
double m00 = this.m00, m01 = this.m01, m10 = this.m10, m11 = this.m11;
return result.set(Math.sqrt(m00*m00 + m01*m01),
Math.sqrt(m10*m10 + m11*m11));
}
@Override // from IMatrix3
public double approximateUniformScale () {
double cp = m00*m11 - m01*m10;
return (cp < 0f) ? -Math.sqrt(-cp) : Math.sqrt(cp);
}
@Override
public String toString () {
return ("[[" + m00 + ", " + m10 + ", " + m20 + "], " +
"[" + m01 + ", " + m11 + ", " + m21 + "], " +
"[" + m02 + ", " + m12 + ", " + m22 + "]]");
}
@Override
public int hashCode () { | return Platform.hashCode(m00) ^ Platform.hashCode(m10) ^ Platform.hashCode(m20) ^ |
samskivert/pythagoras | src/main/java/pythagoras/f/AffineTransform.java | // Path: src/main/java/pythagoras/util/NoninvertibleTransformException.java
// public class NoninvertibleTransformException extends RuntimeException
// {
// private static final long serialVersionUID = 5208863644264280750L;
//
// public NoninvertibleTransformException (String s) {
// super(s);
// }
// }
| import pythagoras.util.NoninvertibleTransformException; | //
// Pythagoras - a collection of geometry classes
// http://github.com/samskivert/pythagoras
package pythagoras.f;
/**
* Implements an affine (3x2 matrix) transform. The transformation matrix has the form:
* <pre>{@code
* [ m00, m10, tx ]
* [ m01, m11, ty ]
* [ 0, 0, 1 ]
* }</pre>
*/
public class AffineTransform extends AbstractTransform
{
/** Identifies the affine transform in {@link #generality}. */
public static final int GENERALITY = 4;
/** The scale, rotation and shear components of this transform. */
public float m00, m01, m10, m11;
/** The translation components of this transform. */
public float tx, ty;
/** Creates an affine transform configured with the identity transform. */
public AffineTransform () {
this(1, 0, 0, 1, 0, 0);
}
/** Creates an affine transform from the supplied scale, rotation and translation. */
public AffineTransform (float scale, float angle, float tx, float ty) {
this(scale, scale, angle, tx, ty);
}
/** Creates an affine transform from the supplied scale, rotation and translation. */
public AffineTransform (float scaleX, float scaleY, float angle, float tx, float ty) {
float sina = FloatMath.sin(angle), cosa = FloatMath.cos(angle);
this.m00 = cosa * scaleX; this.m01 = sina * scaleY;
this.m10 = -sina * scaleX; this.m11 = cosa * scaleY;
this.tx = tx; this.ty = ty;
}
/** Creates an affine transform with the specified transform matrix. */
public AffineTransform (float m00, float m01, float m10, float m11, float tx, float ty) {
this.m00 = m00; this.m01 = m01;
this.m10 = m10; this.m11 = m11;
this.tx = tx; this.ty = ty;
}
/** Sets this affine transform matrix to {@code other}.
* @return this instance, for chaining. */
public AffineTransform set (AffineTransform other) {
return setTransform(other.m00, other.m01, other.m10, other.m11, other.tx, other.ty);
}
@Override // from Transform
public float uniformScale () {
// the square root of the signed area of the parallelogram spanned by the axis vectors
float cp = m00*m11 - m01*m10;
return (cp < 0f) ? -FloatMath.sqrt(-cp) : FloatMath.sqrt(cp);
}
@Override // from Transform
public float scaleX () {
return FloatMath.sqrt(m00*m00 + m01*m01);
}
@Override // from Transform
public float scaleY () {
return FloatMath.sqrt(m10*m10 + m11*m11);
}
@Override // from Transform
public float rotation () {
// use the iterative polar decomposition algorithm described by Ken Shoemake:
// http://www.cs.wisc.edu/graphics/Courses/838-s2002/Papers/polar-decomp.pdf
// start with the contents of the upper 2x2 portion of the matrix
float n00 = m00, n10 = m10;
float n01 = m01, n11 = m11;
for (int ii = 0; ii < 10; ii++) {
// store the results of the previous iteration
float o00 = n00, o10 = n10;
float o01 = n01, o11 = n11;
// compute average of the matrix with its inverse transpose
float det = o00*o11 - o10*o01;
if (Math.abs(det) == 0f) {
// determinant is zero; matrix is not invertible | // Path: src/main/java/pythagoras/util/NoninvertibleTransformException.java
// public class NoninvertibleTransformException extends RuntimeException
// {
// private static final long serialVersionUID = 5208863644264280750L;
//
// public NoninvertibleTransformException (String s) {
// super(s);
// }
// }
// Path: src/main/java/pythagoras/f/AffineTransform.java
import pythagoras.util.NoninvertibleTransformException;
//
// Pythagoras - a collection of geometry classes
// http://github.com/samskivert/pythagoras
package pythagoras.f;
/**
* Implements an affine (3x2 matrix) transform. The transformation matrix has the form:
* <pre>{@code
* [ m00, m10, tx ]
* [ m01, m11, ty ]
* [ 0, 0, 1 ]
* }</pre>
*/
public class AffineTransform extends AbstractTransform
{
/** Identifies the affine transform in {@link #generality}. */
public static final int GENERALITY = 4;
/** The scale, rotation and shear components of this transform. */
public float m00, m01, m10, m11;
/** The translation components of this transform. */
public float tx, ty;
/** Creates an affine transform configured with the identity transform. */
public AffineTransform () {
this(1, 0, 0, 1, 0, 0);
}
/** Creates an affine transform from the supplied scale, rotation and translation. */
public AffineTransform (float scale, float angle, float tx, float ty) {
this(scale, scale, angle, tx, ty);
}
/** Creates an affine transform from the supplied scale, rotation and translation. */
public AffineTransform (float scaleX, float scaleY, float angle, float tx, float ty) {
float sina = FloatMath.sin(angle), cosa = FloatMath.cos(angle);
this.m00 = cosa * scaleX; this.m01 = sina * scaleY;
this.m10 = -sina * scaleX; this.m11 = cosa * scaleY;
this.tx = tx; this.ty = ty;
}
/** Creates an affine transform with the specified transform matrix. */
public AffineTransform (float m00, float m01, float m10, float m11, float tx, float ty) {
this.m00 = m00; this.m01 = m01;
this.m10 = m10; this.m11 = m11;
this.tx = tx; this.ty = ty;
}
/** Sets this affine transform matrix to {@code other}.
* @return this instance, for chaining. */
public AffineTransform set (AffineTransform other) {
return setTransform(other.m00, other.m01, other.m10, other.m11, other.tx, other.ty);
}
@Override // from Transform
public float uniformScale () {
// the square root of the signed area of the parallelogram spanned by the axis vectors
float cp = m00*m11 - m01*m10;
return (cp < 0f) ? -FloatMath.sqrt(-cp) : FloatMath.sqrt(cp);
}
@Override // from Transform
public float scaleX () {
return FloatMath.sqrt(m00*m00 + m01*m01);
}
@Override // from Transform
public float scaleY () {
return FloatMath.sqrt(m10*m10 + m11*m11);
}
@Override // from Transform
public float rotation () {
// use the iterative polar decomposition algorithm described by Ken Shoemake:
// http://www.cs.wisc.edu/graphics/Courses/838-s2002/Papers/polar-decomp.pdf
// start with the contents of the upper 2x2 portion of the matrix
float n00 = m00, n10 = m10;
float n01 = m01, n11 = m11;
for (int ii = 0; ii < 10; ii++) {
// store the results of the previous iteration
float o00 = n00, o10 = n10;
float o01 = n01, o11 = n11;
// compute average of the matrix with its inverse transpose
float det = o00*o11 - o10*o01;
if (Math.abs(det) == 0f) {
// determinant is zero; matrix is not invertible | throw new NoninvertibleTransformException(this.toString()); |
samskivert/pythagoras | src/main/java/pythagoras/f/Matrix3.java | // Path: src/gwt/java/pythagoras/util/Platform.java
// public class Platform
// {
// /**
// * Returns a hash code for the supplied float value.
// */
// public static int hashCode (float f1) {
// return (int)f1; // alas nothing better can be done in JavaScript
// }
//
// /**
// * Returns a hash code for the supplied double value.
// */
// public static int hashCode (double d1) {
// return (int)d1; // alas nothing better can be done in JavaScript
// }
//
// /**
// * Clones the supplied array of bytes.
// */
// public static native byte[] clone (byte[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of ints.
// */
// public static native int[] clone (int[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of floats.
// */
// public static native float[] clone (float[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of doubles.
// */
// public static native double[] clone (double[] values) /*-{
// return values.slice(0);
// }-*/;
// }
//
// Path: src/main/java/pythagoras/util/SingularMatrixException.java
// public class SingularMatrixException extends RuntimeException
// {
// private static final long serialVersionUID = -4744745375693073952L;
//
// /**
// * Creates a new exception.
// */
// public SingularMatrixException () {
// }
//
// /**
// * Creates a new exception with the provided message.
// */
// public SingularMatrixException (String message) {
// super(message);
// }
// }
| import pythagoras.util.Platform;
import pythagoras.util.SingularMatrixException;
import java.io.Serializable;
import java.nio.FloatBuffer; |
@Override // from IMatrix3
public Matrix3 multAffine (IMatrix3 other, Matrix3 result) {
float m00 = this.m00, m01 = this.m01;
float m10 = this.m10, m11 = this.m11;
float m20 = this.m20, m21 = this.m21;
float om00 = other.m00(), om01 = other.m01();
float om10 = other.m10(), om11 = other.m11();
float om20 = other.m20(), om21 = other.m21();
return result.set(m00*om00 + m10*om01,
m00*om10 + m10*om11,
m00*om20 + m10*om21 + m20,
m01*om00 + m11*om01,
m01*om10 + m11*om11,
m01*om20 + m11*om21 + m21,
0f, 0f, 1f);
}
@Override // from IMatrix3
public Matrix3 invert () {
return invert(new Matrix3());
}
/**
* {@inheritDoc} This code is based on the examples in the
* <a href="http://www.j3d.org/matrix_faq/matrfaq_latest.html">Matrix and Quaternion FAQ</a>.
*/
@Override // from IMatrix3 | // Path: src/gwt/java/pythagoras/util/Platform.java
// public class Platform
// {
// /**
// * Returns a hash code for the supplied float value.
// */
// public static int hashCode (float f1) {
// return (int)f1; // alas nothing better can be done in JavaScript
// }
//
// /**
// * Returns a hash code for the supplied double value.
// */
// public static int hashCode (double d1) {
// return (int)d1; // alas nothing better can be done in JavaScript
// }
//
// /**
// * Clones the supplied array of bytes.
// */
// public static native byte[] clone (byte[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of ints.
// */
// public static native int[] clone (int[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of floats.
// */
// public static native float[] clone (float[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of doubles.
// */
// public static native double[] clone (double[] values) /*-{
// return values.slice(0);
// }-*/;
// }
//
// Path: src/main/java/pythagoras/util/SingularMatrixException.java
// public class SingularMatrixException extends RuntimeException
// {
// private static final long serialVersionUID = -4744745375693073952L;
//
// /**
// * Creates a new exception.
// */
// public SingularMatrixException () {
// }
//
// /**
// * Creates a new exception with the provided message.
// */
// public SingularMatrixException (String message) {
// super(message);
// }
// }
// Path: src/main/java/pythagoras/f/Matrix3.java
import pythagoras.util.Platform;
import pythagoras.util.SingularMatrixException;
import java.io.Serializable;
import java.nio.FloatBuffer;
@Override // from IMatrix3
public Matrix3 multAffine (IMatrix3 other, Matrix3 result) {
float m00 = this.m00, m01 = this.m01;
float m10 = this.m10, m11 = this.m11;
float m20 = this.m20, m21 = this.m21;
float om00 = other.m00(), om01 = other.m01();
float om10 = other.m10(), om11 = other.m11();
float om20 = other.m20(), om21 = other.m21();
return result.set(m00*om00 + m10*om01,
m00*om10 + m10*om11,
m00*om20 + m10*om21 + m20,
m01*om00 + m11*om01,
m01*om10 + m11*om11,
m01*om20 + m11*om21 + m21,
0f, 0f, 1f);
}
@Override // from IMatrix3
public Matrix3 invert () {
return invert(new Matrix3());
}
/**
* {@inheritDoc} This code is based on the examples in the
* <a href="http://www.j3d.org/matrix_faq/matrfaq_latest.html">Matrix and Quaternion FAQ</a>.
*/
@Override // from IMatrix3 | public Matrix3 invert (Matrix3 result) throws SingularMatrixException { |
samskivert/pythagoras | src/main/java/pythagoras/f/Matrix3.java | // Path: src/gwt/java/pythagoras/util/Platform.java
// public class Platform
// {
// /**
// * Returns a hash code for the supplied float value.
// */
// public static int hashCode (float f1) {
// return (int)f1; // alas nothing better can be done in JavaScript
// }
//
// /**
// * Returns a hash code for the supplied double value.
// */
// public static int hashCode (double d1) {
// return (int)d1; // alas nothing better can be done in JavaScript
// }
//
// /**
// * Clones the supplied array of bytes.
// */
// public static native byte[] clone (byte[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of ints.
// */
// public static native int[] clone (int[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of floats.
// */
// public static native float[] clone (float[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of doubles.
// */
// public static native double[] clone (double[] values) /*-{
// return values.slice(0);
// }-*/;
// }
//
// Path: src/main/java/pythagoras/util/SingularMatrixException.java
// public class SingularMatrixException extends RuntimeException
// {
// private static final long serialVersionUID = -4744745375693073952L;
//
// /**
// * Creates a new exception.
// */
// public SingularMatrixException () {
// }
//
// /**
// * Creates a new exception with the provided message.
// */
// public SingularMatrixException (String message) {
// super(message);
// }
// }
| import pythagoras.util.Platform;
import pythagoras.util.SingularMatrixException;
import java.io.Serializable;
import java.nio.FloatBuffer; | return FloatMath.atan2(n01, n00);
}
@Override // from IMatrix3
public Vector extractScale () {
return extractScale(new Vector());
}
@Override // from IMatrix3
public Vector extractScale (Vector result) {
float m00 = this.m00, m01 = this.m01, m10 = this.m10, m11 = this.m11;
return result.set(FloatMath.sqrt(m00*m00 + m01*m01),
FloatMath.sqrt(m10*m10 + m11*m11));
}
@Override // from IMatrix3
public float approximateUniformScale () {
float cp = m00*m11 - m01*m10;
return (cp < 0f) ? -FloatMath.sqrt(-cp) : FloatMath.sqrt(cp);
}
@Override
public String toString () {
return ("[[" + m00 + ", " + m10 + ", " + m20 + "], " +
"[" + m01 + ", " + m11 + ", " + m21 + "], " +
"[" + m02 + ", " + m12 + ", " + m22 + "]]");
}
@Override
public int hashCode () { | // Path: src/gwt/java/pythagoras/util/Platform.java
// public class Platform
// {
// /**
// * Returns a hash code for the supplied float value.
// */
// public static int hashCode (float f1) {
// return (int)f1; // alas nothing better can be done in JavaScript
// }
//
// /**
// * Returns a hash code for the supplied double value.
// */
// public static int hashCode (double d1) {
// return (int)d1; // alas nothing better can be done in JavaScript
// }
//
// /**
// * Clones the supplied array of bytes.
// */
// public static native byte[] clone (byte[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of ints.
// */
// public static native int[] clone (int[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of floats.
// */
// public static native float[] clone (float[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of doubles.
// */
// public static native double[] clone (double[] values) /*-{
// return values.slice(0);
// }-*/;
// }
//
// Path: src/main/java/pythagoras/util/SingularMatrixException.java
// public class SingularMatrixException extends RuntimeException
// {
// private static final long serialVersionUID = -4744745375693073952L;
//
// /**
// * Creates a new exception.
// */
// public SingularMatrixException () {
// }
//
// /**
// * Creates a new exception with the provided message.
// */
// public SingularMatrixException (String message) {
// super(message);
// }
// }
// Path: src/main/java/pythagoras/f/Matrix3.java
import pythagoras.util.Platform;
import pythagoras.util.SingularMatrixException;
import java.io.Serializable;
import java.nio.FloatBuffer;
return FloatMath.atan2(n01, n00);
}
@Override // from IMatrix3
public Vector extractScale () {
return extractScale(new Vector());
}
@Override // from IMatrix3
public Vector extractScale (Vector result) {
float m00 = this.m00, m01 = this.m01, m10 = this.m10, m11 = this.m11;
return result.set(FloatMath.sqrt(m00*m00 + m01*m01),
FloatMath.sqrt(m10*m10 + m11*m11));
}
@Override // from IMatrix3
public float approximateUniformScale () {
float cp = m00*m11 - m01*m10;
return (cp < 0f) ? -FloatMath.sqrt(-cp) : FloatMath.sqrt(cp);
}
@Override
public String toString () {
return ("[[" + m00 + ", " + m10 + ", " + m20 + "], " +
"[" + m01 + ", " + m11 + ", " + m21 + "], " +
"[" + m02 + ", " + m12 + ", " + m22 + "]]");
}
@Override
public int hashCode () { | return Platform.hashCode(m00) ^ Platform.hashCode(m10) ^ Platform.hashCode(m20) ^ |
samskivert/pythagoras | src/main/java/pythagoras/f/Vector4.java | // Path: src/gwt/java/pythagoras/util/Platform.java
// public class Platform
// {
// /**
// * Returns a hash code for the supplied float value.
// */
// public static int hashCode (float f1) {
// return (int)f1; // alas nothing better can be done in JavaScript
// }
//
// /**
// * Returns a hash code for the supplied double value.
// */
// public static int hashCode (double d1) {
// return (int)d1; // alas nothing better can be done in JavaScript
// }
//
// /**
// * Clones the supplied array of bytes.
// */
// public static native byte[] clone (byte[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of ints.
// */
// public static native int[] clone (int[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of floats.
// */
// public static native float[] clone (float[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of doubles.
// */
// public static native double[] clone (double[] values) /*-{
// return values.slice(0);
// }-*/;
// }
| import pythagoras.util.Platform;
import java.io.Serializable;
import java.nio.FloatBuffer; | @Override // from interface IVector4
public Vector4 mult (float v, Vector4 result) {
return result.set(x*v, y*v, z*v, w*v);
}
@Override // from IVector4
public Vector4 mult (IMatrix4 matrix) {
return mult(matrix, new Vector4());
}
@Override // from IVector4
public Vector4 mult (IMatrix4 matrix, Vector4 result) {
float m00 = matrix.m00(), m10 = matrix.m10(), m20 = matrix.m20(), m30 = matrix.m30();
float m01 = matrix.m01(), m11 = matrix.m11(), m21 = matrix.m21(), m31 = matrix.m31();
float m02 = matrix.m02(), m12 = matrix.m12(), m22 = matrix.m22(), m32 = matrix.m32();
float m03 = matrix.m03(), m13 = matrix.m13(), m23 = matrix.m23(), m33 = matrix.m33();
float vx = x, vy = y, vz = z, vw = w;
return result.set(m00*vx + m01*vy + m02*vz + m03*vw,
m10*vx + m11*vy + m12*vz + m13*vw,
m20*vx + m21*vy + m22*vz + m23*vw,
m30*vx + m31*vy + m32*vz + m33*vw);
}
@Override
public String toString () {
return "[" + x + ", " + y + ", " + z + ", " + w + "]";
}
@Override
public int hashCode () { | // Path: src/gwt/java/pythagoras/util/Platform.java
// public class Platform
// {
// /**
// * Returns a hash code for the supplied float value.
// */
// public static int hashCode (float f1) {
// return (int)f1; // alas nothing better can be done in JavaScript
// }
//
// /**
// * Returns a hash code for the supplied double value.
// */
// public static int hashCode (double d1) {
// return (int)d1; // alas nothing better can be done in JavaScript
// }
//
// /**
// * Clones the supplied array of bytes.
// */
// public static native byte[] clone (byte[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of ints.
// */
// public static native int[] clone (int[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of floats.
// */
// public static native float[] clone (float[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of doubles.
// */
// public static native double[] clone (double[] values) /*-{
// return values.slice(0);
// }-*/;
// }
// Path: src/main/java/pythagoras/f/Vector4.java
import pythagoras.util.Platform;
import java.io.Serializable;
import java.nio.FloatBuffer;
@Override // from interface IVector4
public Vector4 mult (float v, Vector4 result) {
return result.set(x*v, y*v, z*v, w*v);
}
@Override // from IVector4
public Vector4 mult (IMatrix4 matrix) {
return mult(matrix, new Vector4());
}
@Override // from IVector4
public Vector4 mult (IMatrix4 matrix, Vector4 result) {
float m00 = matrix.m00(), m10 = matrix.m10(), m20 = matrix.m20(), m30 = matrix.m30();
float m01 = matrix.m01(), m11 = matrix.m11(), m21 = matrix.m21(), m31 = matrix.m31();
float m02 = matrix.m02(), m12 = matrix.m12(), m22 = matrix.m22(), m32 = matrix.m32();
float m03 = matrix.m03(), m13 = matrix.m13(), m23 = matrix.m23(), m33 = matrix.m33();
float vx = x, vy = y, vz = z, vw = w;
return result.set(m00*vx + m01*vy + m02*vz + m03*vw,
m10*vx + m11*vy + m12*vz + m13*vw,
m20*vx + m21*vy + m22*vz + m23*vw,
m30*vx + m31*vy + m32*vz + m33*vw);
}
@Override
public String toString () {
return "[" + x + ", " + y + ", " + z + ", " + w + "]";
}
@Override
public int hashCode () { | return Platform.hashCode(x) ^ Platform.hashCode(y) ^ Platform.hashCode(z) ^ |
samskivert/pythagoras | src/main/java/pythagoras/f/Area.java | // Path: src/gwt/java/pythagoras/util/Platform.java
// public class Platform
// {
// /**
// * Returns a hash code for the supplied float value.
// */
// public static int hashCode (float f1) {
// return (int)f1; // alas nothing better can be done in JavaScript
// }
//
// /**
// * Returns a hash code for the supplied double value.
// */
// public static int hashCode (double d1) {
// return (int)d1; // alas nothing better can be done in JavaScript
// }
//
// /**
// * Clones the supplied array of bytes.
// */
// public static native byte[] clone (byte[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of ints.
// */
// public static native int[] clone (int[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of floats.
// */
// public static native float[] clone (float[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of doubles.
// */
// public static native double[] clone (double[] values) /*-{
// return values.slice(0);
// }-*/;
// }
| import pythagoras.util.Platform;
import java.util.NoSuchElementException; | coefs = new float[] { coords[index - 2], coords[index - 1], coords[index],
coords[index + 1], coords[index + 2], coords[index + 3],
coords[index + 4], coords[index + 5] };
isLeft = CrossingHelper.compare(
coords[index - 2], coords[index - 1], point.x(), point.y()) > 0;
GeometryUtil.subCubic(coefs, point.param(isCurrentArea), !isLeft);
if (isLeft) {
System.arraycopy(coefs, 2, temp, coordsCount, 6);
coordsCount += 6;
} else {
System.arraycopy(coefs, 2, temp, coordsCount, 4);
coordsCount += 4;
}
break;
}
}
if (operation == 2 && !isCurrentArea && coordsCount > 2) {
reverseCopy(temp);
System.arraycopy(temp, 0, resultCoords, resultCoordPos, coordsCount);
} else {
System.arraycopy(temp, 0, resultCoords, resultCoordPos, coordsCount);
}
return (resultCoordPos + coordsCount);
}
private void copy (Area src, Area dst) {
dst._coordsSize = src._coordsSize; | // Path: src/gwt/java/pythagoras/util/Platform.java
// public class Platform
// {
// /**
// * Returns a hash code for the supplied float value.
// */
// public static int hashCode (float f1) {
// return (int)f1; // alas nothing better can be done in JavaScript
// }
//
// /**
// * Returns a hash code for the supplied double value.
// */
// public static int hashCode (double d1) {
// return (int)d1; // alas nothing better can be done in JavaScript
// }
//
// /**
// * Clones the supplied array of bytes.
// */
// public static native byte[] clone (byte[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of ints.
// */
// public static native int[] clone (int[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of floats.
// */
// public static native float[] clone (float[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of doubles.
// */
// public static native double[] clone (double[] values) /*-{
// return values.slice(0);
// }-*/;
// }
// Path: src/main/java/pythagoras/f/Area.java
import pythagoras.util.Platform;
import java.util.NoSuchElementException;
coefs = new float[] { coords[index - 2], coords[index - 1], coords[index],
coords[index + 1], coords[index + 2], coords[index + 3],
coords[index + 4], coords[index + 5] };
isLeft = CrossingHelper.compare(
coords[index - 2], coords[index - 1], point.x(), point.y()) > 0;
GeometryUtil.subCubic(coefs, point.param(isCurrentArea), !isLeft);
if (isLeft) {
System.arraycopy(coefs, 2, temp, coordsCount, 6);
coordsCount += 6;
} else {
System.arraycopy(coefs, 2, temp, coordsCount, 4);
coordsCount += 4;
}
break;
}
}
if (operation == 2 && !isCurrentArea && coordsCount > 2) {
reverseCopy(temp);
System.arraycopy(temp, 0, resultCoords, resultCoordPos, coordsCount);
} else {
System.arraycopy(temp, 0, resultCoords, resultCoordPos, coordsCount);
}
return (resultCoordPos + coordsCount);
}
private void copy (Area src, Area dst) {
dst._coordsSize = src._coordsSize; | dst._coords = Platform.clone(src._coords); |
samskivert/pythagoras | src/main/java/pythagoras/f/Quaternion.java | // Path: src/gwt/java/pythagoras/util/Platform.java
// public class Platform
// {
// /**
// * Returns a hash code for the supplied float value.
// */
// public static int hashCode (float f1) {
// return (int)f1; // alas nothing better can be done in JavaScript
// }
//
// /**
// * Returns a hash code for the supplied double value.
// */
// public static int hashCode (double d1) {
// return (int)d1; // alas nothing better can be done in JavaScript
// }
//
// /**
// * Clones the supplied array of bytes.
// */
// public static native byte[] clone (byte[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of ints.
// */
// public static native int[] clone (int[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of floats.
// */
// public static native float[] clone (float[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of doubles.
// */
// public static native double[] clone (double[] values) /*-{
// return values.slice(0);
// }-*/;
// }
| import pythagoras.util.Platform;
import java.io.Serializable;
import java.util.Random; |
@Override // from IQuaternion
public float getRotationZ () {
return FloatMath.atan2(2f*(x*y + z*w), 1f - 2f*(y*y + z*z));
}
@Override // from IQuaternion
public Quaternion integrate (IVector3 velocity, float t) {
return integrate(velocity, t, new Quaternion());
}
@Override // from IQuaternion
public Quaternion integrate (IVector3 velocity, float t, Quaternion result) {
// TODO: use Runge-Kutta integration?
float qx = 0.5f * velocity.x();
float qy = 0.5f * velocity.y();
float qz = 0.5f * velocity.z();
return result.set(x + t*(qx*w + qy*z - qz*y),
y + t*(qy*w + qz*x - qx*z),
z + t*(qz*w + qx*y - qy*x),
w + t*(-qx*x - qy*y - qz*z)).normalizeLocal();
}
@Override // documentation inherited
public String toString () {
return "[" + x + ", " + y + ", " + z + ", " + w + "]";
}
@Override // documentation inherited
public int hashCode () { | // Path: src/gwt/java/pythagoras/util/Platform.java
// public class Platform
// {
// /**
// * Returns a hash code for the supplied float value.
// */
// public static int hashCode (float f1) {
// return (int)f1; // alas nothing better can be done in JavaScript
// }
//
// /**
// * Returns a hash code for the supplied double value.
// */
// public static int hashCode (double d1) {
// return (int)d1; // alas nothing better can be done in JavaScript
// }
//
// /**
// * Clones the supplied array of bytes.
// */
// public static native byte[] clone (byte[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of ints.
// */
// public static native int[] clone (int[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of floats.
// */
// public static native float[] clone (float[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of doubles.
// */
// public static native double[] clone (double[] values) /*-{
// return values.slice(0);
// }-*/;
// }
// Path: src/main/java/pythagoras/f/Quaternion.java
import pythagoras.util.Platform;
import java.io.Serializable;
import java.util.Random;
@Override // from IQuaternion
public float getRotationZ () {
return FloatMath.atan2(2f*(x*y + z*w), 1f - 2f*(y*y + z*z));
}
@Override // from IQuaternion
public Quaternion integrate (IVector3 velocity, float t) {
return integrate(velocity, t, new Quaternion());
}
@Override // from IQuaternion
public Quaternion integrate (IVector3 velocity, float t, Quaternion result) {
// TODO: use Runge-Kutta integration?
float qx = 0.5f * velocity.x();
float qy = 0.5f * velocity.y();
float qz = 0.5f * velocity.z();
return result.set(x + t*(qx*w + qy*z - qz*y),
y + t*(qy*w + qz*x - qx*z),
z + t*(qz*w + qx*y - qy*x),
w + t*(-qx*x - qy*y - qz*z)).normalizeLocal();
}
@Override // documentation inherited
public String toString () {
return "[" + x + ", " + y + ", " + z + ", " + w + "]";
}
@Override // documentation inherited
public int hashCode () { | return Platform.hashCode(x) ^ Platform.hashCode(y) ^ Platform.hashCode(z) ^ |
samskivert/pythagoras | src/main/java/pythagoras/d/AbstractCircle.java | // Path: src/gwt/java/pythagoras/util/Platform.java
// public class Platform
// {
// /**
// * Returns a hash code for the supplied float value.
// */
// public static int hashCode (float f1) {
// return (int)f1; // alas nothing better can be done in JavaScript
// }
//
// /**
// * Returns a hash code for the supplied double value.
// */
// public static int hashCode (double d1) {
// return (int)d1; // alas nothing better can be done in JavaScript
// }
//
// /**
// * Clones the supplied array of bytes.
// */
// public static native byte[] clone (byte[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of ints.
// */
// public static native int[] clone (int[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of floats.
// */
// public static native float[] clone (float[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of doubles.
// */
// public static native double[] clone (double[] values) /*-{
// return values.slice(0);
// }-*/;
// }
| import pythagoras.util.Platform; | @Override // from ICircle
public Circle offset (double x, double y) {
return new Circle(x() + x, y() + y, radius());
}
@Override // from ICircle
public Circle offset (double x, double y, Circle result) {
result.set(x() + x, y() + y, radius());
return result;
}
@Override // from ICircle
public Circle clone () {
return new Circle(this);
}
@Override
public boolean equals (Object obj) {
if (obj == this) {
return true;
}
if (obj instanceof AbstractCircle) {
AbstractCircle c = (AbstractCircle)obj;
return x() == c.x() && y() == c.y() && radius() == c.radius();
}
return false;
}
@Override
public int hashCode () { | // Path: src/gwt/java/pythagoras/util/Platform.java
// public class Platform
// {
// /**
// * Returns a hash code for the supplied float value.
// */
// public static int hashCode (float f1) {
// return (int)f1; // alas nothing better can be done in JavaScript
// }
//
// /**
// * Returns a hash code for the supplied double value.
// */
// public static int hashCode (double d1) {
// return (int)d1; // alas nothing better can be done in JavaScript
// }
//
// /**
// * Clones the supplied array of bytes.
// */
// public static native byte[] clone (byte[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of ints.
// */
// public static native int[] clone (int[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of floats.
// */
// public static native float[] clone (float[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of doubles.
// */
// public static native double[] clone (double[] values) /*-{
// return values.slice(0);
// }-*/;
// }
// Path: src/main/java/pythagoras/d/AbstractCircle.java
import pythagoras.util.Platform;
@Override // from ICircle
public Circle offset (double x, double y) {
return new Circle(x() + x, y() + y, radius());
}
@Override // from ICircle
public Circle offset (double x, double y, Circle result) {
result.set(x() + x, y() + y, radius());
return result;
}
@Override // from ICircle
public Circle clone () {
return new Circle(this);
}
@Override
public boolean equals (Object obj) {
if (obj == this) {
return true;
}
if (obj instanceof AbstractCircle) {
AbstractCircle c = (AbstractCircle)obj;
return x() == c.x() && y() == c.y() && radius() == c.radius();
}
return false;
}
@Override
public int hashCode () { | return Platform.hashCode(x()) ^ Platform.hashCode(y()) ^ Platform.hashCode(radius()); |
samskivert/pythagoras | src/main/java/pythagoras/d/Quaternion.java | // Path: src/gwt/java/pythagoras/util/Platform.java
// public class Platform
// {
// /**
// * Returns a hash code for the supplied float value.
// */
// public static int hashCode (float f1) {
// return (int)f1; // alas nothing better can be done in JavaScript
// }
//
// /**
// * Returns a hash code for the supplied double value.
// */
// public static int hashCode (double d1) {
// return (int)d1; // alas nothing better can be done in JavaScript
// }
//
// /**
// * Clones the supplied array of bytes.
// */
// public static native byte[] clone (byte[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of ints.
// */
// public static native int[] clone (int[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of floats.
// */
// public static native float[] clone (float[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of doubles.
// */
// public static native double[] clone (double[] values) /*-{
// return values.slice(0);
// }-*/;
// }
| import pythagoras.util.Platform;
import java.io.Serializable;
import java.util.Random; |
@Override // from IQuaternion
public double getRotationZ () {
return Math.atan2(2f*(x*y + z*w), 1f - 2f*(y*y + z*z));
}
@Override // from IQuaternion
public Quaternion integrate (IVector3 velocity, double t) {
return integrate(velocity, t, new Quaternion());
}
@Override // from IQuaternion
public Quaternion integrate (IVector3 velocity, double t, Quaternion result) {
// TODO: use Runge-Kutta integration?
double qx = 0.5f * velocity.x();
double qy = 0.5f * velocity.y();
double qz = 0.5f * velocity.z();
return result.set(x + t*(qx*w + qy*z - qz*y),
y + t*(qy*w + qz*x - qx*z),
z + t*(qz*w + qx*y - qy*x),
w + t*(-qx*x - qy*y - qz*z)).normalizeLocal();
}
@Override // documentation inherited
public String toString () {
return "[" + x + ", " + y + ", " + z + ", " + w + "]";
}
@Override // documentation inherited
public int hashCode () { | // Path: src/gwt/java/pythagoras/util/Platform.java
// public class Platform
// {
// /**
// * Returns a hash code for the supplied float value.
// */
// public static int hashCode (float f1) {
// return (int)f1; // alas nothing better can be done in JavaScript
// }
//
// /**
// * Returns a hash code for the supplied double value.
// */
// public static int hashCode (double d1) {
// return (int)d1; // alas nothing better can be done in JavaScript
// }
//
// /**
// * Clones the supplied array of bytes.
// */
// public static native byte[] clone (byte[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of ints.
// */
// public static native int[] clone (int[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of floats.
// */
// public static native float[] clone (float[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of doubles.
// */
// public static native double[] clone (double[] values) /*-{
// return values.slice(0);
// }-*/;
// }
// Path: src/main/java/pythagoras/d/Quaternion.java
import pythagoras.util.Platform;
import java.io.Serializable;
import java.util.Random;
@Override // from IQuaternion
public double getRotationZ () {
return Math.atan2(2f*(x*y + z*w), 1f - 2f*(y*y + z*z));
}
@Override // from IQuaternion
public Quaternion integrate (IVector3 velocity, double t) {
return integrate(velocity, t, new Quaternion());
}
@Override // from IQuaternion
public Quaternion integrate (IVector3 velocity, double t, Quaternion result) {
// TODO: use Runge-Kutta integration?
double qx = 0.5f * velocity.x();
double qy = 0.5f * velocity.y();
double qz = 0.5f * velocity.z();
return result.set(x + t*(qx*w + qy*z - qz*y),
y + t*(qy*w + qz*x - qx*z),
z + t*(qz*w + qx*y - qy*x),
w + t*(-qx*x - qy*y - qz*z)).normalizeLocal();
}
@Override // documentation inherited
public String toString () {
return "[" + x + ", " + y + ", " + z + ", " + w + "]";
}
@Override // documentation inherited
public int hashCode () { | return Platform.hashCode(x) ^ Platform.hashCode(y) ^ Platform.hashCode(z) ^ |
samskivert/pythagoras | src/main/java/pythagoras/f/AbstractPoint.java | // Path: src/gwt/java/pythagoras/util/Platform.java
// public class Platform
// {
// /**
// * Returns a hash code for the supplied float value.
// */
// public static int hashCode (float f1) {
// return (int)f1; // alas nothing better can be done in JavaScript
// }
//
// /**
// * Returns a hash code for the supplied double value.
// */
// public static int hashCode (double d1) {
// return (int)d1; // alas nothing better can be done in JavaScript
// }
//
// /**
// * Clones the supplied array of bytes.
// */
// public static native byte[] clone (byte[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of ints.
// */
// public static native int[] clone (int[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of floats.
// */
// public static native float[] clone (float[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of doubles.
// */
// public static native double[] clone (double[] values) /*-{
// return values.slice(0);
// }-*/;
// }
| import pythagoras.util.Platform; | public Point rotate (float angle) {
return rotate(angle, new Point());
}
@Override // from IPoint
public Point rotate (float angle, Point result) {
float x = x(), y = y();
float sina = FloatMath.sin(angle), cosa = FloatMath.cos(angle);
return result.set(x*cosa - y*sina, x*sina + y*cosa);
}
@Override // from IPoint
public Point clone () {
return new Point(this);
}
@Override
public boolean equals (Object obj) {
if (obj == this) {
return true;
}
if (obj instanceof AbstractPoint) {
AbstractPoint p = (AbstractPoint)obj;
return x() == p.x() && y() == p.y();
}
return false;
}
@Override
public int hashCode () { | // Path: src/gwt/java/pythagoras/util/Platform.java
// public class Platform
// {
// /**
// * Returns a hash code for the supplied float value.
// */
// public static int hashCode (float f1) {
// return (int)f1; // alas nothing better can be done in JavaScript
// }
//
// /**
// * Returns a hash code for the supplied double value.
// */
// public static int hashCode (double d1) {
// return (int)d1; // alas nothing better can be done in JavaScript
// }
//
// /**
// * Clones the supplied array of bytes.
// */
// public static native byte[] clone (byte[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of ints.
// */
// public static native int[] clone (int[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of floats.
// */
// public static native float[] clone (float[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of doubles.
// */
// public static native double[] clone (double[] values) /*-{
// return values.slice(0);
// }-*/;
// }
// Path: src/main/java/pythagoras/f/AbstractPoint.java
import pythagoras.util.Platform;
public Point rotate (float angle) {
return rotate(angle, new Point());
}
@Override // from IPoint
public Point rotate (float angle, Point result) {
float x = x(), y = y();
float sina = FloatMath.sin(angle), cosa = FloatMath.cos(angle);
return result.set(x*cosa - y*sina, x*sina + y*cosa);
}
@Override // from IPoint
public Point clone () {
return new Point(this);
}
@Override
public boolean equals (Object obj) {
if (obj == this) {
return true;
}
if (obj instanceof AbstractPoint) {
AbstractPoint p = (AbstractPoint)obj;
return x() == p.x() && y() == p.y();
}
return false;
}
@Override
public int hashCode () { | return Platform.hashCode(x()) ^ Platform.hashCode(y()); |
samskivert/pythagoras | src/main/java/pythagoras/d/Matrix4.java | // Path: src/gwt/java/pythagoras/util/Platform.java
// public class Platform
// {
// /**
// * Returns a hash code for the supplied float value.
// */
// public static int hashCode (float f1) {
// return (int)f1; // alas nothing better can be done in JavaScript
// }
//
// /**
// * Returns a hash code for the supplied double value.
// */
// public static int hashCode (double d1) {
// return (int)d1; // alas nothing better can be done in JavaScript
// }
//
// /**
// * Clones the supplied array of bytes.
// */
// public static native byte[] clone (byte[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of ints.
// */
// public static native int[] clone (int[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of floats.
// */
// public static native float[] clone (float[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of doubles.
// */
// public static native double[] clone (double[] values) /*-{
// return values.slice(0);
// }-*/;
// }
//
// Path: src/main/java/pythagoras/util/SingularMatrixException.java
// public class SingularMatrixException extends RuntimeException
// {
// private static final long serialVersionUID = -4744745375693073952L;
//
// /**
// * Creates a new exception.
// */
// public SingularMatrixException () {
// }
//
// /**
// * Creates a new exception with the provided message.
// */
// public SingularMatrixException (String message) {
// super(message);
// }
// }
| import pythagoras.util.Platform;
import pythagoras.util.SingularMatrixException;
import java.io.Serializable;
import java.nio.DoubleBuffer; | double om01 = other.m01(), om11 = other.m11(), om21 = other.m21(), om31 = other.m31();
double om02 = other.m02(), om12 = other.m12(), om22 = other.m22(), om32 = other.m32();
return result.set(m00*om00 + m10*om01 + m20*om02,
m00*om10 + m10*om11 + m20*om12,
m00*om20 + m10*om21 + m20*om22,
m00*om30 + m10*om31 + m20*om32 + m30,
m01*om00 + m11*om01 + m21*om02,
m01*om10 + m11*om11 + m21*om12,
m01*om20 + m11*om21 + m21*om22,
m01*om30 + m11*om31 + m21*om32 + m31,
m02*om00 + m12*om01 + m22*om02,
m02*om10 + m12*om11 + m22*om12,
m02*om20 + m12*om21 + m22*om22,
m02*om30 + m12*om31 + m22*om32 + m32,
0f, 0f, 0f, 1f);
}
@Override // from IMatrix4
public Matrix4 invert () {
return invert(new Matrix4());
}
/**
* {@inheritDoc} This code is based on the examples in the
* <a href="http://www.j3d.org/matrix_faq/matrfaq_latest.html">Matrix and Quaternion FAQ</a>.
*/
@Override // from IMatrix4 | // Path: src/gwt/java/pythagoras/util/Platform.java
// public class Platform
// {
// /**
// * Returns a hash code for the supplied float value.
// */
// public static int hashCode (float f1) {
// return (int)f1; // alas nothing better can be done in JavaScript
// }
//
// /**
// * Returns a hash code for the supplied double value.
// */
// public static int hashCode (double d1) {
// return (int)d1; // alas nothing better can be done in JavaScript
// }
//
// /**
// * Clones the supplied array of bytes.
// */
// public static native byte[] clone (byte[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of ints.
// */
// public static native int[] clone (int[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of floats.
// */
// public static native float[] clone (float[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of doubles.
// */
// public static native double[] clone (double[] values) /*-{
// return values.slice(0);
// }-*/;
// }
//
// Path: src/main/java/pythagoras/util/SingularMatrixException.java
// public class SingularMatrixException extends RuntimeException
// {
// private static final long serialVersionUID = -4744745375693073952L;
//
// /**
// * Creates a new exception.
// */
// public SingularMatrixException () {
// }
//
// /**
// * Creates a new exception with the provided message.
// */
// public SingularMatrixException (String message) {
// super(message);
// }
// }
// Path: src/main/java/pythagoras/d/Matrix4.java
import pythagoras.util.Platform;
import pythagoras.util.SingularMatrixException;
import java.io.Serializable;
import java.nio.DoubleBuffer;
double om01 = other.m01(), om11 = other.m11(), om21 = other.m21(), om31 = other.m31();
double om02 = other.m02(), om12 = other.m12(), om22 = other.m22(), om32 = other.m32();
return result.set(m00*om00 + m10*om01 + m20*om02,
m00*om10 + m10*om11 + m20*om12,
m00*om20 + m10*om21 + m20*om22,
m00*om30 + m10*om31 + m20*om32 + m30,
m01*om00 + m11*om01 + m21*om02,
m01*om10 + m11*om11 + m21*om12,
m01*om20 + m11*om21 + m21*om22,
m01*om30 + m11*om31 + m21*om32 + m31,
m02*om00 + m12*om01 + m22*om02,
m02*om10 + m12*om11 + m22*om12,
m02*om20 + m12*om21 + m22*om22,
m02*om30 + m12*om31 + m22*om32 + m32,
0f, 0f, 0f, 1f);
}
@Override // from IMatrix4
public Matrix4 invert () {
return invert(new Matrix4());
}
/**
* {@inheritDoc} This code is based on the examples in the
* <a href="http://www.j3d.org/matrix_faq/matrfaq_latest.html">Matrix and Quaternion FAQ</a>.
*/
@Override // from IMatrix4 | public Matrix4 invert (Matrix4 result) throws SingularMatrixException { |
samskivert/pythagoras | src/main/java/pythagoras/d/Matrix4.java | // Path: src/gwt/java/pythagoras/util/Platform.java
// public class Platform
// {
// /**
// * Returns a hash code for the supplied float value.
// */
// public static int hashCode (float f1) {
// return (int)f1; // alas nothing better can be done in JavaScript
// }
//
// /**
// * Returns a hash code for the supplied double value.
// */
// public static int hashCode (double d1) {
// return (int)d1; // alas nothing better can be done in JavaScript
// }
//
// /**
// * Clones the supplied array of bytes.
// */
// public static native byte[] clone (byte[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of ints.
// */
// public static native int[] clone (int[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of floats.
// */
// public static native float[] clone (float[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of doubles.
// */
// public static native double[] clone (double[] values) /*-{
// return values.slice(0);
// }-*/;
// }
//
// Path: src/main/java/pythagoras/util/SingularMatrixException.java
// public class SingularMatrixException extends RuntimeException
// {
// private static final long serialVersionUID = -4744745375693073952L;
//
// /**
// * Creates a new exception.
// */
// public SingularMatrixException () {
// }
//
// /**
// * Creates a new exception with the provided message.
// */
// public SingularMatrixException (String message) {
// super(message);
// }
// }
| import pythagoras.util.Platform;
import pythagoras.util.SingularMatrixException;
import java.io.Serializable;
import java.nio.DoubleBuffer; | Math.abs(m10 - other.m10()) < epsilon &&
Math.abs(m20 - other.m20()) < epsilon &&
Math.abs(m30 - other.m30()) < epsilon &&
Math.abs(m01 - other.m01()) < epsilon &&
Math.abs(m11 - other.m11()) < epsilon &&
Math.abs(m21 - other.m21()) < epsilon &&
Math.abs(m31 - other.m31()) < epsilon &&
Math.abs(m02 - other.m02()) < epsilon &&
Math.abs(m12 - other.m12()) < epsilon &&
Math.abs(m22 - other.m22()) < epsilon &&
Math.abs(m32 - other.m32()) < epsilon &&
Math.abs(m03 - other.m03()) < epsilon &&
Math.abs(m13 - other.m13()) < epsilon &&
Math.abs(m23 - other.m23()) < epsilon &&
Math.abs(m33 - other.m33()) < epsilon);
}
@Override
public String toString () {
return ("[[" + m00 + ", " + m10 + ", " + m20 + ", " + m30 + "], " +
"[" + m01 + ", " + m11 + ", " + m21 + ", " + m31 + "], " +
"[" + m02 + ", " + m12 + ", " + m22 + ", " + m32 + "], " +
"[" + m03 + ", " + m13 + ", " + m23 + ", " + m33 + "]]");
}
@Override
public int hashCode () { | // Path: src/gwt/java/pythagoras/util/Platform.java
// public class Platform
// {
// /**
// * Returns a hash code for the supplied float value.
// */
// public static int hashCode (float f1) {
// return (int)f1; // alas nothing better can be done in JavaScript
// }
//
// /**
// * Returns a hash code for the supplied double value.
// */
// public static int hashCode (double d1) {
// return (int)d1; // alas nothing better can be done in JavaScript
// }
//
// /**
// * Clones the supplied array of bytes.
// */
// public static native byte[] clone (byte[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of ints.
// */
// public static native int[] clone (int[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of floats.
// */
// public static native float[] clone (float[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of doubles.
// */
// public static native double[] clone (double[] values) /*-{
// return values.slice(0);
// }-*/;
// }
//
// Path: src/main/java/pythagoras/util/SingularMatrixException.java
// public class SingularMatrixException extends RuntimeException
// {
// private static final long serialVersionUID = -4744745375693073952L;
//
// /**
// * Creates a new exception.
// */
// public SingularMatrixException () {
// }
//
// /**
// * Creates a new exception with the provided message.
// */
// public SingularMatrixException (String message) {
// super(message);
// }
// }
// Path: src/main/java/pythagoras/d/Matrix4.java
import pythagoras.util.Platform;
import pythagoras.util.SingularMatrixException;
import java.io.Serializable;
import java.nio.DoubleBuffer;
Math.abs(m10 - other.m10()) < epsilon &&
Math.abs(m20 - other.m20()) < epsilon &&
Math.abs(m30 - other.m30()) < epsilon &&
Math.abs(m01 - other.m01()) < epsilon &&
Math.abs(m11 - other.m11()) < epsilon &&
Math.abs(m21 - other.m21()) < epsilon &&
Math.abs(m31 - other.m31()) < epsilon &&
Math.abs(m02 - other.m02()) < epsilon &&
Math.abs(m12 - other.m12()) < epsilon &&
Math.abs(m22 - other.m22()) < epsilon &&
Math.abs(m32 - other.m32()) < epsilon &&
Math.abs(m03 - other.m03()) < epsilon &&
Math.abs(m13 - other.m13()) < epsilon &&
Math.abs(m23 - other.m23()) < epsilon &&
Math.abs(m33 - other.m33()) < epsilon);
}
@Override
public String toString () {
return ("[[" + m00 + ", " + m10 + ", " + m20 + ", " + m30 + "], " +
"[" + m01 + ", " + m11 + ", " + m21 + ", " + m31 + "], " +
"[" + m02 + ", " + m12 + ", " + m22 + ", " + m32 + "], " +
"[" + m03 + ", " + m13 + ", " + m23 + ", " + m33 + "]]");
}
@Override
public int hashCode () { | return Platform.hashCode(m00) ^ Platform.hashCode(m10) ^ |
samskivert/pythagoras | src/main/java/pythagoras/d/Plane.java | // Path: src/gwt/java/pythagoras/util/Platform.java
// public class Platform
// {
// /**
// * Returns a hash code for the supplied float value.
// */
// public static int hashCode (float f1) {
// return (int)f1; // alas nothing better can be done in JavaScript
// }
//
// /**
// * Returns a hash code for the supplied double value.
// */
// public static int hashCode (double d1) {
// return (int)d1; // alas nothing better can be done in JavaScript
// }
//
// /**
// * Clones the supplied array of bytes.
// */
// public static native byte[] clone (byte[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of ints.
// */
// public static native int[] clone (int[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of floats.
// */
// public static native float[] clone (float[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of doubles.
// */
// public static native double[] clone (double[] values) /*-{
// return values.slice(0);
// }-*/;
// }
| import pythagoras.util.Platform;
import java.io.Serializable;
import java.nio.DoubleBuffer; | result.constant = -constant;
return result;
}
@Override // from IPlane
public boolean intersection (IRay3 ray, Vector3 result) {
double distance = distance(ray);
if (Double.isNaN(distance) || distance < 0f) {
return false;
} else {
ray.origin().addScaled(ray.direction(), distance, result);
return true;
}
}
@Override // from IPlane
public double distance (IRay3 ray) {
double dividend = -distance(ray.origin());
double divisor = _normal.dot(ray.direction());
if (Math.abs(dividend) < MathUtil.EPSILON) {
return 0f; // origin is on plane
} else if (Math.abs(divisor) < MathUtil.EPSILON) {
return Float.NaN; // ray is parallel to plane
} else {
return dividend / divisor;
}
}
@Override
public int hashCode () { | // Path: src/gwt/java/pythagoras/util/Platform.java
// public class Platform
// {
// /**
// * Returns a hash code for the supplied float value.
// */
// public static int hashCode (float f1) {
// return (int)f1; // alas nothing better can be done in JavaScript
// }
//
// /**
// * Returns a hash code for the supplied double value.
// */
// public static int hashCode (double d1) {
// return (int)d1; // alas nothing better can be done in JavaScript
// }
//
// /**
// * Clones the supplied array of bytes.
// */
// public static native byte[] clone (byte[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of ints.
// */
// public static native int[] clone (int[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of floats.
// */
// public static native float[] clone (float[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of doubles.
// */
// public static native double[] clone (double[] values) /*-{
// return values.slice(0);
// }-*/;
// }
// Path: src/main/java/pythagoras/d/Plane.java
import pythagoras.util.Platform;
import java.io.Serializable;
import java.nio.DoubleBuffer;
result.constant = -constant;
return result;
}
@Override // from IPlane
public boolean intersection (IRay3 ray, Vector3 result) {
double distance = distance(ray);
if (Double.isNaN(distance) || distance < 0f) {
return false;
} else {
ray.origin().addScaled(ray.direction(), distance, result);
return true;
}
}
@Override // from IPlane
public double distance (IRay3 ray) {
double dividend = -distance(ray.origin());
double divisor = _normal.dot(ray.direction());
if (Math.abs(dividend) < MathUtil.EPSILON) {
return 0f; // origin is on plane
} else if (Math.abs(divisor) < MathUtil.EPSILON) {
return Float.NaN; // ray is parallel to plane
} else {
return dividend / divisor;
}
}
@Override
public int hashCode () { | return _normal.hashCode() ^ Platform.hashCode(constant); |
samskivert/pythagoras | src/main/java/pythagoras/f/Vector3.java | // Path: src/gwt/java/pythagoras/util/Platform.java
// public class Platform
// {
// /**
// * Returns a hash code for the supplied float value.
// */
// public static int hashCode (float f1) {
// return (int)f1; // alas nothing better can be done in JavaScript
// }
//
// /**
// * Returns a hash code for the supplied double value.
// */
// public static int hashCode (double d1) {
// return (int)d1; // alas nothing better can be done in JavaScript
// }
//
// /**
// * Clones the supplied array of bytes.
// */
// public static native byte[] clone (byte[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of ints.
// */
// public static native int[] clone (int[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of floats.
// */
// public static native float[] clone (float[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of doubles.
// */
// public static native double[] clone (double[] values) /*-{
// return values.slice(0);
// }-*/;
// }
| import pythagoras.util.Platform;
import java.io.Serializable;
import java.nio.FloatBuffer; |
@Override // from interface IVector3
public float get (int idx) {
switch (idx) {
case 0: return x;
case 1: return y;
case 2: return z;
}
throw new IndexOutOfBoundsException(String.valueOf(idx));
}
@Override // from interface IVector3
public void get (float[] values) {
values[0] = x;
values[1] = y;
values[2] = z;
}
@Override // from interface IVector3
public FloatBuffer get (FloatBuffer buf) {
return buf.put(x).put(y).put(z);
}
@Override
public String toString () {
return "[" + x + ", " + y + ", " + z + "]";
}
@Override
public int hashCode () { | // Path: src/gwt/java/pythagoras/util/Platform.java
// public class Platform
// {
// /**
// * Returns a hash code for the supplied float value.
// */
// public static int hashCode (float f1) {
// return (int)f1; // alas nothing better can be done in JavaScript
// }
//
// /**
// * Returns a hash code for the supplied double value.
// */
// public static int hashCode (double d1) {
// return (int)d1; // alas nothing better can be done in JavaScript
// }
//
// /**
// * Clones the supplied array of bytes.
// */
// public static native byte[] clone (byte[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of ints.
// */
// public static native int[] clone (int[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of floats.
// */
// public static native float[] clone (float[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of doubles.
// */
// public static native double[] clone (double[] values) /*-{
// return values.slice(0);
// }-*/;
// }
// Path: src/main/java/pythagoras/f/Vector3.java
import pythagoras.util.Platform;
import java.io.Serializable;
import java.nio.FloatBuffer;
@Override // from interface IVector3
public float get (int idx) {
switch (idx) {
case 0: return x;
case 1: return y;
case 2: return z;
}
throw new IndexOutOfBoundsException(String.valueOf(idx));
}
@Override // from interface IVector3
public void get (float[] values) {
values[0] = x;
values[1] = y;
values[2] = z;
}
@Override // from interface IVector3
public FloatBuffer get (FloatBuffer buf) {
return buf.put(x).put(y).put(z);
}
@Override
public String toString () {
return "[" + x + ", " + y + ", " + z + "]";
}
@Override
public int hashCode () { | return Platform.hashCode(x) ^ Platform.hashCode(y) ^ Platform.hashCode(z); |
samskivert/pythagoras | src/main/java/pythagoras/d/AffineTransform.java | // Path: src/main/java/pythagoras/util/NoninvertibleTransformException.java
// public class NoninvertibleTransformException extends RuntimeException
// {
// private static final long serialVersionUID = 5208863644264280750L;
//
// public NoninvertibleTransformException (String s) {
// super(s);
// }
// }
| import pythagoras.util.NoninvertibleTransformException; | //
// Pythagoras - a collection of geometry classes
// http://github.com/samskivert/pythagoras
package pythagoras.d;
/**
* Implements an affine (3x2 matrix) transform. The transformation matrix has the form:
* <pre>{@code
* [ m00, m10, tx ]
* [ m01, m11, ty ]
* [ 0, 0, 1 ]
* }</pre>
*/
public class AffineTransform extends AbstractTransform
{
/** Identifies the affine transform in {@link #generality}. */
public static final int GENERALITY = 4;
/** The scale, rotation and shear components of this transform. */
public double m00, m01, m10, m11;
/** The translation components of this transform. */
public double tx, ty;
/** Creates an affine transform configured with the identity transform. */
public AffineTransform () {
this(1, 0, 0, 1, 0, 0);
}
/** Creates an affine transform from the supplied scale, rotation and translation. */
public AffineTransform (double scale, double angle, double tx, double ty) {
this(scale, scale, angle, tx, ty);
}
/** Creates an affine transform from the supplied scale, rotation and translation. */
public AffineTransform (double scaleX, double scaleY, double angle, double tx, double ty) {
double sina = Math.sin(angle), cosa = Math.cos(angle);
this.m00 = cosa * scaleX; this.m01 = sina * scaleY;
this.m10 = -sina * scaleX; this.m11 = cosa * scaleY;
this.tx = tx; this.ty = ty;
}
/** Creates an affine transform with the specified transform matrix. */
public AffineTransform (double m00, double m01, double m10, double m11, double tx, double ty) {
this.m00 = m00; this.m01 = m01;
this.m10 = m10; this.m11 = m11;
this.tx = tx; this.ty = ty;
}
/** Sets this affine transform matrix to {@code other}.
* @return this instance, for chaining. */
public AffineTransform set (AffineTransform other) {
return setTransform(other.m00, other.m01, other.m10, other.m11, other.tx, other.ty);
}
@Override // from Transform
public double uniformScale () {
// the square root of the signed area of the parallelogram spanned by the axis vectors
double cp = m00*m11 - m01*m10;
return (cp < 0f) ? -Math.sqrt(-cp) : Math.sqrt(cp);
}
@Override // from Transform
public double scaleX () {
return Math.sqrt(m00*m00 + m01*m01);
}
@Override // from Transform
public double scaleY () {
return Math.sqrt(m10*m10 + m11*m11);
}
@Override // from Transform
public double rotation () {
// use the iterative polar decomposition algorithm described by Ken Shoemake:
// http://www.cs.wisc.edu/graphics/Courses/838-s2002/Papers/polar-decomp.pdf
// start with the contents of the upper 2x2 portion of the matrix
double n00 = m00, n10 = m10;
double n01 = m01, n11 = m11;
for (int ii = 0; ii < 10; ii++) {
// store the results of the previous iteration
double o00 = n00, o10 = n10;
double o01 = n01, o11 = n11;
// compute average of the matrix with its inverse transpose
double det = o00*o11 - o10*o01;
if (Math.abs(det) == 0f) {
// determinant is zero; matrix is not invertible | // Path: src/main/java/pythagoras/util/NoninvertibleTransformException.java
// public class NoninvertibleTransformException extends RuntimeException
// {
// private static final long serialVersionUID = 5208863644264280750L;
//
// public NoninvertibleTransformException (String s) {
// super(s);
// }
// }
// Path: src/main/java/pythagoras/d/AffineTransform.java
import pythagoras.util.NoninvertibleTransformException;
//
// Pythagoras - a collection of geometry classes
// http://github.com/samskivert/pythagoras
package pythagoras.d;
/**
* Implements an affine (3x2 matrix) transform. The transformation matrix has the form:
* <pre>{@code
* [ m00, m10, tx ]
* [ m01, m11, ty ]
* [ 0, 0, 1 ]
* }</pre>
*/
public class AffineTransform extends AbstractTransform
{
/** Identifies the affine transform in {@link #generality}. */
public static final int GENERALITY = 4;
/** The scale, rotation and shear components of this transform. */
public double m00, m01, m10, m11;
/** The translation components of this transform. */
public double tx, ty;
/** Creates an affine transform configured with the identity transform. */
public AffineTransform () {
this(1, 0, 0, 1, 0, 0);
}
/** Creates an affine transform from the supplied scale, rotation and translation. */
public AffineTransform (double scale, double angle, double tx, double ty) {
this(scale, scale, angle, tx, ty);
}
/** Creates an affine transform from the supplied scale, rotation and translation. */
public AffineTransform (double scaleX, double scaleY, double angle, double tx, double ty) {
double sina = Math.sin(angle), cosa = Math.cos(angle);
this.m00 = cosa * scaleX; this.m01 = sina * scaleY;
this.m10 = -sina * scaleX; this.m11 = cosa * scaleY;
this.tx = tx; this.ty = ty;
}
/** Creates an affine transform with the specified transform matrix. */
public AffineTransform (double m00, double m01, double m10, double m11, double tx, double ty) {
this.m00 = m00; this.m01 = m01;
this.m10 = m10; this.m11 = m11;
this.tx = tx; this.ty = ty;
}
/** Sets this affine transform matrix to {@code other}.
* @return this instance, for chaining. */
public AffineTransform set (AffineTransform other) {
return setTransform(other.m00, other.m01, other.m10, other.m11, other.tx, other.ty);
}
@Override // from Transform
public double uniformScale () {
// the square root of the signed area of the parallelogram spanned by the axis vectors
double cp = m00*m11 - m01*m10;
return (cp < 0f) ? -Math.sqrt(-cp) : Math.sqrt(cp);
}
@Override // from Transform
public double scaleX () {
return Math.sqrt(m00*m00 + m01*m01);
}
@Override // from Transform
public double scaleY () {
return Math.sqrt(m10*m10 + m11*m11);
}
@Override // from Transform
public double rotation () {
// use the iterative polar decomposition algorithm described by Ken Shoemake:
// http://www.cs.wisc.edu/graphics/Courses/838-s2002/Papers/polar-decomp.pdf
// start with the contents of the upper 2x2 portion of the matrix
double n00 = m00, n10 = m10;
double n01 = m01, n11 = m11;
for (int ii = 0; ii < 10; ii++) {
// store the results of the previous iteration
double o00 = n00, o10 = n10;
double o01 = n01, o11 = n11;
// compute average of the matrix with its inverse transpose
double det = o00*o11 - o10*o01;
if (Math.abs(det) == 0f) {
// determinant is zero; matrix is not invertible | throw new NoninvertibleTransformException(this.toString()); |
samskivert/pythagoras | src/main/java/pythagoras/d/Vector4.java | // Path: src/gwt/java/pythagoras/util/Platform.java
// public class Platform
// {
// /**
// * Returns a hash code for the supplied float value.
// */
// public static int hashCode (float f1) {
// return (int)f1; // alas nothing better can be done in JavaScript
// }
//
// /**
// * Returns a hash code for the supplied double value.
// */
// public static int hashCode (double d1) {
// return (int)d1; // alas nothing better can be done in JavaScript
// }
//
// /**
// * Clones the supplied array of bytes.
// */
// public static native byte[] clone (byte[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of ints.
// */
// public static native int[] clone (int[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of floats.
// */
// public static native float[] clone (float[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of doubles.
// */
// public static native double[] clone (double[] values) /*-{
// return values.slice(0);
// }-*/;
// }
| import pythagoras.util.Platform;
import java.io.Serializable;
import java.nio.DoubleBuffer; | @Override // from interface IVector4
public Vector4 mult (double v, Vector4 result) {
return result.set(x*v, y*v, z*v, w*v);
}
@Override // from IVector4
public Vector4 mult (IMatrix4 matrix) {
return mult(matrix, new Vector4());
}
@Override // from IVector4
public Vector4 mult (IMatrix4 matrix, Vector4 result) {
double m00 = matrix.m00(), m10 = matrix.m10(), m20 = matrix.m20(), m30 = matrix.m30();
double m01 = matrix.m01(), m11 = matrix.m11(), m21 = matrix.m21(), m31 = matrix.m31();
double m02 = matrix.m02(), m12 = matrix.m12(), m22 = matrix.m22(), m32 = matrix.m32();
double m03 = matrix.m03(), m13 = matrix.m13(), m23 = matrix.m23(), m33 = matrix.m33();
double vx = x, vy = y, vz = z, vw = w;
return result.set(m00*vx + m01*vy + m02*vz + m03*vw,
m10*vx + m11*vy + m12*vz + m13*vw,
m20*vx + m21*vy + m22*vz + m23*vw,
m30*vx + m31*vy + m32*vz + m33*vw);
}
@Override
public String toString () {
return "[" + x + ", " + y + ", " + z + ", " + w + "]";
}
@Override
public int hashCode () { | // Path: src/gwt/java/pythagoras/util/Platform.java
// public class Platform
// {
// /**
// * Returns a hash code for the supplied float value.
// */
// public static int hashCode (float f1) {
// return (int)f1; // alas nothing better can be done in JavaScript
// }
//
// /**
// * Returns a hash code for the supplied double value.
// */
// public static int hashCode (double d1) {
// return (int)d1; // alas nothing better can be done in JavaScript
// }
//
// /**
// * Clones the supplied array of bytes.
// */
// public static native byte[] clone (byte[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of ints.
// */
// public static native int[] clone (int[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of floats.
// */
// public static native float[] clone (float[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of doubles.
// */
// public static native double[] clone (double[] values) /*-{
// return values.slice(0);
// }-*/;
// }
// Path: src/main/java/pythagoras/d/Vector4.java
import pythagoras.util.Platform;
import java.io.Serializable;
import java.nio.DoubleBuffer;
@Override // from interface IVector4
public Vector4 mult (double v, Vector4 result) {
return result.set(x*v, y*v, z*v, w*v);
}
@Override // from IVector4
public Vector4 mult (IMatrix4 matrix) {
return mult(matrix, new Vector4());
}
@Override // from IVector4
public Vector4 mult (IMatrix4 matrix, Vector4 result) {
double m00 = matrix.m00(), m10 = matrix.m10(), m20 = matrix.m20(), m30 = matrix.m30();
double m01 = matrix.m01(), m11 = matrix.m11(), m21 = matrix.m21(), m31 = matrix.m31();
double m02 = matrix.m02(), m12 = matrix.m12(), m22 = matrix.m22(), m32 = matrix.m32();
double m03 = matrix.m03(), m13 = matrix.m13(), m23 = matrix.m23(), m33 = matrix.m33();
double vx = x, vy = y, vz = z, vw = w;
return result.set(m00*vx + m01*vy + m02*vz + m03*vw,
m10*vx + m11*vy + m12*vz + m13*vw,
m20*vx + m21*vy + m22*vz + m23*vw,
m30*vx + m31*vy + m32*vz + m33*vw);
}
@Override
public String toString () {
return "[" + x + ", " + y + ", " + z + ", " + w + "]";
}
@Override
public int hashCode () { | return Platform.hashCode(x) ^ Platform.hashCode(y) ^ Platform.hashCode(z) ^ |
samskivert/pythagoras | src/main/java/pythagoras/f/AbstractRectangle.java | // Path: src/gwt/java/pythagoras/util/Platform.java
// public class Platform
// {
// /**
// * Returns a hash code for the supplied float value.
// */
// public static int hashCode (float f1) {
// return (int)f1; // alas nothing better can be done in JavaScript
// }
//
// /**
// * Returns a hash code for the supplied double value.
// */
// public static int hashCode (double d1) {
// return (int)d1; // alas nothing better can be done in JavaScript
// }
//
// /**
// * Clones the supplied array of bytes.
// */
// public static native byte[] clone (byte[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of ints.
// */
// public static native int[] clone (int[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of floats.
// */
// public static native float[] clone (float[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of doubles.
// */
// public static native double[] clone (double[] values) /*-{
// return values.slice(0);
// }-*/;
// }
| import pythagoras.util.Platform;
import java.util.NoSuchElementException; |
float x1 = x(), y1 = y(), x2 = x1 + width(), y2 = y1 + height();
return (rx + rw > x1) && (rx < x2) && (ry + rh > y1) && (ry < y2);
}
@Override // from interface IShape
public PathIterator pathIterator (Transform t) {
return new Iterator(this, t);
}
@Override // from interface IShape
public PathIterator pathIterator (Transform t, float flatness) {
return new Iterator(this, t);
}
@Override // from Object
public boolean equals (Object obj) {
if (obj == this) {
return true;
}
if (obj instanceof AbstractRectangle) {
AbstractRectangle r = (AbstractRectangle)obj;
return r.x() == x() && r.y() == y() &&
r.width() == width() && r.height() == height();
}
return false;
}
@Override // from Object
public int hashCode () { | // Path: src/gwt/java/pythagoras/util/Platform.java
// public class Platform
// {
// /**
// * Returns a hash code for the supplied float value.
// */
// public static int hashCode (float f1) {
// return (int)f1; // alas nothing better can be done in JavaScript
// }
//
// /**
// * Returns a hash code for the supplied double value.
// */
// public static int hashCode (double d1) {
// return (int)d1; // alas nothing better can be done in JavaScript
// }
//
// /**
// * Clones the supplied array of bytes.
// */
// public static native byte[] clone (byte[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of ints.
// */
// public static native int[] clone (int[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of floats.
// */
// public static native float[] clone (float[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of doubles.
// */
// public static native double[] clone (double[] values) /*-{
// return values.slice(0);
// }-*/;
// }
// Path: src/main/java/pythagoras/f/AbstractRectangle.java
import pythagoras.util.Platform;
import java.util.NoSuchElementException;
float x1 = x(), y1 = y(), x2 = x1 + width(), y2 = y1 + height();
return (rx + rw > x1) && (rx < x2) && (ry + rh > y1) && (ry < y2);
}
@Override // from interface IShape
public PathIterator pathIterator (Transform t) {
return new Iterator(this, t);
}
@Override // from interface IShape
public PathIterator pathIterator (Transform t, float flatness) {
return new Iterator(this, t);
}
@Override // from Object
public boolean equals (Object obj) {
if (obj == this) {
return true;
}
if (obj instanceof AbstractRectangle) {
AbstractRectangle r = (AbstractRectangle)obj;
return r.x() == x() && r.y() == y() &&
r.width() == width() && r.height() == height();
}
return false;
}
@Override // from Object
public int hashCode () { | return Platform.hashCode(x()) ^ Platform.hashCode(y()) ^ |
samskivert/pythagoras | src/main/java/pythagoras/d/AbstractRectangle.java | // Path: src/gwt/java/pythagoras/util/Platform.java
// public class Platform
// {
// /**
// * Returns a hash code for the supplied float value.
// */
// public static int hashCode (float f1) {
// return (int)f1; // alas nothing better can be done in JavaScript
// }
//
// /**
// * Returns a hash code for the supplied double value.
// */
// public static int hashCode (double d1) {
// return (int)d1; // alas nothing better can be done in JavaScript
// }
//
// /**
// * Clones the supplied array of bytes.
// */
// public static native byte[] clone (byte[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of ints.
// */
// public static native int[] clone (int[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of floats.
// */
// public static native float[] clone (float[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of doubles.
// */
// public static native double[] clone (double[] values) /*-{
// return values.slice(0);
// }-*/;
// }
| import pythagoras.util.Platform;
import java.util.NoSuchElementException; |
double x1 = x(), y1 = y(), x2 = x1 + width(), y2 = y1 + height();
return (rx + rw > x1) && (rx < x2) && (ry + rh > y1) && (ry < y2);
}
@Override // from interface IShape
public PathIterator pathIterator (Transform t) {
return new Iterator(this, t);
}
@Override // from interface IShape
public PathIterator pathIterator (Transform t, double flatness) {
return new Iterator(this, t);
}
@Override // from Object
public boolean equals (Object obj) {
if (obj == this) {
return true;
}
if (obj instanceof AbstractRectangle) {
AbstractRectangle r = (AbstractRectangle)obj;
return r.x() == x() && r.y() == y() &&
r.width() == width() && r.height() == height();
}
return false;
}
@Override // from Object
public int hashCode () { | // Path: src/gwt/java/pythagoras/util/Platform.java
// public class Platform
// {
// /**
// * Returns a hash code for the supplied float value.
// */
// public static int hashCode (float f1) {
// return (int)f1; // alas nothing better can be done in JavaScript
// }
//
// /**
// * Returns a hash code for the supplied double value.
// */
// public static int hashCode (double d1) {
// return (int)d1; // alas nothing better can be done in JavaScript
// }
//
// /**
// * Clones the supplied array of bytes.
// */
// public static native byte[] clone (byte[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of ints.
// */
// public static native int[] clone (int[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of floats.
// */
// public static native float[] clone (float[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of doubles.
// */
// public static native double[] clone (double[] values) /*-{
// return values.slice(0);
// }-*/;
// }
// Path: src/main/java/pythagoras/d/AbstractRectangle.java
import pythagoras.util.Platform;
import java.util.NoSuchElementException;
double x1 = x(), y1 = y(), x2 = x1 + width(), y2 = y1 + height();
return (rx + rw > x1) && (rx < x2) && (ry + rh > y1) && (ry < y2);
}
@Override // from interface IShape
public PathIterator pathIterator (Transform t) {
return new Iterator(this, t);
}
@Override // from interface IShape
public PathIterator pathIterator (Transform t, double flatness) {
return new Iterator(this, t);
}
@Override // from Object
public boolean equals (Object obj) {
if (obj == this) {
return true;
}
if (obj instanceof AbstractRectangle) {
AbstractRectangle r = (AbstractRectangle)obj;
return r.x() == x() && r.y() == y() &&
r.width() == width() && r.height() == height();
}
return false;
}
@Override // from Object
public int hashCode () { | return Platform.hashCode(x()) ^ Platform.hashCode(y()) ^ |
samskivert/pythagoras | src/main/java/pythagoras/f/Matrix4.java | // Path: src/gwt/java/pythagoras/util/Platform.java
// public class Platform
// {
// /**
// * Returns a hash code for the supplied float value.
// */
// public static int hashCode (float f1) {
// return (int)f1; // alas nothing better can be done in JavaScript
// }
//
// /**
// * Returns a hash code for the supplied double value.
// */
// public static int hashCode (double d1) {
// return (int)d1; // alas nothing better can be done in JavaScript
// }
//
// /**
// * Clones the supplied array of bytes.
// */
// public static native byte[] clone (byte[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of ints.
// */
// public static native int[] clone (int[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of floats.
// */
// public static native float[] clone (float[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of doubles.
// */
// public static native double[] clone (double[] values) /*-{
// return values.slice(0);
// }-*/;
// }
//
// Path: src/main/java/pythagoras/util/SingularMatrixException.java
// public class SingularMatrixException extends RuntimeException
// {
// private static final long serialVersionUID = -4744745375693073952L;
//
// /**
// * Creates a new exception.
// */
// public SingularMatrixException () {
// }
//
// /**
// * Creates a new exception with the provided message.
// */
// public SingularMatrixException (String message) {
// super(message);
// }
// }
| import pythagoras.util.Platform;
import pythagoras.util.SingularMatrixException;
import java.io.Serializable;
import java.nio.FloatBuffer; | float om01 = other.m01(), om11 = other.m11(), om21 = other.m21(), om31 = other.m31();
float om02 = other.m02(), om12 = other.m12(), om22 = other.m22(), om32 = other.m32();
return result.set(m00*om00 + m10*om01 + m20*om02,
m00*om10 + m10*om11 + m20*om12,
m00*om20 + m10*om21 + m20*om22,
m00*om30 + m10*om31 + m20*om32 + m30,
m01*om00 + m11*om01 + m21*om02,
m01*om10 + m11*om11 + m21*om12,
m01*om20 + m11*om21 + m21*om22,
m01*om30 + m11*om31 + m21*om32 + m31,
m02*om00 + m12*om01 + m22*om02,
m02*om10 + m12*om11 + m22*om12,
m02*om20 + m12*om21 + m22*om22,
m02*om30 + m12*om31 + m22*om32 + m32,
0f, 0f, 0f, 1f);
}
@Override // from IMatrix4
public Matrix4 invert () {
return invert(new Matrix4());
}
/**
* {@inheritDoc} This code is based on the examples in the
* <a href="http://www.j3d.org/matrix_faq/matrfaq_latest.html">Matrix and Quaternion FAQ</a>.
*/
@Override // from IMatrix4 | // Path: src/gwt/java/pythagoras/util/Platform.java
// public class Platform
// {
// /**
// * Returns a hash code for the supplied float value.
// */
// public static int hashCode (float f1) {
// return (int)f1; // alas nothing better can be done in JavaScript
// }
//
// /**
// * Returns a hash code for the supplied double value.
// */
// public static int hashCode (double d1) {
// return (int)d1; // alas nothing better can be done in JavaScript
// }
//
// /**
// * Clones the supplied array of bytes.
// */
// public static native byte[] clone (byte[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of ints.
// */
// public static native int[] clone (int[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of floats.
// */
// public static native float[] clone (float[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of doubles.
// */
// public static native double[] clone (double[] values) /*-{
// return values.slice(0);
// }-*/;
// }
//
// Path: src/main/java/pythagoras/util/SingularMatrixException.java
// public class SingularMatrixException extends RuntimeException
// {
// private static final long serialVersionUID = -4744745375693073952L;
//
// /**
// * Creates a new exception.
// */
// public SingularMatrixException () {
// }
//
// /**
// * Creates a new exception with the provided message.
// */
// public SingularMatrixException (String message) {
// super(message);
// }
// }
// Path: src/main/java/pythagoras/f/Matrix4.java
import pythagoras.util.Platform;
import pythagoras.util.SingularMatrixException;
import java.io.Serializable;
import java.nio.FloatBuffer;
float om01 = other.m01(), om11 = other.m11(), om21 = other.m21(), om31 = other.m31();
float om02 = other.m02(), om12 = other.m12(), om22 = other.m22(), om32 = other.m32();
return result.set(m00*om00 + m10*om01 + m20*om02,
m00*om10 + m10*om11 + m20*om12,
m00*om20 + m10*om21 + m20*om22,
m00*om30 + m10*om31 + m20*om32 + m30,
m01*om00 + m11*om01 + m21*om02,
m01*om10 + m11*om11 + m21*om12,
m01*om20 + m11*om21 + m21*om22,
m01*om30 + m11*om31 + m21*om32 + m31,
m02*om00 + m12*om01 + m22*om02,
m02*om10 + m12*om11 + m22*om12,
m02*om20 + m12*om21 + m22*om22,
m02*om30 + m12*om31 + m22*om32 + m32,
0f, 0f, 0f, 1f);
}
@Override // from IMatrix4
public Matrix4 invert () {
return invert(new Matrix4());
}
/**
* {@inheritDoc} This code is based on the examples in the
* <a href="http://www.j3d.org/matrix_faq/matrfaq_latest.html">Matrix and Quaternion FAQ</a>.
*/
@Override // from IMatrix4 | public Matrix4 invert (Matrix4 result) throws SingularMatrixException { |
samskivert/pythagoras | src/main/java/pythagoras/f/Matrix4.java | // Path: src/gwt/java/pythagoras/util/Platform.java
// public class Platform
// {
// /**
// * Returns a hash code for the supplied float value.
// */
// public static int hashCode (float f1) {
// return (int)f1; // alas nothing better can be done in JavaScript
// }
//
// /**
// * Returns a hash code for the supplied double value.
// */
// public static int hashCode (double d1) {
// return (int)d1; // alas nothing better can be done in JavaScript
// }
//
// /**
// * Clones the supplied array of bytes.
// */
// public static native byte[] clone (byte[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of ints.
// */
// public static native int[] clone (int[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of floats.
// */
// public static native float[] clone (float[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of doubles.
// */
// public static native double[] clone (double[] values) /*-{
// return values.slice(0);
// }-*/;
// }
//
// Path: src/main/java/pythagoras/util/SingularMatrixException.java
// public class SingularMatrixException extends RuntimeException
// {
// private static final long serialVersionUID = -4744745375693073952L;
//
// /**
// * Creates a new exception.
// */
// public SingularMatrixException () {
// }
//
// /**
// * Creates a new exception with the provided message.
// */
// public SingularMatrixException (String message) {
// super(message);
// }
// }
| import pythagoras.util.Platform;
import pythagoras.util.SingularMatrixException;
import java.io.Serializable;
import java.nio.FloatBuffer; | Math.abs(m10 - other.m10()) < epsilon &&
Math.abs(m20 - other.m20()) < epsilon &&
Math.abs(m30 - other.m30()) < epsilon &&
Math.abs(m01 - other.m01()) < epsilon &&
Math.abs(m11 - other.m11()) < epsilon &&
Math.abs(m21 - other.m21()) < epsilon &&
Math.abs(m31 - other.m31()) < epsilon &&
Math.abs(m02 - other.m02()) < epsilon &&
Math.abs(m12 - other.m12()) < epsilon &&
Math.abs(m22 - other.m22()) < epsilon &&
Math.abs(m32 - other.m32()) < epsilon &&
Math.abs(m03 - other.m03()) < epsilon &&
Math.abs(m13 - other.m13()) < epsilon &&
Math.abs(m23 - other.m23()) < epsilon &&
Math.abs(m33 - other.m33()) < epsilon);
}
@Override
public String toString () {
return ("[[" + m00 + ", " + m10 + ", " + m20 + ", " + m30 + "], " +
"[" + m01 + ", " + m11 + ", " + m21 + ", " + m31 + "], " +
"[" + m02 + ", " + m12 + ", " + m22 + ", " + m32 + "], " +
"[" + m03 + ", " + m13 + ", " + m23 + ", " + m33 + "]]");
}
@Override
public int hashCode () { | // Path: src/gwt/java/pythagoras/util/Platform.java
// public class Platform
// {
// /**
// * Returns a hash code for the supplied float value.
// */
// public static int hashCode (float f1) {
// return (int)f1; // alas nothing better can be done in JavaScript
// }
//
// /**
// * Returns a hash code for the supplied double value.
// */
// public static int hashCode (double d1) {
// return (int)d1; // alas nothing better can be done in JavaScript
// }
//
// /**
// * Clones the supplied array of bytes.
// */
// public static native byte[] clone (byte[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of ints.
// */
// public static native int[] clone (int[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of floats.
// */
// public static native float[] clone (float[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of doubles.
// */
// public static native double[] clone (double[] values) /*-{
// return values.slice(0);
// }-*/;
// }
//
// Path: src/main/java/pythagoras/util/SingularMatrixException.java
// public class SingularMatrixException extends RuntimeException
// {
// private static final long serialVersionUID = -4744745375693073952L;
//
// /**
// * Creates a new exception.
// */
// public SingularMatrixException () {
// }
//
// /**
// * Creates a new exception with the provided message.
// */
// public SingularMatrixException (String message) {
// super(message);
// }
// }
// Path: src/main/java/pythagoras/f/Matrix4.java
import pythagoras.util.Platform;
import pythagoras.util.SingularMatrixException;
import java.io.Serializable;
import java.nio.FloatBuffer;
Math.abs(m10 - other.m10()) < epsilon &&
Math.abs(m20 - other.m20()) < epsilon &&
Math.abs(m30 - other.m30()) < epsilon &&
Math.abs(m01 - other.m01()) < epsilon &&
Math.abs(m11 - other.m11()) < epsilon &&
Math.abs(m21 - other.m21()) < epsilon &&
Math.abs(m31 - other.m31()) < epsilon &&
Math.abs(m02 - other.m02()) < epsilon &&
Math.abs(m12 - other.m12()) < epsilon &&
Math.abs(m22 - other.m22()) < epsilon &&
Math.abs(m32 - other.m32()) < epsilon &&
Math.abs(m03 - other.m03()) < epsilon &&
Math.abs(m13 - other.m13()) < epsilon &&
Math.abs(m23 - other.m23()) < epsilon &&
Math.abs(m33 - other.m33()) < epsilon);
}
@Override
public String toString () {
return ("[[" + m00 + ", " + m10 + ", " + m20 + ", " + m30 + "], " +
"[" + m01 + ", " + m11 + ", " + m21 + ", " + m31 + "], " +
"[" + m02 + ", " + m12 + ", " + m22 + ", " + m32 + "], " +
"[" + m03 + ", " + m13 + ", " + m23 + ", " + m33 + "]]");
}
@Override
public int hashCode () { | return Platform.hashCode(m00) ^ Platform.hashCode(m10) ^ |
samskivert/pythagoras | src/main/java/pythagoras/d/Area.java | // Path: src/gwt/java/pythagoras/util/Platform.java
// public class Platform
// {
// /**
// * Returns a hash code for the supplied float value.
// */
// public static int hashCode (float f1) {
// return (int)f1; // alas nothing better can be done in JavaScript
// }
//
// /**
// * Returns a hash code for the supplied double value.
// */
// public static int hashCode (double d1) {
// return (int)d1; // alas nothing better can be done in JavaScript
// }
//
// /**
// * Clones the supplied array of bytes.
// */
// public static native byte[] clone (byte[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of ints.
// */
// public static native int[] clone (int[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of floats.
// */
// public static native float[] clone (float[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of doubles.
// */
// public static native double[] clone (double[] values) /*-{
// return values.slice(0);
// }-*/;
// }
| import pythagoras.util.Platform;
import java.util.NoSuchElementException; | coefs = new double[] { coords[index - 2], coords[index - 1], coords[index],
coords[index + 1], coords[index + 2], coords[index + 3],
coords[index + 4], coords[index + 5] };
isLeft = CrossingHelper.compare(
coords[index - 2], coords[index - 1], point.x(), point.y()) > 0;
GeometryUtil.subCubic(coefs, point.param(isCurrentArea), !isLeft);
if (isLeft) {
System.arraycopy(coefs, 2, temp, coordsCount, 6);
coordsCount += 6;
} else {
System.arraycopy(coefs, 2, temp, coordsCount, 4);
coordsCount += 4;
}
break;
}
}
if (operation == 2 && !isCurrentArea && coordsCount > 2) {
reverseCopy(temp);
System.arraycopy(temp, 0, resultCoords, resultCoordPos, coordsCount);
} else {
System.arraycopy(temp, 0, resultCoords, resultCoordPos, coordsCount);
}
return (resultCoordPos + coordsCount);
}
private void copy (Area src, Area dst) {
dst._coordsSize = src._coordsSize; | // Path: src/gwt/java/pythagoras/util/Platform.java
// public class Platform
// {
// /**
// * Returns a hash code for the supplied float value.
// */
// public static int hashCode (float f1) {
// return (int)f1; // alas nothing better can be done in JavaScript
// }
//
// /**
// * Returns a hash code for the supplied double value.
// */
// public static int hashCode (double d1) {
// return (int)d1; // alas nothing better can be done in JavaScript
// }
//
// /**
// * Clones the supplied array of bytes.
// */
// public static native byte[] clone (byte[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of ints.
// */
// public static native int[] clone (int[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of floats.
// */
// public static native float[] clone (float[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of doubles.
// */
// public static native double[] clone (double[] values) /*-{
// return values.slice(0);
// }-*/;
// }
// Path: src/main/java/pythagoras/d/Area.java
import pythagoras.util.Platform;
import java.util.NoSuchElementException;
coefs = new double[] { coords[index - 2], coords[index - 1], coords[index],
coords[index + 1], coords[index + 2], coords[index + 3],
coords[index + 4], coords[index + 5] };
isLeft = CrossingHelper.compare(
coords[index - 2], coords[index - 1], point.x(), point.y()) > 0;
GeometryUtil.subCubic(coefs, point.param(isCurrentArea), !isLeft);
if (isLeft) {
System.arraycopy(coefs, 2, temp, coordsCount, 6);
coordsCount += 6;
} else {
System.arraycopy(coefs, 2, temp, coordsCount, 4);
coordsCount += 4;
}
break;
}
}
if (operation == 2 && !isCurrentArea && coordsCount > 2) {
reverseCopy(temp);
System.arraycopy(temp, 0, resultCoords, resultCoordPos, coordsCount);
} else {
System.arraycopy(temp, 0, resultCoords, resultCoordPos, coordsCount);
}
return (resultCoordPos + coordsCount);
}
private void copy (Area src, Area dst) {
dst._coordsSize = src._coordsSize; | dst._coords = Platform.clone(src._coords); |
samskivert/pythagoras | src/main/java/pythagoras/f/Plane.java | // Path: src/gwt/java/pythagoras/util/Platform.java
// public class Platform
// {
// /**
// * Returns a hash code for the supplied float value.
// */
// public static int hashCode (float f1) {
// return (int)f1; // alas nothing better can be done in JavaScript
// }
//
// /**
// * Returns a hash code for the supplied double value.
// */
// public static int hashCode (double d1) {
// return (int)d1; // alas nothing better can be done in JavaScript
// }
//
// /**
// * Clones the supplied array of bytes.
// */
// public static native byte[] clone (byte[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of ints.
// */
// public static native int[] clone (int[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of floats.
// */
// public static native float[] clone (float[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of doubles.
// */
// public static native double[] clone (double[] values) /*-{
// return values.slice(0);
// }-*/;
// }
| import pythagoras.util.Platform;
import java.io.Serializable;
import java.nio.FloatBuffer; | result.constant = -constant;
return result;
}
@Override // from IPlane
public boolean intersection (IRay3 ray, Vector3 result) {
float distance = distance(ray);
if (Float.isNaN(distance) || distance < 0f) {
return false;
} else {
ray.origin().addScaled(ray.direction(), distance, result);
return true;
}
}
@Override // from IPlane
public float distance (IRay3 ray) {
float dividend = -distance(ray.origin());
float divisor = _normal.dot(ray.direction());
if (Math.abs(dividend) < MathUtil.EPSILON) {
return 0f; // origin is on plane
} else if (Math.abs(divisor) < MathUtil.EPSILON) {
return Float.NaN; // ray is parallel to plane
} else {
return dividend / divisor;
}
}
@Override
public int hashCode () { | // Path: src/gwt/java/pythagoras/util/Platform.java
// public class Platform
// {
// /**
// * Returns a hash code for the supplied float value.
// */
// public static int hashCode (float f1) {
// return (int)f1; // alas nothing better can be done in JavaScript
// }
//
// /**
// * Returns a hash code for the supplied double value.
// */
// public static int hashCode (double d1) {
// return (int)d1; // alas nothing better can be done in JavaScript
// }
//
// /**
// * Clones the supplied array of bytes.
// */
// public static native byte[] clone (byte[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of ints.
// */
// public static native int[] clone (int[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of floats.
// */
// public static native float[] clone (float[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of doubles.
// */
// public static native double[] clone (double[] values) /*-{
// return values.slice(0);
// }-*/;
// }
// Path: src/main/java/pythagoras/f/Plane.java
import pythagoras.util.Platform;
import java.io.Serializable;
import java.nio.FloatBuffer;
result.constant = -constant;
return result;
}
@Override // from IPlane
public boolean intersection (IRay3 ray, Vector3 result) {
float distance = distance(ray);
if (Float.isNaN(distance) || distance < 0f) {
return false;
} else {
ray.origin().addScaled(ray.direction(), distance, result);
return true;
}
}
@Override // from IPlane
public float distance (IRay3 ray) {
float dividend = -distance(ray.origin());
float divisor = _normal.dot(ray.direction());
if (Math.abs(dividend) < MathUtil.EPSILON) {
return 0f; // origin is on plane
} else if (Math.abs(divisor) < MathUtil.EPSILON) {
return Float.NaN; // ray is parallel to plane
} else {
return dividend / divisor;
}
}
@Override
public int hashCode () { | return _normal.hashCode() ^ Platform.hashCode(constant); |
samskivert/pythagoras | src/main/java/pythagoras/d/Vector3.java | // Path: src/gwt/java/pythagoras/util/Platform.java
// public class Platform
// {
// /**
// * Returns a hash code for the supplied float value.
// */
// public static int hashCode (float f1) {
// return (int)f1; // alas nothing better can be done in JavaScript
// }
//
// /**
// * Returns a hash code for the supplied double value.
// */
// public static int hashCode (double d1) {
// return (int)d1; // alas nothing better can be done in JavaScript
// }
//
// /**
// * Clones the supplied array of bytes.
// */
// public static native byte[] clone (byte[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of ints.
// */
// public static native int[] clone (int[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of floats.
// */
// public static native float[] clone (float[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of doubles.
// */
// public static native double[] clone (double[] values) /*-{
// return values.slice(0);
// }-*/;
// }
| import pythagoras.util.Platform;
import java.io.Serializable;
import java.nio.DoubleBuffer; |
@Override // from interface IVector3
public double get (int idx) {
switch (idx) {
case 0: return x;
case 1: return y;
case 2: return z;
}
throw new IndexOutOfBoundsException(String.valueOf(idx));
}
@Override // from interface IVector3
public void get (double[] values) {
values[0] = x;
values[1] = y;
values[2] = z;
}
@Override // from interface IVector3
public DoubleBuffer get (DoubleBuffer buf) {
return buf.put(x).put(y).put(z);
}
@Override
public String toString () {
return "[" + x + ", " + y + ", " + z + "]";
}
@Override
public int hashCode () { | // Path: src/gwt/java/pythagoras/util/Platform.java
// public class Platform
// {
// /**
// * Returns a hash code for the supplied float value.
// */
// public static int hashCode (float f1) {
// return (int)f1; // alas nothing better can be done in JavaScript
// }
//
// /**
// * Returns a hash code for the supplied double value.
// */
// public static int hashCode (double d1) {
// return (int)d1; // alas nothing better can be done in JavaScript
// }
//
// /**
// * Clones the supplied array of bytes.
// */
// public static native byte[] clone (byte[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of ints.
// */
// public static native int[] clone (int[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of floats.
// */
// public static native float[] clone (float[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of doubles.
// */
// public static native double[] clone (double[] values) /*-{
// return values.slice(0);
// }-*/;
// }
// Path: src/main/java/pythagoras/d/Vector3.java
import pythagoras.util.Platform;
import java.io.Serializable;
import java.nio.DoubleBuffer;
@Override // from interface IVector3
public double get (int idx) {
switch (idx) {
case 0: return x;
case 1: return y;
case 2: return z;
}
throw new IndexOutOfBoundsException(String.valueOf(idx));
}
@Override // from interface IVector3
public void get (double[] values) {
values[0] = x;
values[1] = y;
values[2] = z;
}
@Override // from interface IVector3
public DoubleBuffer get (DoubleBuffer buf) {
return buf.put(x).put(y).put(z);
}
@Override
public String toString () {
return "[" + x + ", " + y + ", " + z + "]";
}
@Override
public int hashCode () { | return Platform.hashCode(x) ^ Platform.hashCode(y) ^ Platform.hashCode(z); |
samskivert/pythagoras | src/main/java/pythagoras/f/AbstractCircle.java | // Path: src/gwt/java/pythagoras/util/Platform.java
// public class Platform
// {
// /**
// * Returns a hash code for the supplied float value.
// */
// public static int hashCode (float f1) {
// return (int)f1; // alas nothing better can be done in JavaScript
// }
//
// /**
// * Returns a hash code for the supplied double value.
// */
// public static int hashCode (double d1) {
// return (int)d1; // alas nothing better can be done in JavaScript
// }
//
// /**
// * Clones the supplied array of bytes.
// */
// public static native byte[] clone (byte[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of ints.
// */
// public static native int[] clone (int[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of floats.
// */
// public static native float[] clone (float[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of doubles.
// */
// public static native double[] clone (double[] values) /*-{
// return values.slice(0);
// }-*/;
// }
| import pythagoras.util.Platform; | @Override // from ICircle
public Circle offset (float x, float y) {
return new Circle(x() + x, y() + y, radius());
}
@Override // from ICircle
public Circle offset (float x, float y, Circle result) {
result.set(x() + x, y() + y, radius());
return result;
}
@Override // from ICircle
public Circle clone () {
return new Circle(this);
}
@Override
public boolean equals (Object obj) {
if (obj == this) {
return true;
}
if (obj instanceof AbstractCircle) {
AbstractCircle c = (AbstractCircle)obj;
return x() == c.x() && y() == c.y() && radius() == c.radius();
}
return false;
}
@Override
public int hashCode () { | // Path: src/gwt/java/pythagoras/util/Platform.java
// public class Platform
// {
// /**
// * Returns a hash code for the supplied float value.
// */
// public static int hashCode (float f1) {
// return (int)f1; // alas nothing better can be done in JavaScript
// }
//
// /**
// * Returns a hash code for the supplied double value.
// */
// public static int hashCode (double d1) {
// return (int)d1; // alas nothing better can be done in JavaScript
// }
//
// /**
// * Clones the supplied array of bytes.
// */
// public static native byte[] clone (byte[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of ints.
// */
// public static native int[] clone (int[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of floats.
// */
// public static native float[] clone (float[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of doubles.
// */
// public static native double[] clone (double[] values) /*-{
// return values.slice(0);
// }-*/;
// }
// Path: src/main/java/pythagoras/f/AbstractCircle.java
import pythagoras.util.Platform;
@Override // from ICircle
public Circle offset (float x, float y) {
return new Circle(x() + x, y() + y, radius());
}
@Override // from ICircle
public Circle offset (float x, float y, Circle result) {
result.set(x() + x, y() + y, radius());
return result;
}
@Override // from ICircle
public Circle clone () {
return new Circle(this);
}
@Override
public boolean equals (Object obj) {
if (obj == this) {
return true;
}
if (obj instanceof AbstractCircle) {
AbstractCircle c = (AbstractCircle)obj;
return x() == c.x() && y() == c.y() && radius() == c.radius();
}
return false;
}
@Override
public int hashCode () { | return Platform.hashCode(x()) ^ Platform.hashCode(y()) ^ Platform.hashCode(radius()); |
samskivert/pythagoras | src/main/java/pythagoras/d/AbstractPoint.java | // Path: src/gwt/java/pythagoras/util/Platform.java
// public class Platform
// {
// /**
// * Returns a hash code for the supplied float value.
// */
// public static int hashCode (float f1) {
// return (int)f1; // alas nothing better can be done in JavaScript
// }
//
// /**
// * Returns a hash code for the supplied double value.
// */
// public static int hashCode (double d1) {
// return (int)d1; // alas nothing better can be done in JavaScript
// }
//
// /**
// * Clones the supplied array of bytes.
// */
// public static native byte[] clone (byte[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of ints.
// */
// public static native int[] clone (int[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of floats.
// */
// public static native float[] clone (float[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of doubles.
// */
// public static native double[] clone (double[] values) /*-{
// return values.slice(0);
// }-*/;
// }
| import pythagoras.util.Platform; | public Point rotate (double angle) {
return rotate(angle, new Point());
}
@Override // from IPoint
public Point rotate (double angle, Point result) {
double x = x(), y = y();
double sina = Math.sin(angle), cosa = Math.cos(angle);
return result.set(x*cosa - y*sina, x*sina + y*cosa);
}
@Override // from IPoint
public Point clone () {
return new Point(this);
}
@Override
public boolean equals (Object obj) {
if (obj == this) {
return true;
}
if (obj instanceof AbstractPoint) {
AbstractPoint p = (AbstractPoint)obj;
return x() == p.x() && y() == p.y();
}
return false;
}
@Override
public int hashCode () { | // Path: src/gwt/java/pythagoras/util/Platform.java
// public class Platform
// {
// /**
// * Returns a hash code for the supplied float value.
// */
// public static int hashCode (float f1) {
// return (int)f1; // alas nothing better can be done in JavaScript
// }
//
// /**
// * Returns a hash code for the supplied double value.
// */
// public static int hashCode (double d1) {
// return (int)d1; // alas nothing better can be done in JavaScript
// }
//
// /**
// * Clones the supplied array of bytes.
// */
// public static native byte[] clone (byte[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of ints.
// */
// public static native int[] clone (int[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of floats.
// */
// public static native float[] clone (float[] values) /*-{
// return values.slice(0);
// }-*/;
//
// /**
// * Clones the supplied array of doubles.
// */
// public static native double[] clone (double[] values) /*-{
// return values.slice(0);
// }-*/;
// }
// Path: src/main/java/pythagoras/d/AbstractPoint.java
import pythagoras.util.Platform;
public Point rotate (double angle) {
return rotate(angle, new Point());
}
@Override // from IPoint
public Point rotate (double angle, Point result) {
double x = x(), y = y();
double sina = Math.sin(angle), cosa = Math.cos(angle);
return result.set(x*cosa - y*sina, x*sina + y*cosa);
}
@Override // from IPoint
public Point clone () {
return new Point(this);
}
@Override
public boolean equals (Object obj) {
if (obj == this) {
return true;
}
if (obj instanceof AbstractPoint) {
AbstractPoint p = (AbstractPoint)obj;
return x() == p.x() && y() == p.y();
}
return false;
}
@Override
public int hashCode () { | return Platform.hashCode(x()) ^ Platform.hashCode(y()); |
vert-x3/vertx-infinispan | vertx-infinispan/src/main/java/io/vertx/ext/cluster/infinispan/ClusterHealthCheck.java | // Path: vertx-infinispan/src/main/java/io/vertx/ext/cluster/infinispan/impl/ClusterHealthCheckImpl.java
// public class ClusterHealthCheckImpl implements ClusterHealthCheck {
//
// private final Vertx vertx;
// private final boolean detailed;
//
// public ClusterHealthCheckImpl(Vertx vertx, boolean detailed) {
// this.vertx = vertx;
// this.detailed = detailed;
// }
//
// @Override
// public void handle(Promise<Status> promise) {
// VertxInternal vertxInternal = (VertxInternal) vertx;
// InfinispanClusterManager clusterManager = (InfinispanClusterManager) vertxInternal.getClusterManager();
// EmbeddedCacheManager cacheManager = (EmbeddedCacheManager) clusterManager.getCacheContainer();
// Health health = cacheManager.getHealth();
// HealthStatus healthStatus = health.getClusterHealth().getHealthStatus();
// Status status = new Status().setOk(healthStatus == HealthStatus.HEALTHY);
// if (detailed) {
// status.setData(convert(health));
// }
// promise.complete(status);
// }
//
// private JsonObject convert(Health health) {
// return new JsonObject()
// .put("clusterHealth", convert(health.getClusterHealth()))
// .put("cacheHealth", convert(health.getCacheHealth()));
// }
//
// private JsonObject convert(ClusterHealth clusterHealth) {
// return new JsonObject()
// .put("healthStatus", clusterHealth.getHealthStatus().name())
// .put("clusterName", clusterHealth.getClusterName())
// .put("numberOfNodes", clusterHealth.getNumberOfNodes())
// .put("nodeNames", clusterHealth.getNodeNames().stream()
// .collect(JsonArray::new, JsonArray::add, JsonArray::addAll));
// }
//
// private JsonArray convert(List<CacheHealth> cacheHealths) {
// return cacheHealths.stream()
// .map(cacheHealth -> new JsonObject()
// .put("cacheName", cacheHealth.getCacheName())
// .put("status", cacheHealth.getStatus().name()))
// .collect(JsonArray::new, JsonArray::add, JsonArray::addAll);
// }
// }
| import io.vertx.codegen.annotations.VertxGen;
import io.vertx.core.Handler;
import io.vertx.core.Promise;
import io.vertx.core.Vertx;
import io.vertx.ext.cluster.infinispan.impl.ClusterHealthCheckImpl;
import io.vertx.ext.healthchecks.Status; | /*
* Copyright 2021 Red Hat, Inc.
*
* Red Hat licenses this file to you under the Apache License, version 2.0
* (the "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
package io.vertx.ext.cluster.infinispan;
/**
* A helper to create Vert.x cluster {@link io.vertx.ext.healthchecks.HealthChecks} procedures.
*
* @author Thomas Segismont
*/
@VertxGen
public interface ClusterHealthCheck extends Handler<Promise<Status>> {
/**
* Like {@link #createProcedure(Vertx, boolean)} with {@code details} set to {@code true}.
*/
static ClusterHealthCheck createProcedure(Vertx vertx) {
return createProcedure(vertx, true);
}
/**
* Creates a ready-to-use Vert.x cluster {@link io.vertx.ext.healthchecks.HealthChecks} procedure.
*
* @param vertx the instance of Vert.x, must not be {@code null}
* @param detailed when set to {@code true}, {@link Status} data will be filled with cluster health details
* @return a Vert.x cluster {@link io.vertx.ext.healthchecks.HealthChecks} procedure
*/
static ClusterHealthCheck createProcedure(Vertx vertx, boolean detailed) { | // Path: vertx-infinispan/src/main/java/io/vertx/ext/cluster/infinispan/impl/ClusterHealthCheckImpl.java
// public class ClusterHealthCheckImpl implements ClusterHealthCheck {
//
// private final Vertx vertx;
// private final boolean detailed;
//
// public ClusterHealthCheckImpl(Vertx vertx, boolean detailed) {
// this.vertx = vertx;
// this.detailed = detailed;
// }
//
// @Override
// public void handle(Promise<Status> promise) {
// VertxInternal vertxInternal = (VertxInternal) vertx;
// InfinispanClusterManager clusterManager = (InfinispanClusterManager) vertxInternal.getClusterManager();
// EmbeddedCacheManager cacheManager = (EmbeddedCacheManager) clusterManager.getCacheContainer();
// Health health = cacheManager.getHealth();
// HealthStatus healthStatus = health.getClusterHealth().getHealthStatus();
// Status status = new Status().setOk(healthStatus == HealthStatus.HEALTHY);
// if (detailed) {
// status.setData(convert(health));
// }
// promise.complete(status);
// }
//
// private JsonObject convert(Health health) {
// return new JsonObject()
// .put("clusterHealth", convert(health.getClusterHealth()))
// .put("cacheHealth", convert(health.getCacheHealth()));
// }
//
// private JsonObject convert(ClusterHealth clusterHealth) {
// return new JsonObject()
// .put("healthStatus", clusterHealth.getHealthStatus().name())
// .put("clusterName", clusterHealth.getClusterName())
// .put("numberOfNodes", clusterHealth.getNumberOfNodes())
// .put("nodeNames", clusterHealth.getNodeNames().stream()
// .collect(JsonArray::new, JsonArray::add, JsonArray::addAll));
// }
//
// private JsonArray convert(List<CacheHealth> cacheHealths) {
// return cacheHealths.stream()
// .map(cacheHealth -> new JsonObject()
// .put("cacheName", cacheHealth.getCacheName())
// .put("status", cacheHealth.getStatus().name()))
// .collect(JsonArray::new, JsonArray::add, JsonArray::addAll);
// }
// }
// Path: vertx-infinispan/src/main/java/io/vertx/ext/cluster/infinispan/ClusterHealthCheck.java
import io.vertx.codegen.annotations.VertxGen;
import io.vertx.core.Handler;
import io.vertx.core.Promise;
import io.vertx.core.Vertx;
import io.vertx.ext.cluster.infinispan.impl.ClusterHealthCheckImpl;
import io.vertx.ext.healthchecks.Status;
/*
* Copyright 2021 Red Hat, Inc.
*
* Red Hat licenses this file to you under the Apache License, version 2.0
* (the "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
package io.vertx.ext.cluster.infinispan;
/**
* A helper to create Vert.x cluster {@link io.vertx.ext.healthchecks.HealthChecks} procedures.
*
* @author Thomas Segismont
*/
@VertxGen
public interface ClusterHealthCheck extends Handler<Promise<Status>> {
/**
* Like {@link #createProcedure(Vertx, boolean)} with {@code details} set to {@code true}.
*/
static ClusterHealthCheck createProcedure(Vertx vertx) {
return createProcedure(vertx, true);
}
/**
* Creates a ready-to-use Vert.x cluster {@link io.vertx.ext.healthchecks.HealthChecks} procedure.
*
* @param vertx the instance of Vert.x, must not be {@code null}
* @param detailed when set to {@code true}, {@link Status} data will be filled with cluster health details
* @return a Vert.x cluster {@link io.vertx.ext.healthchecks.HealthChecks} procedure
*/
static ClusterHealthCheck createProcedure(Vertx vertx, boolean detailed) { | return new ClusterHealthCheckImpl(vertx, detailed); |
vert-x3/vertx-infinispan | vertx-web-sstore-infinispan/src/main/java/examples/Examples.java | // Path: vertx-web-sstore-infinispan/src/main/java/io/vertx/ext/web/sstore/infinispan/InfinispanSessionStore.java
// @VertxGen
// public interface InfinispanSessionStore extends SessionStore {
//
// /**
// * Create a new {@link InfinispanSessionStore} for the given configuration.
// *
// * @param vertx vertx instance
// * @param options the configuration
// * @return the new instance
// */
// static InfinispanSessionStore create(Vertx vertx, JsonObject options) {
// InfinispanSessionStoreImpl store = new InfinispanSessionStoreImpl();
// store.init(vertx, options);
// return store;
// }
//
// /**
// * Like {@link #create(Vertx, JsonObject)} but with a pre-configured Infinispan Client.
// *
// * @param vertx vertx instance
// * @param options the configuration
// * @param remoteCacheManager pre-configured Infinispan Client
// * @return the new instance
// */
// @GenIgnore(PERMITTED_TYPE)
// static InfinispanSessionStore create(Vertx vertx, JsonObject options, RemoteCacheManager remoteCacheManager) {
// InfinispanSessionStoreImpl store = new InfinispanSessionStoreImpl();
// store.init(vertx, options, Objects.requireNonNull(remoteCacheManager, "remoteCacheManager is required"));
// return store;
// }
// }
| import io.vertx.core.Vertx;
import io.vertx.core.json.JsonArray;
import io.vertx.core.json.JsonObject;
import io.vertx.ext.web.Router;
import io.vertx.ext.web.handler.SessionHandler;
import io.vertx.ext.web.sstore.SessionStore;
import io.vertx.ext.web.sstore.infinispan.InfinispanSessionStore;
import org.infinispan.client.hotrod.RemoteCacheManager; |
void simpleSetup(Vertx vertx, Router router) {
JsonObject config = new JsonObject()
.put("servers", new JsonArray()
.add(new JsonObject()
.put("host", "server1.datagrid.mycorp.int")
.put("username", "foo")
.put("password", "bar"))
.add(new JsonObject()
.put("host", "server2.datagrid.mycorp.int")
.put("username", "foo")
.put("password", "bar"))
);
SessionStore store = SessionStore.create(vertx, config);
SessionHandler sessionHandler = SessionHandler.create(store);
router.route().handler(sessionHandler);
}
void explicitSetup(Vertx vertx, Router router) {
JsonObject config = new JsonObject()
.put("servers", new JsonArray()
.add(new JsonObject()
.put("host", "server1.datagrid.mycorp.int")
.put("username", "foo")
.put("password", "bar"))
.add(new JsonObject()
.put("host", "server2.datagrid.mycorp.int")
.put("username", "foo")
.put("password", "bar"))
); | // Path: vertx-web-sstore-infinispan/src/main/java/io/vertx/ext/web/sstore/infinispan/InfinispanSessionStore.java
// @VertxGen
// public interface InfinispanSessionStore extends SessionStore {
//
// /**
// * Create a new {@link InfinispanSessionStore} for the given configuration.
// *
// * @param vertx vertx instance
// * @param options the configuration
// * @return the new instance
// */
// static InfinispanSessionStore create(Vertx vertx, JsonObject options) {
// InfinispanSessionStoreImpl store = new InfinispanSessionStoreImpl();
// store.init(vertx, options);
// return store;
// }
//
// /**
// * Like {@link #create(Vertx, JsonObject)} but with a pre-configured Infinispan Client.
// *
// * @param vertx vertx instance
// * @param options the configuration
// * @param remoteCacheManager pre-configured Infinispan Client
// * @return the new instance
// */
// @GenIgnore(PERMITTED_TYPE)
// static InfinispanSessionStore create(Vertx vertx, JsonObject options, RemoteCacheManager remoteCacheManager) {
// InfinispanSessionStoreImpl store = new InfinispanSessionStoreImpl();
// store.init(vertx, options, Objects.requireNonNull(remoteCacheManager, "remoteCacheManager is required"));
// return store;
// }
// }
// Path: vertx-web-sstore-infinispan/src/main/java/examples/Examples.java
import io.vertx.core.Vertx;
import io.vertx.core.json.JsonArray;
import io.vertx.core.json.JsonObject;
import io.vertx.ext.web.Router;
import io.vertx.ext.web.handler.SessionHandler;
import io.vertx.ext.web.sstore.SessionStore;
import io.vertx.ext.web.sstore.infinispan.InfinispanSessionStore;
import org.infinispan.client.hotrod.RemoteCacheManager;
void simpleSetup(Vertx vertx, Router router) {
JsonObject config = new JsonObject()
.put("servers", new JsonArray()
.add(new JsonObject()
.put("host", "server1.datagrid.mycorp.int")
.put("username", "foo")
.put("password", "bar"))
.add(new JsonObject()
.put("host", "server2.datagrid.mycorp.int")
.put("username", "foo")
.put("password", "bar"))
);
SessionStore store = SessionStore.create(vertx, config);
SessionHandler sessionHandler = SessionHandler.create(store);
router.route().handler(sessionHandler);
}
void explicitSetup(Vertx vertx, Router router) {
JsonObject config = new JsonObject()
.put("servers", new JsonArray()
.add(new JsonObject()
.put("host", "server1.datagrid.mycorp.int")
.put("username", "foo")
.put("password", "bar"))
.add(new JsonObject()
.put("host", "server2.datagrid.mycorp.int")
.put("username", "foo")
.put("password", "bar"))
); | InfinispanSessionStore store = InfinispanSessionStore.create(vertx, config); |
vert-x3/vertx-infinispan | vertx-infinispan/src/test/java/io/vertx/ext/cluster/infinispan/ClusterHealthCheckTest.java | // Path: vertx-infinispan/src/test/java/io/vertx/Lifecycle.java
// public class Lifecycle {
//
// private static final Logger log = LoggerFactory.getLogger(Lifecycle.class);
//
// public static void closeClustered(List<Vertx> clustered) throws Exception {
// for (Vertx vertx : clustered) {
// VertxInternal vertxInternal = (VertxInternal) vertx;
//
// InfinispanClusterManager clusterManager = getInfinispanClusterManager(vertxInternal.getClusterManager());
//
// ComponentStatus status = null;
// if (clusterManager != null) {
// EmbeddedCacheManager cacheManager = (EmbeddedCacheManager) clusterManager.getCacheContainer();
// status = cacheManager.getStatus();
//
// Health health = cacheManager.getHealth();
//
// SECONDS.sleep(2); // Make sure rebalancing has been triggered
//
// long start = System.currentTimeMillis();
// try {
// while (health.getClusterHealth().getHealthStatus() != HealthStatus.HEALTHY
// && System.currentTimeMillis() - start < MILLISECONDS.convert(2, MINUTES)) {
// MILLISECONDS.sleep(100);
// }
// } catch (Exception ignore) {
// }
// }
//
// if (status == null || status.compareTo(STOPPING) >= 0) {
// vertxInternal.close();
// } else {
// CountDownLatch latch = new CountDownLatch(1);
// vertxInternal.close(ar -> {
// if (ar.failed()) {
// log.error("Failed to shutdown vert.x", ar.cause());
// }
// latch.countDown();
// });
// latch.await(2, TimeUnit.MINUTES);
// }
// }
// }
//
// private static InfinispanClusterManager getInfinispanClusterManager(ClusterManager cm) {
// if (cm == null) {
// return null;
// }
// if (cm instanceof WrappedClusterManager) {
// return getInfinispanClusterManager(((WrappedClusterManager) cm).getDelegate());
// }
// if (cm instanceof InfinispanClusterManager) {
// return (InfinispanClusterManager) cm;
// }
// throw new ClassCastException("Unexpected cluster manager implementation: " + cm.getClass());
// }
//
// private Lifecycle() {
// // Utility
// }
// }
| import static org.hamcrest.CoreMatchers.is;
import static org.infinispan.health.HealthStatus.HEALTHY;
import static org.infinispan.health.HealthStatus.HEALTHY_REBALANCING;
import io.vertx.Lifecycle;
import io.vertx.core.*;
import io.vertx.core.json.JsonObject;
import io.vertx.core.spi.cluster.ClusterManager;
import io.vertx.test.core.VertxTestBase;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import java.util.List;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import static org.hamcrest.CoreMatchers.anyOf; | super.setUp();
}
@Override
protected void clusteredVertx(VertxOptions options, Handler<AsyncResult<Vertx>> ar) {
CountDownLatch latch = new CountDownLatch(1);
Promise<Vertx> promise = Promise.promise();
promise.future().onComplete(ar);
super.clusteredVertx(options, asyncResult -> {
if (asyncResult.succeeded()) {
promise.complete(asyncResult.result());
} else {
promise.fail(asyncResult.cause());
}
latch.countDown();
});
try {
assertTrue(latch.await(2, TimeUnit.MINUTES));
} catch (InterruptedException e) {
fail(e.getMessage());
}
}
@Override
protected ClusterManager getClusterManager() {
return new InfinispanClusterManager();
}
@Override
protected void closeClustered(List<Vertx> clustered) throws Exception { | // Path: vertx-infinispan/src/test/java/io/vertx/Lifecycle.java
// public class Lifecycle {
//
// private static final Logger log = LoggerFactory.getLogger(Lifecycle.class);
//
// public static void closeClustered(List<Vertx> clustered) throws Exception {
// for (Vertx vertx : clustered) {
// VertxInternal vertxInternal = (VertxInternal) vertx;
//
// InfinispanClusterManager clusterManager = getInfinispanClusterManager(vertxInternal.getClusterManager());
//
// ComponentStatus status = null;
// if (clusterManager != null) {
// EmbeddedCacheManager cacheManager = (EmbeddedCacheManager) clusterManager.getCacheContainer();
// status = cacheManager.getStatus();
//
// Health health = cacheManager.getHealth();
//
// SECONDS.sleep(2); // Make sure rebalancing has been triggered
//
// long start = System.currentTimeMillis();
// try {
// while (health.getClusterHealth().getHealthStatus() != HealthStatus.HEALTHY
// && System.currentTimeMillis() - start < MILLISECONDS.convert(2, MINUTES)) {
// MILLISECONDS.sleep(100);
// }
// } catch (Exception ignore) {
// }
// }
//
// if (status == null || status.compareTo(STOPPING) >= 0) {
// vertxInternal.close();
// } else {
// CountDownLatch latch = new CountDownLatch(1);
// vertxInternal.close(ar -> {
// if (ar.failed()) {
// log.error("Failed to shutdown vert.x", ar.cause());
// }
// latch.countDown();
// });
// latch.await(2, TimeUnit.MINUTES);
// }
// }
// }
//
// private static InfinispanClusterManager getInfinispanClusterManager(ClusterManager cm) {
// if (cm == null) {
// return null;
// }
// if (cm instanceof WrappedClusterManager) {
// return getInfinispanClusterManager(((WrappedClusterManager) cm).getDelegate());
// }
// if (cm instanceof InfinispanClusterManager) {
// return (InfinispanClusterManager) cm;
// }
// throw new ClassCastException("Unexpected cluster manager implementation: " + cm.getClass());
// }
//
// private Lifecycle() {
// // Utility
// }
// }
// Path: vertx-infinispan/src/test/java/io/vertx/ext/cluster/infinispan/ClusterHealthCheckTest.java
import static org.hamcrest.CoreMatchers.is;
import static org.infinispan.health.HealthStatus.HEALTHY;
import static org.infinispan.health.HealthStatus.HEALTHY_REBALANCING;
import io.vertx.Lifecycle;
import io.vertx.core.*;
import io.vertx.core.json.JsonObject;
import io.vertx.core.spi.cluster.ClusterManager;
import io.vertx.test.core.VertxTestBase;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import java.util.List;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import static org.hamcrest.CoreMatchers.anyOf;
super.setUp();
}
@Override
protected void clusteredVertx(VertxOptions options, Handler<AsyncResult<Vertx>> ar) {
CountDownLatch latch = new CountDownLatch(1);
Promise<Vertx> promise = Promise.promise();
promise.future().onComplete(ar);
super.clusteredVertx(options, asyncResult -> {
if (asyncResult.succeeded()) {
promise.complete(asyncResult.result());
} else {
promise.fail(asyncResult.cause());
}
latch.countDown();
});
try {
assertTrue(latch.await(2, TimeUnit.MINUTES));
} catch (InterruptedException e) {
fail(e.getMessage());
}
}
@Override
protected ClusterManager getClusterManager() {
return new InfinispanClusterManager();
}
@Override
protected void closeClustered(List<Vertx> clustered) throws Exception { | Lifecycle.closeClustered(clustered); |
vert-x3/vertx-infinispan | vertx-web-sstore-infinispan/src/test/java/io/vertx/ext/web/sstore/infinispan/impl/InfinispanSessionHandlerTest.java | // Path: vertx-web-sstore-infinispan/src/main/java/io/vertx/ext/web/sstore/infinispan/InfinispanSessionStore.java
// @VertxGen
// public interface InfinispanSessionStore extends SessionStore {
//
// /**
// * Create a new {@link InfinispanSessionStore} for the given configuration.
// *
// * @param vertx vertx instance
// * @param options the configuration
// * @return the new instance
// */
// static InfinispanSessionStore create(Vertx vertx, JsonObject options) {
// InfinispanSessionStoreImpl store = new InfinispanSessionStoreImpl();
// store.init(vertx, options);
// return store;
// }
//
// /**
// * Like {@link #create(Vertx, JsonObject)} but with a pre-configured Infinispan Client.
// *
// * @param vertx vertx instance
// * @param options the configuration
// * @param remoteCacheManager pre-configured Infinispan Client
// * @return the new instance
// */
// @GenIgnore(PERMITTED_TYPE)
// static InfinispanSessionStore create(Vertx vertx, JsonObject options, RemoteCacheManager remoteCacheManager) {
// InfinispanSessionStoreImpl store = new InfinispanSessionStoreImpl();
// store.init(vertx, options, Objects.requireNonNull(remoteCacheManager, "remoteCacheManager is required"));
// return store;
// }
// }
| import io.vertx.core.json.JsonArray;
import io.vertx.core.json.JsonObject;
import io.vertx.ext.web.handler.SessionHandlerTestBase;
import io.vertx.ext.web.sstore.infinispan.InfinispanSessionStore;
import org.junit.ClassRule;
import org.testcontainers.containers.BindMode;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.containers.wait.strategy.LogMessageWaitStrategy;
import static org.infinispan.client.hotrod.impl.ConfigurationProperties.DEFAULT_HOTROD_PORT; | /*
* Copyright 2021 Red Hat, Inc.
*
* Red Hat licenses this file to you under the Apache License, version 2.0
* (the "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
package io.vertx.ext.web.sstore.infinispan.impl;
public class InfinispanSessionHandlerTest extends SessionHandlerTestBase {
private static final String IDENTITIES_PATH = "/user-config/identities.yaml";
private static final String USER = "foo";
private static final String PASS = "bar";
@ClassRule
public static GenericContainer<?> container =
new GenericContainer<>("infinispan/server:12.1")
.withExposedPorts(DEFAULT_HOTROD_PORT)
.withClasspathResourceMapping("identities.yaml", "/user-config/identities.yaml", BindMode.READ_ONLY)
.withEnv("IDENTITIES_PATH", IDENTITIES_PATH)
.waitingFor(new LogMessageWaitStrategy().withRegEx(".*Infinispan Server.*started in.*\\s"));
@Override
public void setUp() throws Exception {
super.setUp();
JsonObject config = new JsonObject()
.put("servers", new JsonArray().add(new JsonObject()
.put("host", container.getHost())
.put("port", container.getMappedPort(DEFAULT_HOTROD_PORT))
.put("username", USER)
.put("password", PASS)
)); | // Path: vertx-web-sstore-infinispan/src/main/java/io/vertx/ext/web/sstore/infinispan/InfinispanSessionStore.java
// @VertxGen
// public interface InfinispanSessionStore extends SessionStore {
//
// /**
// * Create a new {@link InfinispanSessionStore} for the given configuration.
// *
// * @param vertx vertx instance
// * @param options the configuration
// * @return the new instance
// */
// static InfinispanSessionStore create(Vertx vertx, JsonObject options) {
// InfinispanSessionStoreImpl store = new InfinispanSessionStoreImpl();
// store.init(vertx, options);
// return store;
// }
//
// /**
// * Like {@link #create(Vertx, JsonObject)} but with a pre-configured Infinispan Client.
// *
// * @param vertx vertx instance
// * @param options the configuration
// * @param remoteCacheManager pre-configured Infinispan Client
// * @return the new instance
// */
// @GenIgnore(PERMITTED_TYPE)
// static InfinispanSessionStore create(Vertx vertx, JsonObject options, RemoteCacheManager remoteCacheManager) {
// InfinispanSessionStoreImpl store = new InfinispanSessionStoreImpl();
// store.init(vertx, options, Objects.requireNonNull(remoteCacheManager, "remoteCacheManager is required"));
// return store;
// }
// }
// Path: vertx-web-sstore-infinispan/src/test/java/io/vertx/ext/web/sstore/infinispan/impl/InfinispanSessionHandlerTest.java
import io.vertx.core.json.JsonArray;
import io.vertx.core.json.JsonObject;
import io.vertx.ext.web.handler.SessionHandlerTestBase;
import io.vertx.ext.web.sstore.infinispan.InfinispanSessionStore;
import org.junit.ClassRule;
import org.testcontainers.containers.BindMode;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.containers.wait.strategy.LogMessageWaitStrategy;
import static org.infinispan.client.hotrod.impl.ConfigurationProperties.DEFAULT_HOTROD_PORT;
/*
* Copyright 2021 Red Hat, Inc.
*
* Red Hat licenses this file to you under the Apache License, version 2.0
* (the "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
package io.vertx.ext.web.sstore.infinispan.impl;
public class InfinispanSessionHandlerTest extends SessionHandlerTestBase {
private static final String IDENTITIES_PATH = "/user-config/identities.yaml";
private static final String USER = "foo";
private static final String PASS = "bar";
@ClassRule
public static GenericContainer<?> container =
new GenericContainer<>("infinispan/server:12.1")
.withExposedPorts(DEFAULT_HOTROD_PORT)
.withClasspathResourceMapping("identities.yaml", "/user-config/identities.yaml", BindMode.READ_ONLY)
.withEnv("IDENTITIES_PATH", IDENTITIES_PATH)
.waitingFor(new LogMessageWaitStrategy().withRegEx(".*Infinispan Server.*started in.*\\s"));
@Override
public void setUp() throws Exception {
super.setUp();
JsonObject config = new JsonObject()
.put("servers", new JsonArray().add(new JsonObject()
.put("host", container.getHost())
.put("port", container.getMappedPort(DEFAULT_HOTROD_PORT))
.put("username", USER)
.put("password", PASS)
)); | store = InfinispanSessionStore.create(vertx, config); |
darko1002001/android-rest-client | android-rest-lib/src/main/java/com/dg/libs/rest/handlers/ResponseHandler.java | // Path: android-rest-lib/src/main/java/com/dg/libs/rest/callbacks/HttpCallback.java
// public interface HttpCallback<T> {
//
// /**
// * This method shows that the callback successfully finished. It contains
// * response data which represents the return type of the callback.
// *
// * @param responseData
// * It can be of any type.
// */
// void onSuccess(T responseData, ResponseStatus responseStatus);
//
// /**
// * This method shows that the callback has failed due to server issue, no
// * connectivity or parser error
// *
// * @param responseStatus
// */
// void onHttpError(ResponseStatus responseStatus);
//
// }
//
// Path: android-rest-lib/src/main/java/com/dg/libs/rest/domain/ResponseStatus.java
// public class ResponseStatus {
//
// public static final String TAG = ResponseStatus.class.getSimpleName();
//
// private int statusCode;
// private String statusMessage;
//
// public ResponseStatus(int statusCode, String statusMessage) {
// this.statusCode = statusCode;
// this.statusMessage = statusMessage;
// }
//
// public ResponseStatus() {
// }
//
// public int getStatusCode() {
// return statusCode;
// }
//
// public void setStatusCode(int statusCode) {
// this.statusCode = statusCode;
// }
//
// public String getStatusMessage() {
// return statusMessage;
// }
//
// public void setStatusMessage(String statusMessage) {
// this.statusMessage = statusMessage;
// }
//
// public static ResponseStatus getConnectionErrorStatus() {
// ResponseStatus status = new ResponseStatus();
// status.setStatusCode(HttpStatus.SC_REQUEST_TIMEOUT);
// status.setStatusMessage("HTTP Connection Error");
// return status;
// }
//
// public static ResponseStatus getParseErrorStatus() {
// ResponseStatus status = new ResponseStatus();
// status.setStatusCode(HttpStatus.SC_BAD_REQUEST);
// status.setStatusMessage("Parser Error");
// return status;
// }
//
// @Override
// public String toString() {
// StringBuilder builder = new StringBuilder();
// builder.append("ResponseStatus [statusCode=");
// builder.append(statusCode);
// builder.append(", statusMessage=");
// builder.append(statusMessage);
// builder.append("]");
// return builder.toString();
// }
//
// }
| import com.dg.libs.rest.callbacks.HttpCallback;
import com.dg.libs.rest.domain.ResponseStatus; | package com.dg.libs.rest.handlers;
public interface ResponseHandler<T> {
public HttpCallback<T> getCallback();
| // Path: android-rest-lib/src/main/java/com/dg/libs/rest/callbacks/HttpCallback.java
// public interface HttpCallback<T> {
//
// /**
// * This method shows that the callback successfully finished. It contains
// * response data which represents the return type of the callback.
// *
// * @param responseData
// * It can be of any type.
// */
// void onSuccess(T responseData, ResponseStatus responseStatus);
//
// /**
// * This method shows that the callback has failed due to server issue, no
// * connectivity or parser error
// *
// * @param responseStatus
// */
// void onHttpError(ResponseStatus responseStatus);
//
// }
//
// Path: android-rest-lib/src/main/java/com/dg/libs/rest/domain/ResponseStatus.java
// public class ResponseStatus {
//
// public static final String TAG = ResponseStatus.class.getSimpleName();
//
// private int statusCode;
// private String statusMessage;
//
// public ResponseStatus(int statusCode, String statusMessage) {
// this.statusCode = statusCode;
// this.statusMessage = statusMessage;
// }
//
// public ResponseStatus() {
// }
//
// public int getStatusCode() {
// return statusCode;
// }
//
// public void setStatusCode(int statusCode) {
// this.statusCode = statusCode;
// }
//
// public String getStatusMessage() {
// return statusMessage;
// }
//
// public void setStatusMessage(String statusMessage) {
// this.statusMessage = statusMessage;
// }
//
// public static ResponseStatus getConnectionErrorStatus() {
// ResponseStatus status = new ResponseStatus();
// status.setStatusCode(HttpStatus.SC_REQUEST_TIMEOUT);
// status.setStatusMessage("HTTP Connection Error");
// return status;
// }
//
// public static ResponseStatus getParseErrorStatus() {
// ResponseStatus status = new ResponseStatus();
// status.setStatusCode(HttpStatus.SC_BAD_REQUEST);
// status.setStatusMessage("Parser Error");
// return status;
// }
//
// @Override
// public String toString() {
// StringBuilder builder = new StringBuilder();
// builder.append("ResponseStatus [statusCode=");
// builder.append(statusCode);
// builder.append(", statusMessage=");
// builder.append(statusMessage);
// builder.append("]");
// return builder.toString();
// }
//
// }
// Path: android-rest-lib/src/main/java/com/dg/libs/rest/handlers/ResponseHandler.java
import com.dg.libs.rest.callbacks.HttpCallback;
import com.dg.libs.rest.domain.ResponseStatus;
package com.dg.libs.rest.handlers;
public interface ResponseHandler<T> {
public HttpCallback<T> getCallback();
| public void handleSuccess(final T responseData, ResponseStatus status); |
darko1002001/android-rest-client | android-rest-lib/src/main/java/com/dg/libs/rest/callbacks/BoundCallback.java | // Path: android-rest-lib/src/main/java/com/dg/libs/rest/domain/ResponseStatus.java
// public class ResponseStatus {
//
// public static final String TAG = ResponseStatus.class.getSimpleName();
//
// private int statusCode;
// private String statusMessage;
//
// public ResponseStatus(int statusCode, String statusMessage) {
// this.statusCode = statusCode;
// this.statusMessage = statusMessage;
// }
//
// public ResponseStatus() {
// }
//
// public int getStatusCode() {
// return statusCode;
// }
//
// public void setStatusCode(int statusCode) {
// this.statusCode = statusCode;
// }
//
// public String getStatusMessage() {
// return statusMessage;
// }
//
// public void setStatusMessage(String statusMessage) {
// this.statusMessage = statusMessage;
// }
//
// public static ResponseStatus getConnectionErrorStatus() {
// ResponseStatus status = new ResponseStatus();
// status.setStatusCode(HttpStatus.SC_REQUEST_TIMEOUT);
// status.setStatusMessage("HTTP Connection Error");
// return status;
// }
//
// public static ResponseStatus getParseErrorStatus() {
// ResponseStatus status = new ResponseStatus();
// status.setStatusCode(HttpStatus.SC_BAD_REQUEST);
// status.setStatusMessage("Parser Error");
// return status;
// }
//
// @Override
// public String toString() {
// StringBuilder builder = new StringBuilder();
// builder.append("ResponseStatus [statusCode=");
// builder.append(statusCode);
// builder.append(", statusMessage=");
// builder.append(statusMessage);
// builder.append("]");
// return builder.toString();
// }
//
// }
| import android.util.Log;
import com.dg.libs.rest.domain.ResponseStatus; | package com.dg.libs.rest.callbacks;
public class BoundCallback<T> implements HttpCallback<T> {
private static final String TAG = BoundCallback.class.getSimpleName();
private HttpCallback<T> callback;
private boolean isRegistered = true;
public BoundCallback(HttpCallback<T> callback) {
this.callback = callback;
}
public void unregister() {
isRegistered = false;
}
public boolean isRegistered() {
return isRegistered;
}
@Override | // Path: android-rest-lib/src/main/java/com/dg/libs/rest/domain/ResponseStatus.java
// public class ResponseStatus {
//
// public static final String TAG = ResponseStatus.class.getSimpleName();
//
// private int statusCode;
// private String statusMessage;
//
// public ResponseStatus(int statusCode, String statusMessage) {
// this.statusCode = statusCode;
// this.statusMessage = statusMessage;
// }
//
// public ResponseStatus() {
// }
//
// public int getStatusCode() {
// return statusCode;
// }
//
// public void setStatusCode(int statusCode) {
// this.statusCode = statusCode;
// }
//
// public String getStatusMessage() {
// return statusMessage;
// }
//
// public void setStatusMessage(String statusMessage) {
// this.statusMessage = statusMessage;
// }
//
// public static ResponseStatus getConnectionErrorStatus() {
// ResponseStatus status = new ResponseStatus();
// status.setStatusCode(HttpStatus.SC_REQUEST_TIMEOUT);
// status.setStatusMessage("HTTP Connection Error");
// return status;
// }
//
// public static ResponseStatus getParseErrorStatus() {
// ResponseStatus status = new ResponseStatus();
// status.setStatusCode(HttpStatus.SC_BAD_REQUEST);
// status.setStatusMessage("Parser Error");
// return status;
// }
//
// @Override
// public String toString() {
// StringBuilder builder = new StringBuilder();
// builder.append("ResponseStatus [statusCode=");
// builder.append(statusCode);
// builder.append(", statusMessage=");
// builder.append(statusMessage);
// builder.append("]");
// return builder.toString();
// }
//
// }
// Path: android-rest-lib/src/main/java/com/dg/libs/rest/callbacks/BoundCallback.java
import android.util.Log;
import com.dg.libs.rest.domain.ResponseStatus;
package com.dg.libs.rest.callbacks;
public class BoundCallback<T> implements HttpCallback<T> {
private static final String TAG = BoundCallback.class.getSimpleName();
private HttpCallback<T> callback;
private boolean isRegistered = true;
public BoundCallback(HttpCallback<T> callback) {
this.callback = callback;
}
public void unregister() {
isRegistered = false;
}
public boolean isRegistered() {
return isRegistered;
}
@Override | public void onSuccess(T responseData, ResponseStatus responseStatus) { |
darko1002001/android-rest-client | android-rest-lib/src/main/java/com/dg/libs/rest/RestClientConfiguration.java | // Path: android-rest-lib/src/main/java/com/dg/libs/rest/authentication/AuthenticationProvider.java
// public interface AuthenticationProvider {
//
// public void authenticateRequest(RestClientRequest restClientRequest);
// }
| import android.content.Context;
import com.araneaapps.android.libs.asyncrunners.models.AsyncRunners;
import com.dg.libs.rest.authentication.AuthenticationProvider; | package com.dg.libs.rest;
public class RestClientConfiguration {
private static Context applicationContext; | // Path: android-rest-lib/src/main/java/com/dg/libs/rest/authentication/AuthenticationProvider.java
// public interface AuthenticationProvider {
//
// public void authenticateRequest(RestClientRequest restClientRequest);
// }
// Path: android-rest-lib/src/main/java/com/dg/libs/rest/RestClientConfiguration.java
import android.content.Context;
import com.araneaapps.android.libs.asyncrunners.models.AsyncRunners;
import com.dg.libs.rest.authentication.AuthenticationProvider;
package com.dg.libs.rest;
public class RestClientConfiguration {
private static Context applicationContext; | private AuthenticationProvider authenticationProvider; |
darko1002001/android-rest-client | android-rest-lib/src/main/java/com/dg/libs/rest/handlers/DefaultResponseStatusHandler.java | // Path: android-rest-lib/src/main/java/com/dg/libs/rest/domain/ResponseStatus.java
// public class ResponseStatus {
//
// public static final String TAG = ResponseStatus.class.getSimpleName();
//
// private int statusCode;
// private String statusMessage;
//
// public ResponseStatus(int statusCode, String statusMessage) {
// this.statusCode = statusCode;
// this.statusMessage = statusMessage;
// }
//
// public ResponseStatus() {
// }
//
// public int getStatusCode() {
// return statusCode;
// }
//
// public void setStatusCode(int statusCode) {
// this.statusCode = statusCode;
// }
//
// public String getStatusMessage() {
// return statusMessage;
// }
//
// public void setStatusMessage(String statusMessage) {
// this.statusMessage = statusMessage;
// }
//
// public static ResponseStatus getConnectionErrorStatus() {
// ResponseStatus status = new ResponseStatus();
// status.setStatusCode(HttpStatus.SC_REQUEST_TIMEOUT);
// status.setStatusMessage("HTTP Connection Error");
// return status;
// }
//
// public static ResponseStatus getParseErrorStatus() {
// ResponseStatus status = new ResponseStatus();
// status.setStatusCode(HttpStatus.SC_BAD_REQUEST);
// status.setStatusMessage("Parser Error");
// return status;
// }
//
// @Override
// public String toString() {
// StringBuilder builder = new StringBuilder();
// builder.append("ResponseStatus [statusCode=");
// builder.append(statusCode);
// builder.append(", statusMessage=");
// builder.append(statusMessage);
// builder.append("]");
// return builder.toString();
// }
//
// }
| import com.dg.libs.rest.domain.ResponseStatus; | package com.dg.libs.rest.handlers;
public class DefaultResponseStatusHandler implements ResponseStatusHandler {
public DefaultResponseStatusHandler() {
super();
}
@Override | // Path: android-rest-lib/src/main/java/com/dg/libs/rest/domain/ResponseStatus.java
// public class ResponseStatus {
//
// public static final String TAG = ResponseStatus.class.getSimpleName();
//
// private int statusCode;
// private String statusMessage;
//
// public ResponseStatus(int statusCode, String statusMessage) {
// this.statusCode = statusCode;
// this.statusMessage = statusMessage;
// }
//
// public ResponseStatus() {
// }
//
// public int getStatusCode() {
// return statusCode;
// }
//
// public void setStatusCode(int statusCode) {
// this.statusCode = statusCode;
// }
//
// public String getStatusMessage() {
// return statusMessage;
// }
//
// public void setStatusMessage(String statusMessage) {
// this.statusMessage = statusMessage;
// }
//
// public static ResponseStatus getConnectionErrorStatus() {
// ResponseStatus status = new ResponseStatus();
// status.setStatusCode(HttpStatus.SC_REQUEST_TIMEOUT);
// status.setStatusMessage("HTTP Connection Error");
// return status;
// }
//
// public static ResponseStatus getParseErrorStatus() {
// ResponseStatus status = new ResponseStatus();
// status.setStatusCode(HttpStatus.SC_BAD_REQUEST);
// status.setStatusMessage("Parser Error");
// return status;
// }
//
// @Override
// public String toString() {
// StringBuilder builder = new StringBuilder();
// builder.append("ResponseStatus [statusCode=");
// builder.append(statusCode);
// builder.append(", statusMessage=");
// builder.append(statusMessage);
// builder.append("]");
// return builder.toString();
// }
//
// }
// Path: android-rest-lib/src/main/java/com/dg/libs/rest/handlers/DefaultResponseStatusHandler.java
import com.dg.libs.rest.domain.ResponseStatus;
package com.dg.libs.rest.handlers;
public class DefaultResponseStatusHandler implements ResponseStatusHandler {
public DefaultResponseStatusHandler() {
super();
}
@Override | public boolean hasErrorInStatus(ResponseStatus status) { |
darko1002001/android-rest-client | android-rest-lib/src/main/java/com/dg/libs/rest/handlers/BackgroundThreadResponseHandler.java | // Path: android-rest-lib/src/main/java/com/dg/libs/rest/callbacks/HttpCallback.java
// public interface HttpCallback<T> {
//
// /**
// * This method shows that the callback successfully finished. It contains
// * response data which represents the return type of the callback.
// *
// * @param responseData
// * It can be of any type.
// */
// void onSuccess(T responseData, ResponseStatus responseStatus);
//
// /**
// * This method shows that the callback has failed due to server issue, no
// * connectivity or parser error
// *
// * @param responseStatus
// */
// void onHttpError(ResponseStatus responseStatus);
//
// }
//
// Path: android-rest-lib/src/main/java/com/dg/libs/rest/domain/ResponseStatus.java
// public class ResponseStatus {
//
// public static final String TAG = ResponseStatus.class.getSimpleName();
//
// private int statusCode;
// private String statusMessage;
//
// public ResponseStatus(int statusCode, String statusMessage) {
// this.statusCode = statusCode;
// this.statusMessage = statusMessage;
// }
//
// public ResponseStatus() {
// }
//
// public int getStatusCode() {
// return statusCode;
// }
//
// public void setStatusCode(int statusCode) {
// this.statusCode = statusCode;
// }
//
// public String getStatusMessage() {
// return statusMessage;
// }
//
// public void setStatusMessage(String statusMessage) {
// this.statusMessage = statusMessage;
// }
//
// public static ResponseStatus getConnectionErrorStatus() {
// ResponseStatus status = new ResponseStatus();
// status.setStatusCode(HttpStatus.SC_REQUEST_TIMEOUT);
// status.setStatusMessage("HTTP Connection Error");
// return status;
// }
//
// public static ResponseStatus getParseErrorStatus() {
// ResponseStatus status = new ResponseStatus();
// status.setStatusCode(HttpStatus.SC_BAD_REQUEST);
// status.setStatusMessage("Parser Error");
// return status;
// }
//
// @Override
// public String toString() {
// StringBuilder builder = new StringBuilder();
// builder.append("ResponseStatus [statusCode=");
// builder.append(statusCode);
// builder.append(", statusMessage=");
// builder.append(statusMessage);
// builder.append("]");
// return builder.toString();
// }
//
// }
| import com.dg.libs.rest.callbacks.HttpCallback;
import com.dg.libs.rest.domain.ResponseStatus; | package com.dg.libs.rest.handlers;
public class BackgroundThreadResponseHandler<T> implements ResponseHandler<T> {
public static final String TAG = BackgroundThreadResponseHandler.class.getSimpleName(); | // Path: android-rest-lib/src/main/java/com/dg/libs/rest/callbacks/HttpCallback.java
// public interface HttpCallback<T> {
//
// /**
// * This method shows that the callback successfully finished. It contains
// * response data which represents the return type of the callback.
// *
// * @param responseData
// * It can be of any type.
// */
// void onSuccess(T responseData, ResponseStatus responseStatus);
//
// /**
// * This method shows that the callback has failed due to server issue, no
// * connectivity or parser error
// *
// * @param responseStatus
// */
// void onHttpError(ResponseStatus responseStatus);
//
// }
//
// Path: android-rest-lib/src/main/java/com/dg/libs/rest/domain/ResponseStatus.java
// public class ResponseStatus {
//
// public static final String TAG = ResponseStatus.class.getSimpleName();
//
// private int statusCode;
// private String statusMessage;
//
// public ResponseStatus(int statusCode, String statusMessage) {
// this.statusCode = statusCode;
// this.statusMessage = statusMessage;
// }
//
// public ResponseStatus() {
// }
//
// public int getStatusCode() {
// return statusCode;
// }
//
// public void setStatusCode(int statusCode) {
// this.statusCode = statusCode;
// }
//
// public String getStatusMessage() {
// return statusMessage;
// }
//
// public void setStatusMessage(String statusMessage) {
// this.statusMessage = statusMessage;
// }
//
// public static ResponseStatus getConnectionErrorStatus() {
// ResponseStatus status = new ResponseStatus();
// status.setStatusCode(HttpStatus.SC_REQUEST_TIMEOUT);
// status.setStatusMessage("HTTP Connection Error");
// return status;
// }
//
// public static ResponseStatus getParseErrorStatus() {
// ResponseStatus status = new ResponseStatus();
// status.setStatusCode(HttpStatus.SC_BAD_REQUEST);
// status.setStatusMessage("Parser Error");
// return status;
// }
//
// @Override
// public String toString() {
// StringBuilder builder = new StringBuilder();
// builder.append("ResponseStatus [statusCode=");
// builder.append(statusCode);
// builder.append(", statusMessage=");
// builder.append(statusMessage);
// builder.append("]");
// return builder.toString();
// }
//
// }
// Path: android-rest-lib/src/main/java/com/dg/libs/rest/handlers/BackgroundThreadResponseHandler.java
import com.dg.libs.rest.callbacks.HttpCallback;
import com.dg.libs.rest.domain.ResponseStatus;
package com.dg.libs.rest.handlers;
public class BackgroundThreadResponseHandler<T> implements ResponseHandler<T> {
public static final String TAG = BackgroundThreadResponseHandler.class.getSimpleName(); | protected final HttpCallback<T> callback; |
darko1002001/android-rest-client | android-rest-lib/src/main/java/com/dg/libs/rest/handlers/BackgroundThreadResponseHandler.java | // Path: android-rest-lib/src/main/java/com/dg/libs/rest/callbacks/HttpCallback.java
// public interface HttpCallback<T> {
//
// /**
// * This method shows that the callback successfully finished. It contains
// * response data which represents the return type of the callback.
// *
// * @param responseData
// * It can be of any type.
// */
// void onSuccess(T responseData, ResponseStatus responseStatus);
//
// /**
// * This method shows that the callback has failed due to server issue, no
// * connectivity or parser error
// *
// * @param responseStatus
// */
// void onHttpError(ResponseStatus responseStatus);
//
// }
//
// Path: android-rest-lib/src/main/java/com/dg/libs/rest/domain/ResponseStatus.java
// public class ResponseStatus {
//
// public static final String TAG = ResponseStatus.class.getSimpleName();
//
// private int statusCode;
// private String statusMessage;
//
// public ResponseStatus(int statusCode, String statusMessage) {
// this.statusCode = statusCode;
// this.statusMessage = statusMessage;
// }
//
// public ResponseStatus() {
// }
//
// public int getStatusCode() {
// return statusCode;
// }
//
// public void setStatusCode(int statusCode) {
// this.statusCode = statusCode;
// }
//
// public String getStatusMessage() {
// return statusMessage;
// }
//
// public void setStatusMessage(String statusMessage) {
// this.statusMessage = statusMessage;
// }
//
// public static ResponseStatus getConnectionErrorStatus() {
// ResponseStatus status = new ResponseStatus();
// status.setStatusCode(HttpStatus.SC_REQUEST_TIMEOUT);
// status.setStatusMessage("HTTP Connection Error");
// return status;
// }
//
// public static ResponseStatus getParseErrorStatus() {
// ResponseStatus status = new ResponseStatus();
// status.setStatusCode(HttpStatus.SC_BAD_REQUEST);
// status.setStatusMessage("Parser Error");
// return status;
// }
//
// @Override
// public String toString() {
// StringBuilder builder = new StringBuilder();
// builder.append("ResponseStatus [statusCode=");
// builder.append(statusCode);
// builder.append(", statusMessage=");
// builder.append(statusMessage);
// builder.append("]");
// return builder.toString();
// }
//
// }
| import com.dg.libs.rest.callbacks.HttpCallback;
import com.dg.libs.rest.domain.ResponseStatus; | package com.dg.libs.rest.handlers;
public class BackgroundThreadResponseHandler<T> implements ResponseHandler<T> {
public static final String TAG = BackgroundThreadResponseHandler.class.getSimpleName();
protected final HttpCallback<T> callback;
public BackgroundThreadResponseHandler(HttpCallback<T> callback) {
this.callback = callback;
}
@Override
public HttpCallback<T> getCallback() {
return callback;
}
@Override | // Path: android-rest-lib/src/main/java/com/dg/libs/rest/callbacks/HttpCallback.java
// public interface HttpCallback<T> {
//
// /**
// * This method shows that the callback successfully finished. It contains
// * response data which represents the return type of the callback.
// *
// * @param responseData
// * It can be of any type.
// */
// void onSuccess(T responseData, ResponseStatus responseStatus);
//
// /**
// * This method shows that the callback has failed due to server issue, no
// * connectivity or parser error
// *
// * @param responseStatus
// */
// void onHttpError(ResponseStatus responseStatus);
//
// }
//
// Path: android-rest-lib/src/main/java/com/dg/libs/rest/domain/ResponseStatus.java
// public class ResponseStatus {
//
// public static final String TAG = ResponseStatus.class.getSimpleName();
//
// private int statusCode;
// private String statusMessage;
//
// public ResponseStatus(int statusCode, String statusMessage) {
// this.statusCode = statusCode;
// this.statusMessage = statusMessage;
// }
//
// public ResponseStatus() {
// }
//
// public int getStatusCode() {
// return statusCode;
// }
//
// public void setStatusCode(int statusCode) {
// this.statusCode = statusCode;
// }
//
// public String getStatusMessage() {
// return statusMessage;
// }
//
// public void setStatusMessage(String statusMessage) {
// this.statusMessage = statusMessage;
// }
//
// public static ResponseStatus getConnectionErrorStatus() {
// ResponseStatus status = new ResponseStatus();
// status.setStatusCode(HttpStatus.SC_REQUEST_TIMEOUT);
// status.setStatusMessage("HTTP Connection Error");
// return status;
// }
//
// public static ResponseStatus getParseErrorStatus() {
// ResponseStatus status = new ResponseStatus();
// status.setStatusCode(HttpStatus.SC_BAD_REQUEST);
// status.setStatusMessage("Parser Error");
// return status;
// }
//
// @Override
// public String toString() {
// StringBuilder builder = new StringBuilder();
// builder.append("ResponseStatus [statusCode=");
// builder.append(statusCode);
// builder.append(", statusMessage=");
// builder.append(statusMessage);
// builder.append("]");
// return builder.toString();
// }
//
// }
// Path: android-rest-lib/src/main/java/com/dg/libs/rest/handlers/BackgroundThreadResponseHandler.java
import com.dg.libs.rest.callbacks.HttpCallback;
import com.dg.libs.rest.domain.ResponseStatus;
package com.dg.libs.rest.handlers;
public class BackgroundThreadResponseHandler<T> implements ResponseHandler<T> {
public static final String TAG = BackgroundThreadResponseHandler.class.getSimpleName();
protected final HttpCallback<T> callback;
public BackgroundThreadResponseHandler(HttpCallback<T> callback) {
this.callback = callback;
}
@Override
public HttpCallback<T> getCallback() {
return callback;
}
@Override | public void handleSuccess(final T responseData, ResponseStatus status) { |
darko1002001/android-rest-client | android-rest-lib/src/main/java/com/dg/libs/rest/handlers/UIThreadResponseHandler.java | // Path: android-rest-lib/src/main/java/com/dg/libs/rest/callbacks/HttpCallback.java
// public interface HttpCallback<T> {
//
// /**
// * This method shows that the callback successfully finished. It contains
// * response data which represents the return type of the callback.
// *
// * @param responseData
// * It can be of any type.
// */
// void onSuccess(T responseData, ResponseStatus responseStatus);
//
// /**
// * This method shows that the callback has failed due to server issue, no
// * connectivity or parser error
// *
// * @param responseStatus
// */
// void onHttpError(ResponseStatus responseStatus);
//
// }
//
// Path: android-rest-lib/src/main/java/com/dg/libs/rest/domain/ResponseStatus.java
// public class ResponseStatus {
//
// public static final String TAG = ResponseStatus.class.getSimpleName();
//
// private int statusCode;
// private String statusMessage;
//
// public ResponseStatus(int statusCode, String statusMessage) {
// this.statusCode = statusCode;
// this.statusMessage = statusMessage;
// }
//
// public ResponseStatus() {
// }
//
// public int getStatusCode() {
// return statusCode;
// }
//
// public void setStatusCode(int statusCode) {
// this.statusCode = statusCode;
// }
//
// public String getStatusMessage() {
// return statusMessage;
// }
//
// public void setStatusMessage(String statusMessage) {
// this.statusMessage = statusMessage;
// }
//
// public static ResponseStatus getConnectionErrorStatus() {
// ResponseStatus status = new ResponseStatus();
// status.setStatusCode(HttpStatus.SC_REQUEST_TIMEOUT);
// status.setStatusMessage("HTTP Connection Error");
// return status;
// }
//
// public static ResponseStatus getParseErrorStatus() {
// ResponseStatus status = new ResponseStatus();
// status.setStatusCode(HttpStatus.SC_BAD_REQUEST);
// status.setStatusMessage("Parser Error");
// return status;
// }
//
// @Override
// public String toString() {
// StringBuilder builder = new StringBuilder();
// builder.append("ResponseStatus [statusCode=");
// builder.append(statusCode);
// builder.append(", statusMessage=");
// builder.append(statusMessage);
// builder.append("]");
// return builder.toString();
// }
//
// }
| import android.os.Handler;
import android.os.Looper;
import com.dg.libs.rest.callbacks.HttpCallback;
import com.dg.libs.rest.domain.ResponseStatus; | package com.dg.libs.rest.handlers;
public class UIThreadResponseHandler<T> extends BackgroundThreadResponseHandler<T>
implements ResponseHandler<T> {
public static final String TAG = UIThreadResponseHandler.class.getSimpleName();
protected static Handler handler;
| // Path: android-rest-lib/src/main/java/com/dg/libs/rest/callbacks/HttpCallback.java
// public interface HttpCallback<T> {
//
// /**
// * This method shows that the callback successfully finished. It contains
// * response data which represents the return type of the callback.
// *
// * @param responseData
// * It can be of any type.
// */
// void onSuccess(T responseData, ResponseStatus responseStatus);
//
// /**
// * This method shows that the callback has failed due to server issue, no
// * connectivity or parser error
// *
// * @param responseStatus
// */
// void onHttpError(ResponseStatus responseStatus);
//
// }
//
// Path: android-rest-lib/src/main/java/com/dg/libs/rest/domain/ResponseStatus.java
// public class ResponseStatus {
//
// public static final String TAG = ResponseStatus.class.getSimpleName();
//
// private int statusCode;
// private String statusMessage;
//
// public ResponseStatus(int statusCode, String statusMessage) {
// this.statusCode = statusCode;
// this.statusMessage = statusMessage;
// }
//
// public ResponseStatus() {
// }
//
// public int getStatusCode() {
// return statusCode;
// }
//
// public void setStatusCode(int statusCode) {
// this.statusCode = statusCode;
// }
//
// public String getStatusMessage() {
// return statusMessage;
// }
//
// public void setStatusMessage(String statusMessage) {
// this.statusMessage = statusMessage;
// }
//
// public static ResponseStatus getConnectionErrorStatus() {
// ResponseStatus status = new ResponseStatus();
// status.setStatusCode(HttpStatus.SC_REQUEST_TIMEOUT);
// status.setStatusMessage("HTTP Connection Error");
// return status;
// }
//
// public static ResponseStatus getParseErrorStatus() {
// ResponseStatus status = new ResponseStatus();
// status.setStatusCode(HttpStatus.SC_BAD_REQUEST);
// status.setStatusMessage("Parser Error");
// return status;
// }
//
// @Override
// public String toString() {
// StringBuilder builder = new StringBuilder();
// builder.append("ResponseStatus [statusCode=");
// builder.append(statusCode);
// builder.append(", statusMessage=");
// builder.append(statusMessage);
// builder.append("]");
// return builder.toString();
// }
//
// }
// Path: android-rest-lib/src/main/java/com/dg/libs/rest/handlers/UIThreadResponseHandler.java
import android.os.Handler;
import android.os.Looper;
import com.dg.libs.rest.callbacks.HttpCallback;
import com.dg.libs.rest.domain.ResponseStatus;
package com.dg.libs.rest.handlers;
public class UIThreadResponseHandler<T> extends BackgroundThreadResponseHandler<T>
implements ResponseHandler<T> {
public static final String TAG = UIThreadResponseHandler.class.getSimpleName();
protected static Handler handler;
| public UIThreadResponseHandler(HttpCallback<T> callback) { |
darko1002001/android-rest-client | android-rest-lib/src/main/java/com/dg/libs/rest/handlers/UIThreadResponseHandler.java | // Path: android-rest-lib/src/main/java/com/dg/libs/rest/callbacks/HttpCallback.java
// public interface HttpCallback<T> {
//
// /**
// * This method shows that the callback successfully finished. It contains
// * response data which represents the return type of the callback.
// *
// * @param responseData
// * It can be of any type.
// */
// void onSuccess(T responseData, ResponseStatus responseStatus);
//
// /**
// * This method shows that the callback has failed due to server issue, no
// * connectivity or parser error
// *
// * @param responseStatus
// */
// void onHttpError(ResponseStatus responseStatus);
//
// }
//
// Path: android-rest-lib/src/main/java/com/dg/libs/rest/domain/ResponseStatus.java
// public class ResponseStatus {
//
// public static final String TAG = ResponseStatus.class.getSimpleName();
//
// private int statusCode;
// private String statusMessage;
//
// public ResponseStatus(int statusCode, String statusMessage) {
// this.statusCode = statusCode;
// this.statusMessage = statusMessage;
// }
//
// public ResponseStatus() {
// }
//
// public int getStatusCode() {
// return statusCode;
// }
//
// public void setStatusCode(int statusCode) {
// this.statusCode = statusCode;
// }
//
// public String getStatusMessage() {
// return statusMessage;
// }
//
// public void setStatusMessage(String statusMessage) {
// this.statusMessage = statusMessage;
// }
//
// public static ResponseStatus getConnectionErrorStatus() {
// ResponseStatus status = new ResponseStatus();
// status.setStatusCode(HttpStatus.SC_REQUEST_TIMEOUT);
// status.setStatusMessage("HTTP Connection Error");
// return status;
// }
//
// public static ResponseStatus getParseErrorStatus() {
// ResponseStatus status = new ResponseStatus();
// status.setStatusCode(HttpStatus.SC_BAD_REQUEST);
// status.setStatusMessage("Parser Error");
// return status;
// }
//
// @Override
// public String toString() {
// StringBuilder builder = new StringBuilder();
// builder.append("ResponseStatus [statusCode=");
// builder.append(statusCode);
// builder.append(", statusMessage=");
// builder.append(statusMessage);
// builder.append("]");
// return builder.toString();
// }
//
// }
| import android.os.Handler;
import android.os.Looper;
import com.dg.libs.rest.callbacks.HttpCallback;
import com.dg.libs.rest.domain.ResponseStatus; | package com.dg.libs.rest.handlers;
public class UIThreadResponseHandler<T> extends BackgroundThreadResponseHandler<T>
implements ResponseHandler<T> {
public static final String TAG = UIThreadResponseHandler.class.getSimpleName();
protected static Handler handler;
public UIThreadResponseHandler(HttpCallback<T> callback) {
super(callback);
if (handler == null) {
handler = new Handler(Looper.getMainLooper());
}
}
@Override | // Path: android-rest-lib/src/main/java/com/dg/libs/rest/callbacks/HttpCallback.java
// public interface HttpCallback<T> {
//
// /**
// * This method shows that the callback successfully finished. It contains
// * response data which represents the return type of the callback.
// *
// * @param responseData
// * It can be of any type.
// */
// void onSuccess(T responseData, ResponseStatus responseStatus);
//
// /**
// * This method shows that the callback has failed due to server issue, no
// * connectivity or parser error
// *
// * @param responseStatus
// */
// void onHttpError(ResponseStatus responseStatus);
//
// }
//
// Path: android-rest-lib/src/main/java/com/dg/libs/rest/domain/ResponseStatus.java
// public class ResponseStatus {
//
// public static final String TAG = ResponseStatus.class.getSimpleName();
//
// private int statusCode;
// private String statusMessage;
//
// public ResponseStatus(int statusCode, String statusMessage) {
// this.statusCode = statusCode;
// this.statusMessage = statusMessage;
// }
//
// public ResponseStatus() {
// }
//
// public int getStatusCode() {
// return statusCode;
// }
//
// public void setStatusCode(int statusCode) {
// this.statusCode = statusCode;
// }
//
// public String getStatusMessage() {
// return statusMessage;
// }
//
// public void setStatusMessage(String statusMessage) {
// this.statusMessage = statusMessage;
// }
//
// public static ResponseStatus getConnectionErrorStatus() {
// ResponseStatus status = new ResponseStatus();
// status.setStatusCode(HttpStatus.SC_REQUEST_TIMEOUT);
// status.setStatusMessage("HTTP Connection Error");
// return status;
// }
//
// public static ResponseStatus getParseErrorStatus() {
// ResponseStatus status = new ResponseStatus();
// status.setStatusCode(HttpStatus.SC_BAD_REQUEST);
// status.setStatusMessage("Parser Error");
// return status;
// }
//
// @Override
// public String toString() {
// StringBuilder builder = new StringBuilder();
// builder.append("ResponseStatus [statusCode=");
// builder.append(statusCode);
// builder.append(", statusMessage=");
// builder.append(statusMessage);
// builder.append("]");
// return builder.toString();
// }
//
// }
// Path: android-rest-lib/src/main/java/com/dg/libs/rest/handlers/UIThreadResponseHandler.java
import android.os.Handler;
import android.os.Looper;
import com.dg.libs.rest.callbacks.HttpCallback;
import com.dg.libs.rest.domain.ResponseStatus;
package com.dg.libs.rest.handlers;
public class UIThreadResponseHandler<T> extends BackgroundThreadResponseHandler<T>
implements ResponseHandler<T> {
public static final String TAG = UIThreadResponseHandler.class.getSimpleName();
protected static Handler handler;
public UIThreadResponseHandler(HttpCallback<T> callback) {
super(callback);
if (handler == null) {
handler = new Handler(Looper.getMainLooper());
}
}
@Override | public void handleSuccess(final T responseData, final ResponseStatus status) { |
MiniPa/cjs_ssms | cjs_ssms_web/src/main/java/com/chengjs/cjsssmsweb/service/master/UserManagerServiceImpl.java | // Path: cjs_ssms_web/src/main/java/com/chengjs/cjsssmsweb/common/util/UUIDUtil.java
// public class UUIDUtil {
// public static String uuid(){
// UUID uuid=UUID.randomUUID();
// String str = uuid.toString();
// String uuidStr=str.replace("-", "");
// return uuidStr;
// }
// }
//
// Path: cjs_ssms_web/src/main/java/com/chengjs/cjsssmsweb/mybatis/mapper/dao/UserRolePermissionDao.java
// public interface UserRolePermissionDao extends Mapper<Country> {
//
// UUser findByLogin(UUser user);
//
// int findAllCount(UUser user);
//
// List<UUser> findHotUser();
//
// List<UUser> findByParams(UUser user, RowBounds rowBound);
//
// List<UUser> findAllByQuery(UUser user);
//
// List<UUser> list(Map<String, Object> map);
//
// Long getTotal(Map<String, Object> map);
//
// UUser findUserByUsername(String username);
//
// Set<String> findRoleNames(String username);
//
// Set<String> findPermissionNames(Set<String> roleNames);
//
// Set<String> findRoleNamesByUserName(@Param("userName")String userName);
//
// Set<String> findPermissionNamesByRoleNames(@Param("set")Set<String> roleNames);
//
// UUser findUserByUserName(@Param("userName")String userName);
//
// }
//
// Path: cjs_ssms_web/src/main/java/com/chengjs/cjsssmsweb/mybatis/mapper/master/UUserMapper.java
// public interface UUserMapper extends Mapper<UUser> {
//
// /**
// * 测试通过POJO参数方式获取page
// * @param uuser
// * @return
// */
// List<UUser> gridUsers(UUser uuser);
//
// /**
// * 测试通过Map参数方式获取page
// * @param params
// * @return
// */
// List<Map<String,String>> users(Map<String,String> params);
//
// }
//
// Path: cjs_ssms_web/src/main/java/com/chengjs/cjsssmsweb/mybatis/pojo/master/UUser.java
// @Table(name = "u_user")
// public class UUser {
// @Id
// @Column(name = "id")
// @GeneratedValue(strategy = GenerationType.IDENTITY, generator = "SELECT replace(t.uuid,\"-\",\"\") FROM (SELECT uuid() uuid FROM dual) t")
// private String id;
//
// @Column(name = "username")
// private String username;
//
// @Column(name = "password")
// private String password;
//
// @Column(name = "description")
// private String description;
//
// @Column(name = "discard")
// private String discard;
//
// @Column(name = "createtime")
// private Date createtime;
//
// @Column(name = "modifytime")
// private Date modifytime;
//
// /**
// * @return id
// */
// public String getId() {
// return id;
// }
//
// /**
// * @param id
// */
// public void setId(String id) {
// this.id = id == null ? null : id.trim();
// }
//
// /**
// * @return username
// */
// public String getUsername() {
// return username;
// }
//
// /**
// * @param username
// */
// public void setUsername(String username) {
// this.username = username == null ? null : username.trim();
// }
//
// /**
// * @return password
// */
// public String getPassword() {
// return password;
// }
//
// /**
// * @param password
// */
// public void setPassword(String password) {
// this.password = password == null ? null : password.trim();
// }
//
// /**
// * @return description
// */
// public String getDescription() {
// return description;
// }
//
// /**
// * @param description
// */
// public void setDescription(String description) {
// this.description = description == null ? null : description.trim();
// }
//
// /**
// * @return discard
// */
// public String getDiscard() {
// return discard;
// }
//
// /**
// * @param discard
// */
// public void setDiscard(String discard) {
// this.discard = discard == null ? null : discard.trim();
// }
//
// /**
// * @return createtime
// */
// public Date getCreatetime() {
// return createtime;
// }
//
// /**
// * @param createtime
// */
// public void setCreatetime(Date createtime) {
// this.createtime = createtime;
// }
//
// /**
// * @return modifytime
// */
// public Date getModifytime() {
// return modifytime;
// }
//
// /**
// * @param modifytime
// */
// public void setModifytime(Date modifytime) {
// this.modifytime = modifytime;
// }
// }
| import com.chengjs.cjsssmsweb.common.util.UUIDUtil;
import com.chengjs.cjsssmsweb.mybatis.mapper.dao.UserRolePermissionDao;
import com.chengjs.cjsssmsweb.mybatis.mapper.master.UUserMapper;
import com.chengjs.cjsssmsweb.mybatis.pojo.master.UUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.Set; | package com.chengjs.cjsssmsweb.service.master;
/**
* SelectServiceImpl:
* author: <a href="mailto:[email protected]">chengjs</a>, version:1.0.0, 2017/8/24
*/
@Service("userService")
public class UserManagerServiceImpl implements IUserManagerService {
@Autowired | // Path: cjs_ssms_web/src/main/java/com/chengjs/cjsssmsweb/common/util/UUIDUtil.java
// public class UUIDUtil {
// public static String uuid(){
// UUID uuid=UUID.randomUUID();
// String str = uuid.toString();
// String uuidStr=str.replace("-", "");
// return uuidStr;
// }
// }
//
// Path: cjs_ssms_web/src/main/java/com/chengjs/cjsssmsweb/mybatis/mapper/dao/UserRolePermissionDao.java
// public interface UserRolePermissionDao extends Mapper<Country> {
//
// UUser findByLogin(UUser user);
//
// int findAllCount(UUser user);
//
// List<UUser> findHotUser();
//
// List<UUser> findByParams(UUser user, RowBounds rowBound);
//
// List<UUser> findAllByQuery(UUser user);
//
// List<UUser> list(Map<String, Object> map);
//
// Long getTotal(Map<String, Object> map);
//
// UUser findUserByUsername(String username);
//
// Set<String> findRoleNames(String username);
//
// Set<String> findPermissionNames(Set<String> roleNames);
//
// Set<String> findRoleNamesByUserName(@Param("userName")String userName);
//
// Set<String> findPermissionNamesByRoleNames(@Param("set")Set<String> roleNames);
//
// UUser findUserByUserName(@Param("userName")String userName);
//
// }
//
// Path: cjs_ssms_web/src/main/java/com/chengjs/cjsssmsweb/mybatis/mapper/master/UUserMapper.java
// public interface UUserMapper extends Mapper<UUser> {
//
// /**
// * 测试通过POJO参数方式获取page
// * @param uuser
// * @return
// */
// List<UUser> gridUsers(UUser uuser);
//
// /**
// * 测试通过Map参数方式获取page
// * @param params
// * @return
// */
// List<Map<String,String>> users(Map<String,String> params);
//
// }
//
// Path: cjs_ssms_web/src/main/java/com/chengjs/cjsssmsweb/mybatis/pojo/master/UUser.java
// @Table(name = "u_user")
// public class UUser {
// @Id
// @Column(name = "id")
// @GeneratedValue(strategy = GenerationType.IDENTITY, generator = "SELECT replace(t.uuid,\"-\",\"\") FROM (SELECT uuid() uuid FROM dual) t")
// private String id;
//
// @Column(name = "username")
// private String username;
//
// @Column(name = "password")
// private String password;
//
// @Column(name = "description")
// private String description;
//
// @Column(name = "discard")
// private String discard;
//
// @Column(name = "createtime")
// private Date createtime;
//
// @Column(name = "modifytime")
// private Date modifytime;
//
// /**
// * @return id
// */
// public String getId() {
// return id;
// }
//
// /**
// * @param id
// */
// public void setId(String id) {
// this.id = id == null ? null : id.trim();
// }
//
// /**
// * @return username
// */
// public String getUsername() {
// return username;
// }
//
// /**
// * @param username
// */
// public void setUsername(String username) {
// this.username = username == null ? null : username.trim();
// }
//
// /**
// * @return password
// */
// public String getPassword() {
// return password;
// }
//
// /**
// * @param password
// */
// public void setPassword(String password) {
// this.password = password == null ? null : password.trim();
// }
//
// /**
// * @return description
// */
// public String getDescription() {
// return description;
// }
//
// /**
// * @param description
// */
// public void setDescription(String description) {
// this.description = description == null ? null : description.trim();
// }
//
// /**
// * @return discard
// */
// public String getDiscard() {
// return discard;
// }
//
// /**
// * @param discard
// */
// public void setDiscard(String discard) {
// this.discard = discard == null ? null : discard.trim();
// }
//
// /**
// * @return createtime
// */
// public Date getCreatetime() {
// return createtime;
// }
//
// /**
// * @param createtime
// */
// public void setCreatetime(Date createtime) {
// this.createtime = createtime;
// }
//
// /**
// * @return modifytime
// */
// public Date getModifytime() {
// return modifytime;
// }
//
// /**
// * @param modifytime
// */
// public void setModifytime(Date modifytime) {
// this.modifytime = modifytime;
// }
// }
// Path: cjs_ssms_web/src/main/java/com/chengjs/cjsssmsweb/service/master/UserManagerServiceImpl.java
import com.chengjs.cjsssmsweb.common.util.UUIDUtil;
import com.chengjs.cjsssmsweb.mybatis.mapper.dao.UserRolePermissionDao;
import com.chengjs.cjsssmsweb.mybatis.mapper.master.UUserMapper;
import com.chengjs.cjsssmsweb.mybatis.pojo.master.UUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.Set;
package com.chengjs.cjsssmsweb.service.master;
/**
* SelectServiceImpl:
* author: <a href="mailto:[email protected]">chengjs</a>, version:1.0.0, 2017/8/24
*/
@Service("userService")
public class UserManagerServiceImpl implements IUserManagerService {
@Autowired | private UserRolePermissionDao uURPdao; |
MiniPa/cjs_ssms | cjs_ssms_web/src/main/java/com/chengjs/cjsssmsweb/service/master/UserManagerServiceImpl.java | // Path: cjs_ssms_web/src/main/java/com/chengjs/cjsssmsweb/common/util/UUIDUtil.java
// public class UUIDUtil {
// public static String uuid(){
// UUID uuid=UUID.randomUUID();
// String str = uuid.toString();
// String uuidStr=str.replace("-", "");
// return uuidStr;
// }
// }
//
// Path: cjs_ssms_web/src/main/java/com/chengjs/cjsssmsweb/mybatis/mapper/dao/UserRolePermissionDao.java
// public interface UserRolePermissionDao extends Mapper<Country> {
//
// UUser findByLogin(UUser user);
//
// int findAllCount(UUser user);
//
// List<UUser> findHotUser();
//
// List<UUser> findByParams(UUser user, RowBounds rowBound);
//
// List<UUser> findAllByQuery(UUser user);
//
// List<UUser> list(Map<String, Object> map);
//
// Long getTotal(Map<String, Object> map);
//
// UUser findUserByUsername(String username);
//
// Set<String> findRoleNames(String username);
//
// Set<String> findPermissionNames(Set<String> roleNames);
//
// Set<String> findRoleNamesByUserName(@Param("userName")String userName);
//
// Set<String> findPermissionNamesByRoleNames(@Param("set")Set<String> roleNames);
//
// UUser findUserByUserName(@Param("userName")String userName);
//
// }
//
// Path: cjs_ssms_web/src/main/java/com/chengjs/cjsssmsweb/mybatis/mapper/master/UUserMapper.java
// public interface UUserMapper extends Mapper<UUser> {
//
// /**
// * 测试通过POJO参数方式获取page
// * @param uuser
// * @return
// */
// List<UUser> gridUsers(UUser uuser);
//
// /**
// * 测试通过Map参数方式获取page
// * @param params
// * @return
// */
// List<Map<String,String>> users(Map<String,String> params);
//
// }
//
// Path: cjs_ssms_web/src/main/java/com/chengjs/cjsssmsweb/mybatis/pojo/master/UUser.java
// @Table(name = "u_user")
// public class UUser {
// @Id
// @Column(name = "id")
// @GeneratedValue(strategy = GenerationType.IDENTITY, generator = "SELECT replace(t.uuid,\"-\",\"\") FROM (SELECT uuid() uuid FROM dual) t")
// private String id;
//
// @Column(name = "username")
// private String username;
//
// @Column(name = "password")
// private String password;
//
// @Column(name = "description")
// private String description;
//
// @Column(name = "discard")
// private String discard;
//
// @Column(name = "createtime")
// private Date createtime;
//
// @Column(name = "modifytime")
// private Date modifytime;
//
// /**
// * @return id
// */
// public String getId() {
// return id;
// }
//
// /**
// * @param id
// */
// public void setId(String id) {
// this.id = id == null ? null : id.trim();
// }
//
// /**
// * @return username
// */
// public String getUsername() {
// return username;
// }
//
// /**
// * @param username
// */
// public void setUsername(String username) {
// this.username = username == null ? null : username.trim();
// }
//
// /**
// * @return password
// */
// public String getPassword() {
// return password;
// }
//
// /**
// * @param password
// */
// public void setPassword(String password) {
// this.password = password == null ? null : password.trim();
// }
//
// /**
// * @return description
// */
// public String getDescription() {
// return description;
// }
//
// /**
// * @param description
// */
// public void setDescription(String description) {
// this.description = description == null ? null : description.trim();
// }
//
// /**
// * @return discard
// */
// public String getDiscard() {
// return discard;
// }
//
// /**
// * @param discard
// */
// public void setDiscard(String discard) {
// this.discard = discard == null ? null : discard.trim();
// }
//
// /**
// * @return createtime
// */
// public Date getCreatetime() {
// return createtime;
// }
//
// /**
// * @param createtime
// */
// public void setCreatetime(Date createtime) {
// this.createtime = createtime;
// }
//
// /**
// * @return modifytime
// */
// public Date getModifytime() {
// return modifytime;
// }
//
// /**
// * @param modifytime
// */
// public void setModifytime(Date modifytime) {
// this.modifytime = modifytime;
// }
// }
| import com.chengjs.cjsssmsweb.common.util.UUIDUtil;
import com.chengjs.cjsssmsweb.mybatis.mapper.dao.UserRolePermissionDao;
import com.chengjs.cjsssmsweb.mybatis.mapper.master.UUserMapper;
import com.chengjs.cjsssmsweb.mybatis.pojo.master.UUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.Set; | package com.chengjs.cjsssmsweb.service.master;
/**
* SelectServiceImpl:
* author: <a href="mailto:[email protected]">chengjs</a>, version:1.0.0, 2017/8/24
*/
@Service("userService")
public class UserManagerServiceImpl implements IUserManagerService {
@Autowired
private UserRolePermissionDao uURPdao;
@Autowired | // Path: cjs_ssms_web/src/main/java/com/chengjs/cjsssmsweb/common/util/UUIDUtil.java
// public class UUIDUtil {
// public static String uuid(){
// UUID uuid=UUID.randomUUID();
// String str = uuid.toString();
// String uuidStr=str.replace("-", "");
// return uuidStr;
// }
// }
//
// Path: cjs_ssms_web/src/main/java/com/chengjs/cjsssmsweb/mybatis/mapper/dao/UserRolePermissionDao.java
// public interface UserRolePermissionDao extends Mapper<Country> {
//
// UUser findByLogin(UUser user);
//
// int findAllCount(UUser user);
//
// List<UUser> findHotUser();
//
// List<UUser> findByParams(UUser user, RowBounds rowBound);
//
// List<UUser> findAllByQuery(UUser user);
//
// List<UUser> list(Map<String, Object> map);
//
// Long getTotal(Map<String, Object> map);
//
// UUser findUserByUsername(String username);
//
// Set<String> findRoleNames(String username);
//
// Set<String> findPermissionNames(Set<String> roleNames);
//
// Set<String> findRoleNamesByUserName(@Param("userName")String userName);
//
// Set<String> findPermissionNamesByRoleNames(@Param("set")Set<String> roleNames);
//
// UUser findUserByUserName(@Param("userName")String userName);
//
// }
//
// Path: cjs_ssms_web/src/main/java/com/chengjs/cjsssmsweb/mybatis/mapper/master/UUserMapper.java
// public interface UUserMapper extends Mapper<UUser> {
//
// /**
// * 测试通过POJO参数方式获取page
// * @param uuser
// * @return
// */
// List<UUser> gridUsers(UUser uuser);
//
// /**
// * 测试通过Map参数方式获取page
// * @param params
// * @return
// */
// List<Map<String,String>> users(Map<String,String> params);
//
// }
//
// Path: cjs_ssms_web/src/main/java/com/chengjs/cjsssmsweb/mybatis/pojo/master/UUser.java
// @Table(name = "u_user")
// public class UUser {
// @Id
// @Column(name = "id")
// @GeneratedValue(strategy = GenerationType.IDENTITY, generator = "SELECT replace(t.uuid,\"-\",\"\") FROM (SELECT uuid() uuid FROM dual) t")
// private String id;
//
// @Column(name = "username")
// private String username;
//
// @Column(name = "password")
// private String password;
//
// @Column(name = "description")
// private String description;
//
// @Column(name = "discard")
// private String discard;
//
// @Column(name = "createtime")
// private Date createtime;
//
// @Column(name = "modifytime")
// private Date modifytime;
//
// /**
// * @return id
// */
// public String getId() {
// return id;
// }
//
// /**
// * @param id
// */
// public void setId(String id) {
// this.id = id == null ? null : id.trim();
// }
//
// /**
// * @return username
// */
// public String getUsername() {
// return username;
// }
//
// /**
// * @param username
// */
// public void setUsername(String username) {
// this.username = username == null ? null : username.trim();
// }
//
// /**
// * @return password
// */
// public String getPassword() {
// return password;
// }
//
// /**
// * @param password
// */
// public void setPassword(String password) {
// this.password = password == null ? null : password.trim();
// }
//
// /**
// * @return description
// */
// public String getDescription() {
// return description;
// }
//
// /**
// * @param description
// */
// public void setDescription(String description) {
// this.description = description == null ? null : description.trim();
// }
//
// /**
// * @return discard
// */
// public String getDiscard() {
// return discard;
// }
//
// /**
// * @param discard
// */
// public void setDiscard(String discard) {
// this.discard = discard == null ? null : discard.trim();
// }
//
// /**
// * @return createtime
// */
// public Date getCreatetime() {
// return createtime;
// }
//
// /**
// * @param createtime
// */
// public void setCreatetime(Date createtime) {
// this.createtime = createtime;
// }
//
// /**
// * @return modifytime
// */
// public Date getModifytime() {
// return modifytime;
// }
//
// /**
// * @param modifytime
// */
// public void setModifytime(Date modifytime) {
// this.modifytime = modifytime;
// }
// }
// Path: cjs_ssms_web/src/main/java/com/chengjs/cjsssmsweb/service/master/UserManagerServiceImpl.java
import com.chengjs.cjsssmsweb.common.util.UUIDUtil;
import com.chengjs.cjsssmsweb.mybatis.mapper.dao.UserRolePermissionDao;
import com.chengjs.cjsssmsweb.mybatis.mapper.master.UUserMapper;
import com.chengjs.cjsssmsweb.mybatis.pojo.master.UUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.Set;
package com.chengjs.cjsssmsweb.service.master;
/**
* SelectServiceImpl:
* author: <a href="mailto:[email protected]">chengjs</a>, version:1.0.0, 2017/8/24
*/
@Service("userService")
public class UserManagerServiceImpl implements IUserManagerService {
@Autowired
private UserRolePermissionDao uURPdao;
@Autowired | private UUserMapper userMapper; |
MiniPa/cjs_ssms | cjs_ssms_web/src/main/java/com/chengjs/cjsssmsweb/components/cxf/impl/WSSampleImpl.java | // Path: cjs_ssms_web/src/main/java/com/chengjs/cjsssmsweb/components/cxf/WSSample.java
// @WebService
// public interface WSSample {
//
// public String say(String str);
//
// }
| import com.chengjs.cjsssmsweb.components.cxf.WSSample;
import org.springframework.stereotype.Component;
import javax.jws.WebService; | package com.chengjs.cjsssmsweb.components.cxf.impl;
/**
* WSSampleImpl:
* @author: <a href="mailto:[email protected]">chengjs</a>, version:1.0.0, 14:57
*/
@Component("wSSample")
@WebService | // Path: cjs_ssms_web/src/main/java/com/chengjs/cjsssmsweb/components/cxf/WSSample.java
// @WebService
// public interface WSSample {
//
// public String say(String str);
//
// }
// Path: cjs_ssms_web/src/main/java/com/chengjs/cjsssmsweb/components/cxf/impl/WSSampleImpl.java
import com.chengjs.cjsssmsweb.components.cxf.WSSample;
import org.springframework.stereotype.Component;
import javax.jws.WebService;
package com.chengjs.cjsssmsweb.components.cxf.impl;
/**
* WSSampleImpl:
* @author: <a href="mailto:[email protected]">chengjs</a>, version:1.0.0, 14:57
*/
@Component("wSSample")
@WebService | public class WSSampleImpl implements WSSample { |
MiniPa/cjs_ssms | cjs_ssms_web/src/main/java/com/chengjs/cjsssmsweb/enums/TestEnv.java | // Path: cjs_ssms_web/src/main/java/com/chengjs/cjsssmsweb/common/util/resources/PropertiesUtil.java
// public class PropertiesUtil {
//
// private static Logger log = LoggerFactory.getLogger(PropertiesUtil.class);
//
// private static Properties prop = new Properties();
//
// private Long lastModified = 0l;// TODO 热加载
//
// static {
// try {
// prop.load(PropertiesUtil.class.getResourceAsStream(EnvEnum.CJS_SSMS_PROP_PATH.val()));
// //转码处理
// Set<Object> keyset = prop.keySet();
// Iterator<Object> iter = keyset.iterator();
// while (iter.hasNext()) {
// String key = (String) iter.next();
// String newValue = null;
// try {
// //属性配置文件自身的编码
// String propertiesFileEncode = "utf-8";
// newValue = new String(prop.getProperty(key).getBytes("ISO-8859-1"), propertiesFileEncode);
// } catch (UnsupportedEncodingException e) {
// newValue = prop.getProperty(key);
// }
// prop.setProperty(key, newValue);
// }
//
// } catch (Exception e) {
// log.error("读取"+EnvEnum.CJS_SSMS_PROP_PATH.val()+"出错!", e);
// }
// }
//
// private static Properties getProp() {
// return prop;
// }
//
// public static void main(String[] args) {
// log.debug(String.valueOf(getProp()));
// }
//
// public static String getValue(String param){
// return getProp().getProperty(param);
// };
//
// }
| import com.chengjs.cjsssmsweb.common.util.resources.PropertiesUtil; | package com.chengjs.cjsssmsweb.enums;
/**
* TestEnv: 测试环境各种开关类
*
* @author: <a href="mailto:[email protected]">chengjs_minipa</a>, version:1.0.0, 2017/8/31
*/
public class TestEnv {
/**
* 当测试开启时,onTTrue为 true
*/
public static boolean onTTrue = true;
/**
* 当测试开启时, onTFalse为 false
*/
public static boolean onTFalse = false;
public TestEnv() { | // Path: cjs_ssms_web/src/main/java/com/chengjs/cjsssmsweb/common/util/resources/PropertiesUtil.java
// public class PropertiesUtil {
//
// private static Logger log = LoggerFactory.getLogger(PropertiesUtil.class);
//
// private static Properties prop = new Properties();
//
// private Long lastModified = 0l;// TODO 热加载
//
// static {
// try {
// prop.load(PropertiesUtil.class.getResourceAsStream(EnvEnum.CJS_SSMS_PROP_PATH.val()));
// //转码处理
// Set<Object> keyset = prop.keySet();
// Iterator<Object> iter = keyset.iterator();
// while (iter.hasNext()) {
// String key = (String) iter.next();
// String newValue = null;
// try {
// //属性配置文件自身的编码
// String propertiesFileEncode = "utf-8";
// newValue = new String(prop.getProperty(key).getBytes("ISO-8859-1"), propertiesFileEncode);
// } catch (UnsupportedEncodingException e) {
// newValue = prop.getProperty(key);
// }
// prop.setProperty(key, newValue);
// }
//
// } catch (Exception e) {
// log.error("读取"+EnvEnum.CJS_SSMS_PROP_PATH.val()+"出错!", e);
// }
// }
//
// private static Properties getProp() {
// return prop;
// }
//
// public static void main(String[] args) {
// log.debug(String.valueOf(getProp()));
// }
//
// public static String getValue(String param){
// return getProp().getProperty(param);
// };
//
// }
// Path: cjs_ssms_web/src/main/java/com/chengjs/cjsssmsweb/enums/TestEnv.java
import com.chengjs.cjsssmsweb.common.util.resources.PropertiesUtil;
package com.chengjs.cjsssmsweb.enums;
/**
* TestEnv: 测试环境各种开关类
*
* @author: <a href="mailto:[email protected]">chengjs_minipa</a>, version:1.0.0, 2017/8/31
*/
public class TestEnv {
/**
* 当测试开启时,onTTrue为 true
*/
public static boolean onTTrue = true;
/**
* 当测试开启时, onTFalse为 false
*/
public static boolean onTFalse = false;
public TestEnv() { | String testEnv = PropertiesUtil.getValue("test"); |
MiniPa/cjs_ssms | cjs_ssms_web/src/main/java/com/chengjs/cjsssmsweb/controller/WebSocketController.java | // Path: cjs_ssms_web/src/main/java/com/chengjs/cjsssmsweb/mybatis/pojo/master/SocketContent.java
// @Table(name = "socket_content")
// public class SocketContent {
// @Id
// @Column(name = "id")
// @GeneratedValue(strategy = GenerationType.IDENTITY, generator = "SELECT replace(t.uuid,\"-\",\"\") FROM (SELECT uuid() uuid FROM dual) t")
// private String id;
//
// /**
// * 发送者
// */
// @Column(name = "contentsender")
// private String contentsender;
//
// /**
// * 聊天内容
// */
// @Column(name = "content")
// private String content;
//
// @Column(name = "createtime")
// private Date createtime;
//
// /**
// * @return id
// */
// public String getId() {
// return id;
// }
//
// /**
// * @param id
// */
// public void setId(String id) {
// this.id = id == null ? null : id.trim();
// }
//
// /**
// * 获取发送者
// *
// * @return contentsender - 发送者
// */
// public String getContentsender() {
// return contentsender;
// }
//
// /**
// * 设置发送者
// *
// * @param contentsender 发送者
// */
// public void setContentsender(String contentsender) {
// this.contentsender = contentsender == null ? null : contentsender.trim();
// }
//
// /**
// * 获取聊天内容
// *
// * @return content - 聊天内容
// */
// public String getContent() {
// return content;
// }
//
// /**
// * 设置聊天内容
// *
// * @param content 聊天内容
// */
// public void setContent(String content) {
// this.content = content == null ? null : content.trim();
// }
//
// /**
// * @return createtime
// */
// public Date getCreatetime() {
// return createtime;
// }
//
// /**
// * @param createtime
// */
// public void setCreatetime(Date createtime) {
// this.createtime = createtime;
// }
// }
//
// Path: cjs_ssms_web/src/main/java/com/chengjs/cjsssmsweb/service/master/ISocketContentService.java
// public interface ISocketContentService {
//
// List<SocketContent> findSocketContentList();
//
// int insertSelective(SocketContent socketContent);
//
// }
//
// Path: cjs_ssms_web/src/main/java/com/chengjs/cjsssmsweb/common/util/UUIDUtil.java
// public class UUIDUtil {
// public static String uuid(){
// UUID uuid=UUID.randomUUID();
// String str = uuid.toString();
// String uuidStr=str.replace("-", "");
// return uuidStr;
// }
// }
| import com.chengjs.cjsssmsweb.mybatis.pojo.master.SocketContent;
import com.chengjs.cjsssmsweb.service.master.ISocketContentService;
import com.chengjs.cjsssmsweb.common.util.UUIDUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.socket.server.standard.SpringConfigurator;
import javax.websocket.OnClose;
import javax.websocket.OnError;
import javax.websocket.OnMessage;
import javax.websocket.OnOpen;
import javax.websocket.Session;
import javax.websocket.server.ServerEndpoint;
import java.io.IOException;
import java.security.Principal;
import java.util.Date;
import java.util.concurrent.CopyOnWriteArraySet; | package com.chengjs.cjsssmsweb.controller;
/**
* WebSocketController:
*
* 类似Servlet的注解mapping。无需在web.xml中配置。
* configurator = SpringConfigurator.class是为了使该类可以通过Spring注入。
*
* 该注解用来指定一个URI,客户端可以通过这个URI来连接到WebSocket。
*
* @author: <a href="mailto:[email protected]">chengjs</a>, version:1.0.0, 16:58
*/
@ServerEndpoint(value = "/websocket", configurator = SpringConfigurator.class)
public class WebSocketController {
private static final Logger log = LoggerFactory.getLogger(WebSocketController.class);
/**
* TODO 静态变量,用来记录当前在线连接数。应该把它设计成线程安全的。
*/
private static int onlineCount = 0;
/**
* concurrent包的线程安全Set,用来存放每个客户端对应的MyWebSocket对象。
* 若要实现服务端与单一客户端通信的话,可以使用Map来存放,其中Key可以为用户标识
*/
private static CopyOnWriteArraySet<WebSocketController> webSocketSet = new CopyOnWriteArraySet<WebSocketController>();
/**
* 与客户端的连接会话,需要通过它来给客户端发送数据
*/
private Session session;
@Autowired | // Path: cjs_ssms_web/src/main/java/com/chengjs/cjsssmsweb/mybatis/pojo/master/SocketContent.java
// @Table(name = "socket_content")
// public class SocketContent {
// @Id
// @Column(name = "id")
// @GeneratedValue(strategy = GenerationType.IDENTITY, generator = "SELECT replace(t.uuid,\"-\",\"\") FROM (SELECT uuid() uuid FROM dual) t")
// private String id;
//
// /**
// * 发送者
// */
// @Column(name = "contentsender")
// private String contentsender;
//
// /**
// * 聊天内容
// */
// @Column(name = "content")
// private String content;
//
// @Column(name = "createtime")
// private Date createtime;
//
// /**
// * @return id
// */
// public String getId() {
// return id;
// }
//
// /**
// * @param id
// */
// public void setId(String id) {
// this.id = id == null ? null : id.trim();
// }
//
// /**
// * 获取发送者
// *
// * @return contentsender - 发送者
// */
// public String getContentsender() {
// return contentsender;
// }
//
// /**
// * 设置发送者
// *
// * @param contentsender 发送者
// */
// public void setContentsender(String contentsender) {
// this.contentsender = contentsender == null ? null : contentsender.trim();
// }
//
// /**
// * 获取聊天内容
// *
// * @return content - 聊天内容
// */
// public String getContent() {
// return content;
// }
//
// /**
// * 设置聊天内容
// *
// * @param content 聊天内容
// */
// public void setContent(String content) {
// this.content = content == null ? null : content.trim();
// }
//
// /**
// * @return createtime
// */
// public Date getCreatetime() {
// return createtime;
// }
//
// /**
// * @param createtime
// */
// public void setCreatetime(Date createtime) {
// this.createtime = createtime;
// }
// }
//
// Path: cjs_ssms_web/src/main/java/com/chengjs/cjsssmsweb/service/master/ISocketContentService.java
// public interface ISocketContentService {
//
// List<SocketContent> findSocketContentList();
//
// int insertSelective(SocketContent socketContent);
//
// }
//
// Path: cjs_ssms_web/src/main/java/com/chengjs/cjsssmsweb/common/util/UUIDUtil.java
// public class UUIDUtil {
// public static String uuid(){
// UUID uuid=UUID.randomUUID();
// String str = uuid.toString();
// String uuidStr=str.replace("-", "");
// return uuidStr;
// }
// }
// Path: cjs_ssms_web/src/main/java/com/chengjs/cjsssmsweb/controller/WebSocketController.java
import com.chengjs.cjsssmsweb.mybatis.pojo.master.SocketContent;
import com.chengjs.cjsssmsweb.service.master.ISocketContentService;
import com.chengjs.cjsssmsweb.common.util.UUIDUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.socket.server.standard.SpringConfigurator;
import javax.websocket.OnClose;
import javax.websocket.OnError;
import javax.websocket.OnMessage;
import javax.websocket.OnOpen;
import javax.websocket.Session;
import javax.websocket.server.ServerEndpoint;
import java.io.IOException;
import java.security.Principal;
import java.util.Date;
import java.util.concurrent.CopyOnWriteArraySet;
package com.chengjs.cjsssmsweb.controller;
/**
* WebSocketController:
*
* 类似Servlet的注解mapping。无需在web.xml中配置。
* configurator = SpringConfigurator.class是为了使该类可以通过Spring注入。
*
* 该注解用来指定一个URI,客户端可以通过这个URI来连接到WebSocket。
*
* @author: <a href="mailto:[email protected]">chengjs</a>, version:1.0.0, 16:58
*/
@ServerEndpoint(value = "/websocket", configurator = SpringConfigurator.class)
public class WebSocketController {
private static final Logger log = LoggerFactory.getLogger(WebSocketController.class);
/**
* TODO 静态变量,用来记录当前在线连接数。应该把它设计成线程安全的。
*/
private static int onlineCount = 0;
/**
* concurrent包的线程安全Set,用来存放每个客户端对应的MyWebSocket对象。
* 若要实现服务端与单一客户端通信的话,可以使用Map来存放,其中Key可以为用户标识
*/
private static CopyOnWriteArraySet<WebSocketController> webSocketSet = new CopyOnWriteArraySet<WebSocketController>();
/**
* 与客户端的连接会话,需要通过它来给客户端发送数据
*/
private Session session;
@Autowired | private ISocketContentService contentService; |
MiniPa/cjs_ssms | cjs_ssms_web/src/main/java/com/chengjs/cjsssmsweb/controller/WebSocketController.java | // Path: cjs_ssms_web/src/main/java/com/chengjs/cjsssmsweb/mybatis/pojo/master/SocketContent.java
// @Table(name = "socket_content")
// public class SocketContent {
// @Id
// @Column(name = "id")
// @GeneratedValue(strategy = GenerationType.IDENTITY, generator = "SELECT replace(t.uuid,\"-\",\"\") FROM (SELECT uuid() uuid FROM dual) t")
// private String id;
//
// /**
// * 发送者
// */
// @Column(name = "contentsender")
// private String contentsender;
//
// /**
// * 聊天内容
// */
// @Column(name = "content")
// private String content;
//
// @Column(name = "createtime")
// private Date createtime;
//
// /**
// * @return id
// */
// public String getId() {
// return id;
// }
//
// /**
// * @param id
// */
// public void setId(String id) {
// this.id = id == null ? null : id.trim();
// }
//
// /**
// * 获取发送者
// *
// * @return contentsender - 发送者
// */
// public String getContentsender() {
// return contentsender;
// }
//
// /**
// * 设置发送者
// *
// * @param contentsender 发送者
// */
// public void setContentsender(String contentsender) {
// this.contentsender = contentsender == null ? null : contentsender.trim();
// }
//
// /**
// * 获取聊天内容
// *
// * @return content - 聊天内容
// */
// public String getContent() {
// return content;
// }
//
// /**
// * 设置聊天内容
// *
// * @param content 聊天内容
// */
// public void setContent(String content) {
// this.content = content == null ? null : content.trim();
// }
//
// /**
// * @return createtime
// */
// public Date getCreatetime() {
// return createtime;
// }
//
// /**
// * @param createtime
// */
// public void setCreatetime(Date createtime) {
// this.createtime = createtime;
// }
// }
//
// Path: cjs_ssms_web/src/main/java/com/chengjs/cjsssmsweb/service/master/ISocketContentService.java
// public interface ISocketContentService {
//
// List<SocketContent> findSocketContentList();
//
// int insertSelective(SocketContent socketContent);
//
// }
//
// Path: cjs_ssms_web/src/main/java/com/chengjs/cjsssmsweb/common/util/UUIDUtil.java
// public class UUIDUtil {
// public static String uuid(){
// UUID uuid=UUID.randomUUID();
// String str = uuid.toString();
// String uuidStr=str.replace("-", "");
// return uuidStr;
// }
// }
| import com.chengjs.cjsssmsweb.mybatis.pojo.master.SocketContent;
import com.chengjs.cjsssmsweb.service.master.ISocketContentService;
import com.chengjs.cjsssmsweb.common.util.UUIDUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.socket.server.standard.SpringConfigurator;
import javax.websocket.OnClose;
import javax.websocket.OnError;
import javax.websocket.OnMessage;
import javax.websocket.OnOpen;
import javax.websocket.Session;
import javax.websocket.server.ServerEndpoint;
import java.io.IOException;
import java.security.Principal;
import java.util.Date;
import java.util.concurrent.CopyOnWriteArraySet; | continue;
}
item.serializeMessage(message,principal);
} catch (IOException e) {
e.printStackTrace();
continue;
}
}
}
/**
* 发生错误时调用
*
* @param session
* @param error
*/
@OnError
public void onError(Session session, Throwable error) {
log.debug("发生错误");
error.printStackTrace();
}
/**
* 自定义方法: 聊天内容保存到数据库
*
* @param message
* @param username
* @throws IOException
*/
public void serializeMessage(String message, Principal username) throws IOException { | // Path: cjs_ssms_web/src/main/java/com/chengjs/cjsssmsweb/mybatis/pojo/master/SocketContent.java
// @Table(name = "socket_content")
// public class SocketContent {
// @Id
// @Column(name = "id")
// @GeneratedValue(strategy = GenerationType.IDENTITY, generator = "SELECT replace(t.uuid,\"-\",\"\") FROM (SELECT uuid() uuid FROM dual) t")
// private String id;
//
// /**
// * 发送者
// */
// @Column(name = "contentsender")
// private String contentsender;
//
// /**
// * 聊天内容
// */
// @Column(name = "content")
// private String content;
//
// @Column(name = "createtime")
// private Date createtime;
//
// /**
// * @return id
// */
// public String getId() {
// return id;
// }
//
// /**
// * @param id
// */
// public void setId(String id) {
// this.id = id == null ? null : id.trim();
// }
//
// /**
// * 获取发送者
// *
// * @return contentsender - 发送者
// */
// public String getContentsender() {
// return contentsender;
// }
//
// /**
// * 设置发送者
// *
// * @param contentsender 发送者
// */
// public void setContentsender(String contentsender) {
// this.contentsender = contentsender == null ? null : contentsender.trim();
// }
//
// /**
// * 获取聊天内容
// *
// * @return content - 聊天内容
// */
// public String getContent() {
// return content;
// }
//
// /**
// * 设置聊天内容
// *
// * @param content 聊天内容
// */
// public void setContent(String content) {
// this.content = content == null ? null : content.trim();
// }
//
// /**
// * @return createtime
// */
// public Date getCreatetime() {
// return createtime;
// }
//
// /**
// * @param createtime
// */
// public void setCreatetime(Date createtime) {
// this.createtime = createtime;
// }
// }
//
// Path: cjs_ssms_web/src/main/java/com/chengjs/cjsssmsweb/service/master/ISocketContentService.java
// public interface ISocketContentService {
//
// List<SocketContent> findSocketContentList();
//
// int insertSelective(SocketContent socketContent);
//
// }
//
// Path: cjs_ssms_web/src/main/java/com/chengjs/cjsssmsweb/common/util/UUIDUtil.java
// public class UUIDUtil {
// public static String uuid(){
// UUID uuid=UUID.randomUUID();
// String str = uuid.toString();
// String uuidStr=str.replace("-", "");
// return uuidStr;
// }
// }
// Path: cjs_ssms_web/src/main/java/com/chengjs/cjsssmsweb/controller/WebSocketController.java
import com.chengjs.cjsssmsweb.mybatis.pojo.master.SocketContent;
import com.chengjs.cjsssmsweb.service.master.ISocketContentService;
import com.chengjs.cjsssmsweb.common.util.UUIDUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.socket.server.standard.SpringConfigurator;
import javax.websocket.OnClose;
import javax.websocket.OnError;
import javax.websocket.OnMessage;
import javax.websocket.OnOpen;
import javax.websocket.Session;
import javax.websocket.server.ServerEndpoint;
import java.io.IOException;
import java.security.Principal;
import java.util.Date;
import java.util.concurrent.CopyOnWriteArraySet;
continue;
}
item.serializeMessage(message,principal);
} catch (IOException e) {
e.printStackTrace();
continue;
}
}
}
/**
* 发生错误时调用
*
* @param session
* @param error
*/
@OnError
public void onError(Session session, Throwable error) {
log.debug("发生错误");
error.printStackTrace();
}
/**
* 自定义方法: 聊天内容保存到数据库
*
* @param message
* @param username
* @throws IOException
*/
public void serializeMessage(String message, Principal username) throws IOException { | SocketContent content = new SocketContent(); |
MiniPa/cjs_ssms | cjs_ssms_web/src/main/java/com/chengjs/cjsssmsweb/controller/WebSocketController.java | // Path: cjs_ssms_web/src/main/java/com/chengjs/cjsssmsweb/mybatis/pojo/master/SocketContent.java
// @Table(name = "socket_content")
// public class SocketContent {
// @Id
// @Column(name = "id")
// @GeneratedValue(strategy = GenerationType.IDENTITY, generator = "SELECT replace(t.uuid,\"-\",\"\") FROM (SELECT uuid() uuid FROM dual) t")
// private String id;
//
// /**
// * 发送者
// */
// @Column(name = "contentsender")
// private String contentsender;
//
// /**
// * 聊天内容
// */
// @Column(name = "content")
// private String content;
//
// @Column(name = "createtime")
// private Date createtime;
//
// /**
// * @return id
// */
// public String getId() {
// return id;
// }
//
// /**
// * @param id
// */
// public void setId(String id) {
// this.id = id == null ? null : id.trim();
// }
//
// /**
// * 获取发送者
// *
// * @return contentsender - 发送者
// */
// public String getContentsender() {
// return contentsender;
// }
//
// /**
// * 设置发送者
// *
// * @param contentsender 发送者
// */
// public void setContentsender(String contentsender) {
// this.contentsender = contentsender == null ? null : contentsender.trim();
// }
//
// /**
// * 获取聊天内容
// *
// * @return content - 聊天内容
// */
// public String getContent() {
// return content;
// }
//
// /**
// * 设置聊天内容
// *
// * @param content 聊天内容
// */
// public void setContent(String content) {
// this.content = content == null ? null : content.trim();
// }
//
// /**
// * @return createtime
// */
// public Date getCreatetime() {
// return createtime;
// }
//
// /**
// * @param createtime
// */
// public void setCreatetime(Date createtime) {
// this.createtime = createtime;
// }
// }
//
// Path: cjs_ssms_web/src/main/java/com/chengjs/cjsssmsweb/service/master/ISocketContentService.java
// public interface ISocketContentService {
//
// List<SocketContent> findSocketContentList();
//
// int insertSelective(SocketContent socketContent);
//
// }
//
// Path: cjs_ssms_web/src/main/java/com/chengjs/cjsssmsweb/common/util/UUIDUtil.java
// public class UUIDUtil {
// public static String uuid(){
// UUID uuid=UUID.randomUUID();
// String str = uuid.toString();
// String uuidStr=str.replace("-", "");
// return uuidStr;
// }
// }
| import com.chengjs.cjsssmsweb.mybatis.pojo.master.SocketContent;
import com.chengjs.cjsssmsweb.service.master.ISocketContentService;
import com.chengjs.cjsssmsweb.common.util.UUIDUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.socket.server.standard.SpringConfigurator;
import javax.websocket.OnClose;
import javax.websocket.OnError;
import javax.websocket.OnMessage;
import javax.websocket.OnOpen;
import javax.websocket.Session;
import javax.websocket.server.ServerEndpoint;
import java.io.IOException;
import java.security.Principal;
import java.util.Date;
import java.util.concurrent.CopyOnWriteArraySet; | item.serializeMessage(message,principal);
} catch (IOException e) {
e.printStackTrace();
continue;
}
}
}
/**
* 发生错误时调用
*
* @param session
* @param error
*/
@OnError
public void onError(Session session, Throwable error) {
log.debug("发生错误");
error.printStackTrace();
}
/**
* 自定义方法: 聊天内容保存到数据库
*
* @param message
* @param username
* @throws IOException
*/
public void serializeMessage(String message, Principal username) throws IOException {
SocketContent content = new SocketContent();
| // Path: cjs_ssms_web/src/main/java/com/chengjs/cjsssmsweb/mybatis/pojo/master/SocketContent.java
// @Table(name = "socket_content")
// public class SocketContent {
// @Id
// @Column(name = "id")
// @GeneratedValue(strategy = GenerationType.IDENTITY, generator = "SELECT replace(t.uuid,\"-\",\"\") FROM (SELECT uuid() uuid FROM dual) t")
// private String id;
//
// /**
// * 发送者
// */
// @Column(name = "contentsender")
// private String contentsender;
//
// /**
// * 聊天内容
// */
// @Column(name = "content")
// private String content;
//
// @Column(name = "createtime")
// private Date createtime;
//
// /**
// * @return id
// */
// public String getId() {
// return id;
// }
//
// /**
// * @param id
// */
// public void setId(String id) {
// this.id = id == null ? null : id.trim();
// }
//
// /**
// * 获取发送者
// *
// * @return contentsender - 发送者
// */
// public String getContentsender() {
// return contentsender;
// }
//
// /**
// * 设置发送者
// *
// * @param contentsender 发送者
// */
// public void setContentsender(String contentsender) {
// this.contentsender = contentsender == null ? null : contentsender.trim();
// }
//
// /**
// * 获取聊天内容
// *
// * @return content - 聊天内容
// */
// public String getContent() {
// return content;
// }
//
// /**
// * 设置聊天内容
// *
// * @param content 聊天内容
// */
// public void setContent(String content) {
// this.content = content == null ? null : content.trim();
// }
//
// /**
// * @return createtime
// */
// public Date getCreatetime() {
// return createtime;
// }
//
// /**
// * @param createtime
// */
// public void setCreatetime(Date createtime) {
// this.createtime = createtime;
// }
// }
//
// Path: cjs_ssms_web/src/main/java/com/chengjs/cjsssmsweb/service/master/ISocketContentService.java
// public interface ISocketContentService {
//
// List<SocketContent> findSocketContentList();
//
// int insertSelective(SocketContent socketContent);
//
// }
//
// Path: cjs_ssms_web/src/main/java/com/chengjs/cjsssmsweb/common/util/UUIDUtil.java
// public class UUIDUtil {
// public static String uuid(){
// UUID uuid=UUID.randomUUID();
// String str = uuid.toString();
// String uuidStr=str.replace("-", "");
// return uuidStr;
// }
// }
// Path: cjs_ssms_web/src/main/java/com/chengjs/cjsssmsweb/controller/WebSocketController.java
import com.chengjs.cjsssmsweb.mybatis.pojo.master.SocketContent;
import com.chengjs.cjsssmsweb.service.master.ISocketContentService;
import com.chengjs.cjsssmsweb.common.util.UUIDUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.socket.server.standard.SpringConfigurator;
import javax.websocket.OnClose;
import javax.websocket.OnError;
import javax.websocket.OnMessage;
import javax.websocket.OnOpen;
import javax.websocket.Session;
import javax.websocket.server.ServerEndpoint;
import java.io.IOException;
import java.security.Principal;
import java.util.Date;
import java.util.concurrent.CopyOnWriteArraySet;
item.serializeMessage(message,principal);
} catch (IOException e) {
e.printStackTrace();
continue;
}
}
}
/**
* 发生错误时调用
*
* @param session
* @param error
*/
@OnError
public void onError(Session session, Throwable error) {
log.debug("发生错误");
error.printStackTrace();
}
/**
* 自定义方法: 聊天内容保存到数据库
*
* @param message
* @param username
* @throws IOException
*/
public void serializeMessage(String message, Principal username) throws IOException {
SocketContent content = new SocketContent();
| content.setId(UUIDUtil.uuid()); |
MiniPa/cjs_ssms | cjs_ssms_web/src/main/java/com/chengjs/cjsssmsweb/components/cxf/WSServerTest.java | // Path: cjs_ssms_web/src/main/java/com/chengjs/cjsssmsweb/components/cxf/impl/WSSampleImpl.java
// @Component("wSSample")
// @WebService
// public class WSSampleImpl implements WSSample {
//
// public String say(String str) {
// return "你好这是wSSample/say返回值:"+str;
// }
//
// }
//
// Path: cjs_ssms_web/src/main/java/com/chengjs/cjsssmsweb/enums/TestEnv.java
// public class TestEnv {
//
// /**
// * 当测试开启时,onTTrue为 true
// */
// public static boolean onTTrue = true;
//
// /**
// * 当测试开启时, onTFalse为 false
// */
// public static boolean onTFalse = false;
//
// public TestEnv() {
// String testEnv = PropertiesUtil.getValue("test");
// onTTrue = "true".equals(testEnv) ? true : false;
// onTFalse = "true".equals(testEnv) ? false : true;
// }
// }
| import com.chengjs.cjsssmsweb.components.cxf.impl.WSSampleImpl;
import com.chengjs.cjsssmsweb.enums.TestEnv;
import org.apache.cxf.jaxws.JaxWsServerFactoryBean; | package com.chengjs.cjsssmsweb.components.cxf;
public class WSServerTest {
/**
* 接口测试 wsdl: http://localhost:9000/wSSample?wsdl
* @param args
*/
public static void main(String[] args) {
System.out.println("web service 启动中。。。"); | // Path: cjs_ssms_web/src/main/java/com/chengjs/cjsssmsweb/components/cxf/impl/WSSampleImpl.java
// @Component("wSSample")
// @WebService
// public class WSSampleImpl implements WSSample {
//
// public String say(String str) {
// return "你好这是wSSample/say返回值:"+str;
// }
//
// }
//
// Path: cjs_ssms_web/src/main/java/com/chengjs/cjsssmsweb/enums/TestEnv.java
// public class TestEnv {
//
// /**
// * 当测试开启时,onTTrue为 true
// */
// public static boolean onTTrue = true;
//
// /**
// * 当测试开启时, onTFalse为 false
// */
// public static boolean onTFalse = false;
//
// public TestEnv() {
// String testEnv = PropertiesUtil.getValue("test");
// onTTrue = "true".equals(testEnv) ? true : false;
// onTFalse = "true".equals(testEnv) ? false : true;
// }
// }
// Path: cjs_ssms_web/src/main/java/com/chengjs/cjsssmsweb/components/cxf/WSServerTest.java
import com.chengjs.cjsssmsweb.components.cxf.impl.WSSampleImpl;
import com.chengjs.cjsssmsweb.enums.TestEnv;
import org.apache.cxf.jaxws.JaxWsServerFactoryBean;
package com.chengjs.cjsssmsweb.components.cxf;
public class WSServerTest {
/**
* 接口测试 wsdl: http://localhost:9000/wSSample?wsdl
* @param args
*/
public static void main(String[] args) {
System.out.println("web service 启动中。。。"); | WSSampleImpl implementor = new WSSampleImpl(); |
MiniPa/cjs_ssms | cjs_ssms_web/src/main/java/com/chengjs/cjsssmsweb/components/cxf/WSServerTest.java | // Path: cjs_ssms_web/src/main/java/com/chengjs/cjsssmsweb/components/cxf/impl/WSSampleImpl.java
// @Component("wSSample")
// @WebService
// public class WSSampleImpl implements WSSample {
//
// public String say(String str) {
// return "你好这是wSSample/say返回值:"+str;
// }
//
// }
//
// Path: cjs_ssms_web/src/main/java/com/chengjs/cjsssmsweb/enums/TestEnv.java
// public class TestEnv {
//
// /**
// * 当测试开启时,onTTrue为 true
// */
// public static boolean onTTrue = true;
//
// /**
// * 当测试开启时, onTFalse为 false
// */
// public static boolean onTFalse = false;
//
// public TestEnv() {
// String testEnv = PropertiesUtil.getValue("test");
// onTTrue = "true".equals(testEnv) ? true : false;
// onTFalse = "true".equals(testEnv) ? false : true;
// }
// }
| import com.chengjs.cjsssmsweb.components.cxf.impl.WSSampleImpl;
import com.chengjs.cjsssmsweb.enums.TestEnv;
import org.apache.cxf.jaxws.JaxWsServerFactoryBean; | package com.chengjs.cjsssmsweb.components.cxf;
public class WSServerTest {
/**
* 接口测试 wsdl: http://localhost:9000/wSSample?wsdl
* @param args
*/
public static void main(String[] args) {
System.out.println("web service 启动中。。。");
WSSampleImpl implementor = new WSSampleImpl();
String address = "http://192.168.245.221:9000/wSSample"; | // Path: cjs_ssms_web/src/main/java/com/chengjs/cjsssmsweb/components/cxf/impl/WSSampleImpl.java
// @Component("wSSample")
// @WebService
// public class WSSampleImpl implements WSSample {
//
// public String say(String str) {
// return "你好这是wSSample/say返回值:"+str;
// }
//
// }
//
// Path: cjs_ssms_web/src/main/java/com/chengjs/cjsssmsweb/enums/TestEnv.java
// public class TestEnv {
//
// /**
// * 当测试开启时,onTTrue为 true
// */
// public static boolean onTTrue = true;
//
// /**
// * 当测试开启时, onTFalse为 false
// */
// public static boolean onTFalse = false;
//
// public TestEnv() {
// String testEnv = PropertiesUtil.getValue("test");
// onTTrue = "true".equals(testEnv) ? true : false;
// onTFalse = "true".equals(testEnv) ? false : true;
// }
// }
// Path: cjs_ssms_web/src/main/java/com/chengjs/cjsssmsweb/components/cxf/WSServerTest.java
import com.chengjs.cjsssmsweb.components.cxf.impl.WSSampleImpl;
import com.chengjs.cjsssmsweb.enums.TestEnv;
import org.apache.cxf.jaxws.JaxWsServerFactoryBean;
package com.chengjs.cjsssmsweb.components.cxf;
public class WSServerTest {
/**
* 接口测试 wsdl: http://localhost:9000/wSSample?wsdl
* @param args
*/
public static void main(String[] args) {
System.out.println("web service 启动中。。。");
WSSampleImpl implementor = new WSSampleImpl();
String address = "http://192.168.245.221:9000/wSSample"; | if (TestEnv.onTTrue) { |
MiniPa/cjs_ssms | cjs_ssms_web/src/main/java/com/chengjs/cjsssmsweb/components/shiro/CustomCredentialsMatcher.java | // Path: cjs_ssms_web/src/main/java/com/chengjs/cjsssmsweb/common/util/codec/MD5Util.java
// public class MD5Util {
//
// public static final String DEFAULT_SALT = "minipa_chengjs";
//
// /**
// * 指定加密盐
// * @param str
// * @param salt
// * @return
// */
// public static String md5(String str, String salt){
// if (StringUtil.isNullOrEmpty(salt)) {
// salt = DEFAULT_SALT;
// }
// return new Md5Hash(str,salt).toString() ;
// }
//
// /**
// * 采用默认加密盐
// * @param str
// * @return
// */
// public static String md5(String str){
// return new Md5Hash(str,DEFAULT_SALT).toString() ;
// }
//
// public static void main(String[] args) {
// String md5 = md5("123456", DEFAULT_SALT) ;
// System.out.println(md5); // 119d3a4d2dfbca3d23bd1c52a1d6a6e6
// }
//
// }
| import com.chengjs.cjsssmsweb.common.util.codec.MD5Util;
import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.authc.credential.SimpleCredentialsMatcher;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory; | package com.chengjs.cjsssmsweb.components.shiro;
/**
* CustomCredentialsMatcher:
* 密码校验方法继承 SimpleCredentialsMatcher或HashedCredentialsMatcher 实现doCredentialsMatch()
*
* author: <a href="mailto:[email protected]">chengjs_minipa</a>, version:1.0.0, 2017/8/28
*/
public class CustomCredentialsMatcher extends SimpleCredentialsMatcher {
private static final Logger log = LoggerFactory.getLogger(CustomCredentialsMatcher.class);
@Override
public boolean doCredentialsMatch(AuthenticationToken authcToken, AuthenticationInfo info) {
UsernamePasswordToken token = (UsernamePasswordToken) authcToken;
Object tokenCredentials = encrypt(String.valueOf(token.getPassword()));
Object accountCredentials = getCredentials(info);
//将密码加密与系统加密后的密码校验,内容一致就返回true,不一致就返回false
return equals(tokenCredentials, accountCredentials);
}
/**
* 将传进来密码加密方法
* @param data
* @return
*/
private String encrypt(String data) { | // Path: cjs_ssms_web/src/main/java/com/chengjs/cjsssmsweb/common/util/codec/MD5Util.java
// public class MD5Util {
//
// public static final String DEFAULT_SALT = "minipa_chengjs";
//
// /**
// * 指定加密盐
// * @param str
// * @param salt
// * @return
// */
// public static String md5(String str, String salt){
// if (StringUtil.isNullOrEmpty(salt)) {
// salt = DEFAULT_SALT;
// }
// return new Md5Hash(str,salt).toString() ;
// }
//
// /**
// * 采用默认加密盐
// * @param str
// * @return
// */
// public static String md5(String str){
// return new Md5Hash(str,DEFAULT_SALT).toString() ;
// }
//
// public static void main(String[] args) {
// String md5 = md5("123456", DEFAULT_SALT) ;
// System.out.println(md5); // 119d3a4d2dfbca3d23bd1c52a1d6a6e6
// }
//
// }
// Path: cjs_ssms_web/src/main/java/com/chengjs/cjsssmsweb/components/shiro/CustomCredentialsMatcher.java
import com.chengjs.cjsssmsweb.common.util.codec.MD5Util;
import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.authc.credential.SimpleCredentialsMatcher;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
package com.chengjs.cjsssmsweb.components.shiro;
/**
* CustomCredentialsMatcher:
* 密码校验方法继承 SimpleCredentialsMatcher或HashedCredentialsMatcher 实现doCredentialsMatch()
*
* author: <a href="mailto:[email protected]">chengjs_minipa</a>, version:1.0.0, 2017/8/28
*/
public class CustomCredentialsMatcher extends SimpleCredentialsMatcher {
private static final Logger log = LoggerFactory.getLogger(CustomCredentialsMatcher.class);
@Override
public boolean doCredentialsMatch(AuthenticationToken authcToken, AuthenticationInfo info) {
UsernamePasswordToken token = (UsernamePasswordToken) authcToken;
Object tokenCredentials = encrypt(String.valueOf(token.getPassword()));
Object accountCredentials = getCredentials(info);
//将密码加密与系统加密后的密码校验,内容一致就返回true,不一致就返回false
return equals(tokenCredentials, accountCredentials);
}
/**
* 将传进来密码加密方法
* @param data
* @return
*/
private String encrypt(String data) { | String encrypt = MD5Util.md5(data, ""); |
MiniPa/cjs_ssms | cjs_ssms_web/src/main/java/com/chengjs/cjsssmsweb/service/master/SocketContentServiceImpl.java | // Path: cjs_ssms_web/src/main/java/com/chengjs/cjsssmsweb/mybatis/mapper/dao/SocketContentDao.java
// public interface SocketContentDao extends Mapper<Country> {
//
// List<SocketContent> findSocketContentList();
//
// }
//
// Path: cjs_ssms_web/src/main/java/com/chengjs/cjsssmsweb/mybatis/mapper/master/SocketContentMapper.java
// public interface SocketContentMapper extends Mapper<SocketContent> {
// }
//
// Path: cjs_ssms_web/src/main/java/com/chengjs/cjsssmsweb/mybatis/pojo/master/SocketContent.java
// @Table(name = "socket_content")
// public class SocketContent {
// @Id
// @Column(name = "id")
// @GeneratedValue(strategy = GenerationType.IDENTITY, generator = "SELECT replace(t.uuid,\"-\",\"\") FROM (SELECT uuid() uuid FROM dual) t")
// private String id;
//
// /**
// * 发送者
// */
// @Column(name = "contentsender")
// private String contentsender;
//
// /**
// * 聊天内容
// */
// @Column(name = "content")
// private String content;
//
// @Column(name = "createtime")
// private Date createtime;
//
// /**
// * @return id
// */
// public String getId() {
// return id;
// }
//
// /**
// * @param id
// */
// public void setId(String id) {
// this.id = id == null ? null : id.trim();
// }
//
// /**
// * 获取发送者
// *
// * @return contentsender - 发送者
// */
// public String getContentsender() {
// return contentsender;
// }
//
// /**
// * 设置发送者
// *
// * @param contentsender 发送者
// */
// public void setContentsender(String contentsender) {
// this.contentsender = contentsender == null ? null : contentsender.trim();
// }
//
// /**
// * 获取聊天内容
// *
// * @return content - 聊天内容
// */
// public String getContent() {
// return content;
// }
//
// /**
// * 设置聊天内容
// *
// * @param content 聊天内容
// */
// public void setContent(String content) {
// this.content = content == null ? null : content.trim();
// }
//
// /**
// * @return createtime
// */
// public Date getCreatetime() {
// return createtime;
// }
//
// /**
// * @param createtime
// */
// public void setCreatetime(Date createtime) {
// this.createtime = createtime;
// }
// }
| import com.chengjs.cjsssmsweb.mybatis.mapper.dao.SocketContentDao;
import com.chengjs.cjsssmsweb.mybatis.mapper.master.SocketContentMapper;
import com.chengjs.cjsssmsweb.mybatis.pojo.master.SocketContent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List; | package com.chengjs.cjsssmsweb.service.master;
/**
* SocketContentServiceImpl:
* author: <a href="mailto:[email protected]">chengjs</a>, version:1.0.0, 22:14
*/
@Service
public class SocketContentServiceImpl implements ISocketContentService {
@Autowired | // Path: cjs_ssms_web/src/main/java/com/chengjs/cjsssmsweb/mybatis/mapper/dao/SocketContentDao.java
// public interface SocketContentDao extends Mapper<Country> {
//
// List<SocketContent> findSocketContentList();
//
// }
//
// Path: cjs_ssms_web/src/main/java/com/chengjs/cjsssmsweb/mybatis/mapper/master/SocketContentMapper.java
// public interface SocketContentMapper extends Mapper<SocketContent> {
// }
//
// Path: cjs_ssms_web/src/main/java/com/chengjs/cjsssmsweb/mybatis/pojo/master/SocketContent.java
// @Table(name = "socket_content")
// public class SocketContent {
// @Id
// @Column(name = "id")
// @GeneratedValue(strategy = GenerationType.IDENTITY, generator = "SELECT replace(t.uuid,\"-\",\"\") FROM (SELECT uuid() uuid FROM dual) t")
// private String id;
//
// /**
// * 发送者
// */
// @Column(name = "contentsender")
// private String contentsender;
//
// /**
// * 聊天内容
// */
// @Column(name = "content")
// private String content;
//
// @Column(name = "createtime")
// private Date createtime;
//
// /**
// * @return id
// */
// public String getId() {
// return id;
// }
//
// /**
// * @param id
// */
// public void setId(String id) {
// this.id = id == null ? null : id.trim();
// }
//
// /**
// * 获取发送者
// *
// * @return contentsender - 发送者
// */
// public String getContentsender() {
// return contentsender;
// }
//
// /**
// * 设置发送者
// *
// * @param contentsender 发送者
// */
// public void setContentsender(String contentsender) {
// this.contentsender = contentsender == null ? null : contentsender.trim();
// }
//
// /**
// * 获取聊天内容
// *
// * @return content - 聊天内容
// */
// public String getContent() {
// return content;
// }
//
// /**
// * 设置聊天内容
// *
// * @param content 聊天内容
// */
// public void setContent(String content) {
// this.content = content == null ? null : content.trim();
// }
//
// /**
// * @return createtime
// */
// public Date getCreatetime() {
// return createtime;
// }
//
// /**
// * @param createtime
// */
// public void setCreatetime(Date createtime) {
// this.createtime = createtime;
// }
// }
// Path: cjs_ssms_web/src/main/java/com/chengjs/cjsssmsweb/service/master/SocketContentServiceImpl.java
import com.chengjs.cjsssmsweb.mybatis.mapper.dao.SocketContentDao;
import com.chengjs.cjsssmsweb.mybatis.mapper.master.SocketContentMapper;
import com.chengjs.cjsssmsweb.mybatis.pojo.master.SocketContent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
package com.chengjs.cjsssmsweb.service.master;
/**
* SocketContentServiceImpl:
* author: <a href="mailto:[email protected]">chengjs</a>, version:1.0.0, 22:14
*/
@Service
public class SocketContentServiceImpl implements ISocketContentService {
@Autowired | private SocketContentDao socketContentDao; |
MiniPa/cjs_ssms | cjs_ssms_web/src/main/java/com/chengjs/cjsssmsweb/service/master/SocketContentServiceImpl.java | // Path: cjs_ssms_web/src/main/java/com/chengjs/cjsssmsweb/mybatis/mapper/dao/SocketContentDao.java
// public interface SocketContentDao extends Mapper<Country> {
//
// List<SocketContent> findSocketContentList();
//
// }
//
// Path: cjs_ssms_web/src/main/java/com/chengjs/cjsssmsweb/mybatis/mapper/master/SocketContentMapper.java
// public interface SocketContentMapper extends Mapper<SocketContent> {
// }
//
// Path: cjs_ssms_web/src/main/java/com/chengjs/cjsssmsweb/mybatis/pojo/master/SocketContent.java
// @Table(name = "socket_content")
// public class SocketContent {
// @Id
// @Column(name = "id")
// @GeneratedValue(strategy = GenerationType.IDENTITY, generator = "SELECT replace(t.uuid,\"-\",\"\") FROM (SELECT uuid() uuid FROM dual) t")
// private String id;
//
// /**
// * 发送者
// */
// @Column(name = "contentsender")
// private String contentsender;
//
// /**
// * 聊天内容
// */
// @Column(name = "content")
// private String content;
//
// @Column(name = "createtime")
// private Date createtime;
//
// /**
// * @return id
// */
// public String getId() {
// return id;
// }
//
// /**
// * @param id
// */
// public void setId(String id) {
// this.id = id == null ? null : id.trim();
// }
//
// /**
// * 获取发送者
// *
// * @return contentsender - 发送者
// */
// public String getContentsender() {
// return contentsender;
// }
//
// /**
// * 设置发送者
// *
// * @param contentsender 发送者
// */
// public void setContentsender(String contentsender) {
// this.contentsender = contentsender == null ? null : contentsender.trim();
// }
//
// /**
// * 获取聊天内容
// *
// * @return content - 聊天内容
// */
// public String getContent() {
// return content;
// }
//
// /**
// * 设置聊天内容
// *
// * @param content 聊天内容
// */
// public void setContent(String content) {
// this.content = content == null ? null : content.trim();
// }
//
// /**
// * @return createtime
// */
// public Date getCreatetime() {
// return createtime;
// }
//
// /**
// * @param createtime
// */
// public void setCreatetime(Date createtime) {
// this.createtime = createtime;
// }
// }
| import com.chengjs.cjsssmsweb.mybatis.mapper.dao.SocketContentDao;
import com.chengjs.cjsssmsweb.mybatis.mapper.master.SocketContentMapper;
import com.chengjs.cjsssmsweb.mybatis.pojo.master.SocketContent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List; | package com.chengjs.cjsssmsweb.service.master;
/**
* SocketContentServiceImpl:
* author: <a href="mailto:[email protected]">chengjs</a>, version:1.0.0, 22:14
*/
@Service
public class SocketContentServiceImpl implements ISocketContentService {
@Autowired
private SocketContentDao socketContentDao;
@Autowired | // Path: cjs_ssms_web/src/main/java/com/chengjs/cjsssmsweb/mybatis/mapper/dao/SocketContentDao.java
// public interface SocketContentDao extends Mapper<Country> {
//
// List<SocketContent> findSocketContentList();
//
// }
//
// Path: cjs_ssms_web/src/main/java/com/chengjs/cjsssmsweb/mybatis/mapper/master/SocketContentMapper.java
// public interface SocketContentMapper extends Mapper<SocketContent> {
// }
//
// Path: cjs_ssms_web/src/main/java/com/chengjs/cjsssmsweb/mybatis/pojo/master/SocketContent.java
// @Table(name = "socket_content")
// public class SocketContent {
// @Id
// @Column(name = "id")
// @GeneratedValue(strategy = GenerationType.IDENTITY, generator = "SELECT replace(t.uuid,\"-\",\"\") FROM (SELECT uuid() uuid FROM dual) t")
// private String id;
//
// /**
// * 发送者
// */
// @Column(name = "contentsender")
// private String contentsender;
//
// /**
// * 聊天内容
// */
// @Column(name = "content")
// private String content;
//
// @Column(name = "createtime")
// private Date createtime;
//
// /**
// * @return id
// */
// public String getId() {
// return id;
// }
//
// /**
// * @param id
// */
// public void setId(String id) {
// this.id = id == null ? null : id.trim();
// }
//
// /**
// * 获取发送者
// *
// * @return contentsender - 发送者
// */
// public String getContentsender() {
// return contentsender;
// }
//
// /**
// * 设置发送者
// *
// * @param contentsender 发送者
// */
// public void setContentsender(String contentsender) {
// this.contentsender = contentsender == null ? null : contentsender.trim();
// }
//
// /**
// * 获取聊天内容
// *
// * @return content - 聊天内容
// */
// public String getContent() {
// return content;
// }
//
// /**
// * 设置聊天内容
// *
// * @param content 聊天内容
// */
// public void setContent(String content) {
// this.content = content == null ? null : content.trim();
// }
//
// /**
// * @return createtime
// */
// public Date getCreatetime() {
// return createtime;
// }
//
// /**
// * @param createtime
// */
// public void setCreatetime(Date createtime) {
// this.createtime = createtime;
// }
// }
// Path: cjs_ssms_web/src/main/java/com/chengjs/cjsssmsweb/service/master/SocketContentServiceImpl.java
import com.chengjs.cjsssmsweb.mybatis.mapper.dao.SocketContentDao;
import com.chengjs.cjsssmsweb.mybatis.mapper.master.SocketContentMapper;
import com.chengjs.cjsssmsweb.mybatis.pojo.master.SocketContent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
package com.chengjs.cjsssmsweb.service.master;
/**
* SocketContentServiceImpl:
* author: <a href="mailto:[email protected]">chengjs</a>, version:1.0.0, 22:14
*/
@Service
public class SocketContentServiceImpl implements ISocketContentService {
@Autowired
private SocketContentDao socketContentDao;
@Autowired | private SocketContentMapper socketContentMapper; |
MiniPa/cjs_ssms | cjs_ssms_web/src/main/java/com/chengjs/cjsssmsweb/service/master/SocketContentServiceImpl.java | // Path: cjs_ssms_web/src/main/java/com/chengjs/cjsssmsweb/mybatis/mapper/dao/SocketContentDao.java
// public interface SocketContentDao extends Mapper<Country> {
//
// List<SocketContent> findSocketContentList();
//
// }
//
// Path: cjs_ssms_web/src/main/java/com/chengjs/cjsssmsweb/mybatis/mapper/master/SocketContentMapper.java
// public interface SocketContentMapper extends Mapper<SocketContent> {
// }
//
// Path: cjs_ssms_web/src/main/java/com/chengjs/cjsssmsweb/mybatis/pojo/master/SocketContent.java
// @Table(name = "socket_content")
// public class SocketContent {
// @Id
// @Column(name = "id")
// @GeneratedValue(strategy = GenerationType.IDENTITY, generator = "SELECT replace(t.uuid,\"-\",\"\") FROM (SELECT uuid() uuid FROM dual) t")
// private String id;
//
// /**
// * 发送者
// */
// @Column(name = "contentsender")
// private String contentsender;
//
// /**
// * 聊天内容
// */
// @Column(name = "content")
// private String content;
//
// @Column(name = "createtime")
// private Date createtime;
//
// /**
// * @return id
// */
// public String getId() {
// return id;
// }
//
// /**
// * @param id
// */
// public void setId(String id) {
// this.id = id == null ? null : id.trim();
// }
//
// /**
// * 获取发送者
// *
// * @return contentsender - 发送者
// */
// public String getContentsender() {
// return contentsender;
// }
//
// /**
// * 设置发送者
// *
// * @param contentsender 发送者
// */
// public void setContentsender(String contentsender) {
// this.contentsender = contentsender == null ? null : contentsender.trim();
// }
//
// /**
// * 获取聊天内容
// *
// * @return content - 聊天内容
// */
// public String getContent() {
// return content;
// }
//
// /**
// * 设置聊天内容
// *
// * @param content 聊天内容
// */
// public void setContent(String content) {
// this.content = content == null ? null : content.trim();
// }
//
// /**
// * @return createtime
// */
// public Date getCreatetime() {
// return createtime;
// }
//
// /**
// * @param createtime
// */
// public void setCreatetime(Date createtime) {
// this.createtime = createtime;
// }
// }
| import com.chengjs.cjsssmsweb.mybatis.mapper.dao.SocketContentDao;
import com.chengjs.cjsssmsweb.mybatis.mapper.master.SocketContentMapper;
import com.chengjs.cjsssmsweb.mybatis.pojo.master.SocketContent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List; | package com.chengjs.cjsssmsweb.service.master;
/**
* SocketContentServiceImpl:
* author: <a href="mailto:[email protected]">chengjs</a>, version:1.0.0, 22:14
*/
@Service
public class SocketContentServiceImpl implements ISocketContentService {
@Autowired
private SocketContentDao socketContentDao;
@Autowired
private SocketContentMapper socketContentMapper;
@Override | // Path: cjs_ssms_web/src/main/java/com/chengjs/cjsssmsweb/mybatis/mapper/dao/SocketContentDao.java
// public interface SocketContentDao extends Mapper<Country> {
//
// List<SocketContent> findSocketContentList();
//
// }
//
// Path: cjs_ssms_web/src/main/java/com/chengjs/cjsssmsweb/mybatis/mapper/master/SocketContentMapper.java
// public interface SocketContentMapper extends Mapper<SocketContent> {
// }
//
// Path: cjs_ssms_web/src/main/java/com/chengjs/cjsssmsweb/mybatis/pojo/master/SocketContent.java
// @Table(name = "socket_content")
// public class SocketContent {
// @Id
// @Column(name = "id")
// @GeneratedValue(strategy = GenerationType.IDENTITY, generator = "SELECT replace(t.uuid,\"-\",\"\") FROM (SELECT uuid() uuid FROM dual) t")
// private String id;
//
// /**
// * 发送者
// */
// @Column(name = "contentsender")
// private String contentsender;
//
// /**
// * 聊天内容
// */
// @Column(name = "content")
// private String content;
//
// @Column(name = "createtime")
// private Date createtime;
//
// /**
// * @return id
// */
// public String getId() {
// return id;
// }
//
// /**
// * @param id
// */
// public void setId(String id) {
// this.id = id == null ? null : id.trim();
// }
//
// /**
// * 获取发送者
// *
// * @return contentsender - 发送者
// */
// public String getContentsender() {
// return contentsender;
// }
//
// /**
// * 设置发送者
// *
// * @param contentsender 发送者
// */
// public void setContentsender(String contentsender) {
// this.contentsender = contentsender == null ? null : contentsender.trim();
// }
//
// /**
// * 获取聊天内容
// *
// * @return content - 聊天内容
// */
// public String getContent() {
// return content;
// }
//
// /**
// * 设置聊天内容
// *
// * @param content 聊天内容
// */
// public void setContent(String content) {
// this.content = content == null ? null : content.trim();
// }
//
// /**
// * @return createtime
// */
// public Date getCreatetime() {
// return createtime;
// }
//
// /**
// * @param createtime
// */
// public void setCreatetime(Date createtime) {
// this.createtime = createtime;
// }
// }
// Path: cjs_ssms_web/src/main/java/com/chengjs/cjsssmsweb/service/master/SocketContentServiceImpl.java
import com.chengjs.cjsssmsweb.mybatis.mapper.dao.SocketContentDao;
import com.chengjs.cjsssmsweb.mybatis.mapper.master.SocketContentMapper;
import com.chengjs.cjsssmsweb.mybatis.pojo.master.SocketContent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
package com.chengjs.cjsssmsweb.service.master;
/**
* SocketContentServiceImpl:
* author: <a href="mailto:[email protected]">chengjs</a>, version:1.0.0, 22:14
*/
@Service
public class SocketContentServiceImpl implements ISocketContentService {
@Autowired
private SocketContentDao socketContentDao;
@Autowired
private SocketContentMapper socketContentMapper;
@Override | public List<SocketContent> findSocketContentList() { |
MiniPa/cjs_ssms | cjs_ssms_web/src/main/java/com/chengjs/cjsssmsweb/common/util/math/CashUtil.java | // Path: cjs_ssms_web/src/main/java/com/chengjs/cjsssmsweb/common/util/StringUtil.java
// public class StringUtil {
//
// /**
// * 字符串是否为空,包括blank
// *
// * @param str
// * @return
// */
// public static boolean isNullOrEmpty(String str) {
// return null != str && 0 != str.trim().length() ? false : true;
// }
//
// /**
// * 返回"null" 或者 toString
// *
// * @param obj
// * @return
// */
// public static boolean reNullOrEmpty(Object obj) {
// return obj == null || "".equals(obj.toString());
// }
//
// /**
// * 判断是否是空
// *
// * @param str
// * @return
// */
// public static boolean isEmpty(String str) {
// if (str == null || "".equals(str.trim())) {
// return true;
// } else {
// return false;
// }
// }
//
// /**
// * 判断是否不是空
// *
// * @param str
// * @return
// */
// public static boolean isNotEmpty(String str) {
// if ((str != null) && !"".equals(str.trim())) {
// return true;
// } else {
// return false;
// }
// }
//
// /**
// * 格式化模糊查询
// *
// * @param str
// * @return
// */
// public static String formatLike(String str) {
// if (isNotEmpty(str)) {
// return "%" + str + "%";
// } else {
// return null;
// }
// }
//
// /**
// * 返回"null"或者toString
// *
// * @param obj
// * @return
// */
// public static String toString(Object obj) {
// if (obj == null) return "null";
// return obj.toString();
// }
//
// /**
// * 用标签来连接string
// *
// * @param s
// * @param delimiter
// * @return
// */
// public static String join(Collection s, String delimiter) {
// StringBuffer buffer = new StringBuffer();
// Iterator iter = s.iterator();
// while (iter.hasNext()) {
// buffer.append(iter.next());
// if (iter.hasNext()) {
// buffer.append(delimiter);
// }
// }
// return buffer.toString();
// }
//
// /**
// * 首字母变大写
// * @param name
// * @return
// */
// public static String captureName(String name) {
// /*效率低的方法*/
// /* name = name.substring(0, 1).toUpperCase() + name.substring(1);
// return name;*/
//
// /*高效率方法*/
// char[] cs = name.toCharArray();
// cs[0] -= 32;
// return String.valueOf(cs);
// }
//
// /**
// * 去除%
// * @param str
// * @return
// */
// public static String reSqlLikeStr(String str) {
// return str.replace("%", "");
// }
//
//
// }
| import com.chengjs.cjsssmsweb.common.util.StringUtil;
import java.math.BigDecimal;
import java.text.DecimalFormat; | package com.chengjs.cjsssmsweb.common.util.math;
/**
* CashUtil: 涉及金额的计算,以及double类型的计算
* author: Chengjs, version:1.0.0, 2017-09-08
*/
public class CashUtil {
/*格式化2位小数*/
private static java.text.DecimalFormat df2 = new java.text.DecimalFormat("############0.00");
/*格式化4位小数*/
private static java.text.DecimalFormat df4 = new java.text.DecimalFormat("############0.0000");
/*格式化6位小数*/
private static java.text.DecimalFormat df6 = new java.text.DecimalFormat("############0.000000");
/*如果有4位小数格式化4位小数,否则格式化成2位小数*/
private static java.text.DecimalFormat df2or4 = new java.text.DecimalFormat("############0.00##");
/**
* @param d d
* @param v v
* @return boolean
*/
public static boolean isDoubleEquals(double d, double v) {
return Math.abs(d - v) < 0.0000001;
}
/**
* 转换null为0.0d,主要用于从map中get数据时,避免空指针异常
*
* @param o 对象
* @return double
*/
public static double nvlDouble(Object o) {
double d = 0d; | // Path: cjs_ssms_web/src/main/java/com/chengjs/cjsssmsweb/common/util/StringUtil.java
// public class StringUtil {
//
// /**
// * 字符串是否为空,包括blank
// *
// * @param str
// * @return
// */
// public static boolean isNullOrEmpty(String str) {
// return null != str && 0 != str.trim().length() ? false : true;
// }
//
// /**
// * 返回"null" 或者 toString
// *
// * @param obj
// * @return
// */
// public static boolean reNullOrEmpty(Object obj) {
// return obj == null || "".equals(obj.toString());
// }
//
// /**
// * 判断是否是空
// *
// * @param str
// * @return
// */
// public static boolean isEmpty(String str) {
// if (str == null || "".equals(str.trim())) {
// return true;
// } else {
// return false;
// }
// }
//
// /**
// * 判断是否不是空
// *
// * @param str
// * @return
// */
// public static boolean isNotEmpty(String str) {
// if ((str != null) && !"".equals(str.trim())) {
// return true;
// } else {
// return false;
// }
// }
//
// /**
// * 格式化模糊查询
// *
// * @param str
// * @return
// */
// public static String formatLike(String str) {
// if (isNotEmpty(str)) {
// return "%" + str + "%";
// } else {
// return null;
// }
// }
//
// /**
// * 返回"null"或者toString
// *
// * @param obj
// * @return
// */
// public static String toString(Object obj) {
// if (obj == null) return "null";
// return obj.toString();
// }
//
// /**
// * 用标签来连接string
// *
// * @param s
// * @param delimiter
// * @return
// */
// public static String join(Collection s, String delimiter) {
// StringBuffer buffer = new StringBuffer();
// Iterator iter = s.iterator();
// while (iter.hasNext()) {
// buffer.append(iter.next());
// if (iter.hasNext()) {
// buffer.append(delimiter);
// }
// }
// return buffer.toString();
// }
//
// /**
// * 首字母变大写
// * @param name
// * @return
// */
// public static String captureName(String name) {
// /*效率低的方法*/
// /* name = name.substring(0, 1).toUpperCase() + name.substring(1);
// return name;*/
//
// /*高效率方法*/
// char[] cs = name.toCharArray();
// cs[0] -= 32;
// return String.valueOf(cs);
// }
//
// /**
// * 去除%
// * @param str
// * @return
// */
// public static String reSqlLikeStr(String str) {
// return str.replace("%", "");
// }
//
//
// }
// Path: cjs_ssms_web/src/main/java/com/chengjs/cjsssmsweb/common/util/math/CashUtil.java
import com.chengjs.cjsssmsweb.common.util.StringUtil;
import java.math.BigDecimal;
import java.text.DecimalFormat;
package com.chengjs.cjsssmsweb.common.util.math;
/**
* CashUtil: 涉及金额的计算,以及double类型的计算
* author: Chengjs, version:1.0.0, 2017-09-08
*/
public class CashUtil {
/*格式化2位小数*/
private static java.text.DecimalFormat df2 = new java.text.DecimalFormat("############0.00");
/*格式化4位小数*/
private static java.text.DecimalFormat df4 = new java.text.DecimalFormat("############0.0000");
/*格式化6位小数*/
private static java.text.DecimalFormat df6 = new java.text.DecimalFormat("############0.000000");
/*如果有4位小数格式化4位小数,否则格式化成2位小数*/
private static java.text.DecimalFormat df2or4 = new java.text.DecimalFormat("############0.00##");
/**
* @param d d
* @param v v
* @return boolean
*/
public static boolean isDoubleEquals(double d, double v) {
return Math.abs(d - v) < 0.0000001;
}
/**
* 转换null为0.0d,主要用于从map中get数据时,避免空指针异常
*
* @param o 对象
* @return double
*/
public static double nvlDouble(Object o) {
double d = 0d; | if (!StringUtil.isNullOrEmpty(nvl(o))) { |
MiniPa/cjs_ssms | cjs_ssms_web/src/main/java/com/chengjs/cjsssmsweb/components/shiro/UUserRealm.java | // Path: cjs_ssms_web/src/main/java/com/chengjs/cjsssmsweb/mybatis/pojo/master/UUser.java
// @Table(name = "u_user")
// public class UUser {
// @Id
// @Column(name = "id")
// @GeneratedValue(strategy = GenerationType.IDENTITY, generator = "SELECT replace(t.uuid,\"-\",\"\") FROM (SELECT uuid() uuid FROM dual) t")
// private String id;
//
// @Column(name = "username")
// private String username;
//
// @Column(name = "password")
// private String password;
//
// @Column(name = "description")
// private String description;
//
// @Column(name = "discard")
// private String discard;
//
// @Column(name = "createtime")
// private Date createtime;
//
// @Column(name = "modifytime")
// private Date modifytime;
//
// /**
// * @return id
// */
// public String getId() {
// return id;
// }
//
// /**
// * @param id
// */
// public void setId(String id) {
// this.id = id == null ? null : id.trim();
// }
//
// /**
// * @return username
// */
// public String getUsername() {
// return username;
// }
//
// /**
// * @param username
// */
// public void setUsername(String username) {
// this.username = username == null ? null : username.trim();
// }
//
// /**
// * @return password
// */
// public String getPassword() {
// return password;
// }
//
// /**
// * @param password
// */
// public void setPassword(String password) {
// this.password = password == null ? null : password.trim();
// }
//
// /**
// * @return description
// */
// public String getDescription() {
// return description;
// }
//
// /**
// * @param description
// */
// public void setDescription(String description) {
// this.description = description == null ? null : description.trim();
// }
//
// /**
// * @return discard
// */
// public String getDiscard() {
// return discard;
// }
//
// /**
// * @param discard
// */
// public void setDiscard(String discard) {
// this.discard = discard == null ? null : discard.trim();
// }
//
// /**
// * @return createtime
// */
// public Date getCreatetime() {
// return createtime;
// }
//
// /**
// * @param createtime
// */
// public void setCreatetime(Date createtime) {
// this.createtime = createtime;
// }
//
// /**
// * @return modifytime
// */
// public Date getModifytime() {
// return modifytime;
// }
//
// /**
// * @param modifytime
// */
// public void setModifytime(Date modifytime) {
// this.modifytime = modifytime;
// }
// }
//
// Path: cjs_ssms_web/src/main/java/com/chengjs/cjsssmsweb/service/master/IUserManagerService.java
// public interface IUserManagerService {
//
// Set<String> findRoleNames(String UserName);
//
// Set<String> findPermissionNames(Set<String> roleNames);
//
// UUser findUserByUserName(String UserName);
//
// void registerUser(UUser uUser);
//
// }
| import com.chengjs.cjsssmsweb.mybatis.pojo.master.UUser;
import com.chengjs.cjsssmsweb.service.master.IUserManagerService;
import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.SimpleAuthenticationInfo;
import org.apache.shiro.authz.AuthorizationInfo;
import org.apache.shiro.authz.SimpleAuthorizationInfo;
import org.apache.shiro.realm.AuthorizingRealm;
import org.apache.shiro.subject.PrincipalCollection;
import javax.annotation.Resource;
import java.util.Set; | package com.chengjs.cjsssmsweb.components.shiro;
/**
* UserRealm:
* Realm: 其实现的数据模型规定了如何进行授权 与RDBMS LDAP等交流, 完全控制授权模型的创建和定义
* author: <a href="mailto:[email protected]">chengjs</a>, version:1.0.0, 2017/8/25
*/
public class UUserRealm extends AuthorizingRealm {
@Resource | // Path: cjs_ssms_web/src/main/java/com/chengjs/cjsssmsweb/mybatis/pojo/master/UUser.java
// @Table(name = "u_user")
// public class UUser {
// @Id
// @Column(name = "id")
// @GeneratedValue(strategy = GenerationType.IDENTITY, generator = "SELECT replace(t.uuid,\"-\",\"\") FROM (SELECT uuid() uuid FROM dual) t")
// private String id;
//
// @Column(name = "username")
// private String username;
//
// @Column(name = "password")
// private String password;
//
// @Column(name = "description")
// private String description;
//
// @Column(name = "discard")
// private String discard;
//
// @Column(name = "createtime")
// private Date createtime;
//
// @Column(name = "modifytime")
// private Date modifytime;
//
// /**
// * @return id
// */
// public String getId() {
// return id;
// }
//
// /**
// * @param id
// */
// public void setId(String id) {
// this.id = id == null ? null : id.trim();
// }
//
// /**
// * @return username
// */
// public String getUsername() {
// return username;
// }
//
// /**
// * @param username
// */
// public void setUsername(String username) {
// this.username = username == null ? null : username.trim();
// }
//
// /**
// * @return password
// */
// public String getPassword() {
// return password;
// }
//
// /**
// * @param password
// */
// public void setPassword(String password) {
// this.password = password == null ? null : password.trim();
// }
//
// /**
// * @return description
// */
// public String getDescription() {
// return description;
// }
//
// /**
// * @param description
// */
// public void setDescription(String description) {
// this.description = description == null ? null : description.trim();
// }
//
// /**
// * @return discard
// */
// public String getDiscard() {
// return discard;
// }
//
// /**
// * @param discard
// */
// public void setDiscard(String discard) {
// this.discard = discard == null ? null : discard.trim();
// }
//
// /**
// * @return createtime
// */
// public Date getCreatetime() {
// return createtime;
// }
//
// /**
// * @param createtime
// */
// public void setCreatetime(Date createtime) {
// this.createtime = createtime;
// }
//
// /**
// * @return modifytime
// */
// public Date getModifytime() {
// return modifytime;
// }
//
// /**
// * @param modifytime
// */
// public void setModifytime(Date modifytime) {
// this.modifytime = modifytime;
// }
// }
//
// Path: cjs_ssms_web/src/main/java/com/chengjs/cjsssmsweb/service/master/IUserManagerService.java
// public interface IUserManagerService {
//
// Set<String> findRoleNames(String UserName);
//
// Set<String> findPermissionNames(Set<String> roleNames);
//
// UUser findUserByUserName(String UserName);
//
// void registerUser(UUser uUser);
//
// }
// Path: cjs_ssms_web/src/main/java/com/chengjs/cjsssmsweb/components/shiro/UUserRealm.java
import com.chengjs.cjsssmsweb.mybatis.pojo.master.UUser;
import com.chengjs.cjsssmsweb.service.master.IUserManagerService;
import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.SimpleAuthenticationInfo;
import org.apache.shiro.authz.AuthorizationInfo;
import org.apache.shiro.authz.SimpleAuthorizationInfo;
import org.apache.shiro.realm.AuthorizingRealm;
import org.apache.shiro.subject.PrincipalCollection;
import javax.annotation.Resource;
import java.util.Set;
package com.chengjs.cjsssmsweb.components.shiro;
/**
* UserRealm:
* Realm: 其实现的数据模型规定了如何进行授权 与RDBMS LDAP等交流, 完全控制授权模型的创建和定义
* author: <a href="mailto:[email protected]">chengjs</a>, version:1.0.0, 2017/8/25
*/
public class UUserRealm extends AuthorizingRealm {
@Resource | private IUserManagerService userMService; |
MiniPa/cjs_ssms | cjs_ssms_web/src/main/java/com/chengjs/cjsssmsweb/components/shiro/UUserRealm.java | // Path: cjs_ssms_web/src/main/java/com/chengjs/cjsssmsweb/mybatis/pojo/master/UUser.java
// @Table(name = "u_user")
// public class UUser {
// @Id
// @Column(name = "id")
// @GeneratedValue(strategy = GenerationType.IDENTITY, generator = "SELECT replace(t.uuid,\"-\",\"\") FROM (SELECT uuid() uuid FROM dual) t")
// private String id;
//
// @Column(name = "username")
// private String username;
//
// @Column(name = "password")
// private String password;
//
// @Column(name = "description")
// private String description;
//
// @Column(name = "discard")
// private String discard;
//
// @Column(name = "createtime")
// private Date createtime;
//
// @Column(name = "modifytime")
// private Date modifytime;
//
// /**
// * @return id
// */
// public String getId() {
// return id;
// }
//
// /**
// * @param id
// */
// public void setId(String id) {
// this.id = id == null ? null : id.trim();
// }
//
// /**
// * @return username
// */
// public String getUsername() {
// return username;
// }
//
// /**
// * @param username
// */
// public void setUsername(String username) {
// this.username = username == null ? null : username.trim();
// }
//
// /**
// * @return password
// */
// public String getPassword() {
// return password;
// }
//
// /**
// * @param password
// */
// public void setPassword(String password) {
// this.password = password == null ? null : password.trim();
// }
//
// /**
// * @return description
// */
// public String getDescription() {
// return description;
// }
//
// /**
// * @param description
// */
// public void setDescription(String description) {
// this.description = description == null ? null : description.trim();
// }
//
// /**
// * @return discard
// */
// public String getDiscard() {
// return discard;
// }
//
// /**
// * @param discard
// */
// public void setDiscard(String discard) {
// this.discard = discard == null ? null : discard.trim();
// }
//
// /**
// * @return createtime
// */
// public Date getCreatetime() {
// return createtime;
// }
//
// /**
// * @param createtime
// */
// public void setCreatetime(Date createtime) {
// this.createtime = createtime;
// }
//
// /**
// * @return modifytime
// */
// public Date getModifytime() {
// return modifytime;
// }
//
// /**
// * @param modifytime
// */
// public void setModifytime(Date modifytime) {
// this.modifytime = modifytime;
// }
// }
//
// Path: cjs_ssms_web/src/main/java/com/chengjs/cjsssmsweb/service/master/IUserManagerService.java
// public interface IUserManagerService {
//
// Set<String> findRoleNames(String UserName);
//
// Set<String> findPermissionNames(Set<String> roleNames);
//
// UUser findUserByUserName(String UserName);
//
// void registerUser(UUser uUser);
//
// }
| import com.chengjs.cjsssmsweb.mybatis.pojo.master.UUser;
import com.chengjs.cjsssmsweb.service.master.IUserManagerService;
import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.SimpleAuthenticationInfo;
import org.apache.shiro.authz.AuthorizationInfo;
import org.apache.shiro.authz.SimpleAuthorizationInfo;
import org.apache.shiro.realm.AuthorizingRealm;
import org.apache.shiro.subject.PrincipalCollection;
import javax.annotation.Resource;
import java.util.Set; | package com.chengjs.cjsssmsweb.components.shiro;
/**
* UserRealm:
* Realm: 其实现的数据模型规定了如何进行授权 与RDBMS LDAP等交流, 完全控制授权模型的创建和定义
* author: <a href="mailto:[email protected]">chengjs</a>, version:1.0.0, 2017/8/25
*/
public class UUserRealm extends AuthorizingRealm {
@Resource
private IUserManagerService userMService;
/**
* 权限认证
*
* @param principals
* @return AuthorizationInfo
*/
@Override
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
String principal_username = principals.getPrimaryPrincipal().toString();
SimpleAuthorizationInfo info = new SimpleAuthorizationInfo();
Set<String> roleNames = userMService.findRoleNames(principal_username);
Set<String> permissionNames = userMService.findPermissionNames(roleNames);
info.setRoles(roleNames);
//基于权限的授权相比基于角色的授权更好,更灵活,更符合实际情况
info.setStringPermissions(permissionNames);
return info;
}
/**
* 登录认证,在权限认证前执行
*
* @param token
* @return AuthenticationInfo
* @throws AuthenticationException
*/
@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
String username = token.getPrincipal().toString(); | // Path: cjs_ssms_web/src/main/java/com/chengjs/cjsssmsweb/mybatis/pojo/master/UUser.java
// @Table(name = "u_user")
// public class UUser {
// @Id
// @Column(name = "id")
// @GeneratedValue(strategy = GenerationType.IDENTITY, generator = "SELECT replace(t.uuid,\"-\",\"\") FROM (SELECT uuid() uuid FROM dual) t")
// private String id;
//
// @Column(name = "username")
// private String username;
//
// @Column(name = "password")
// private String password;
//
// @Column(name = "description")
// private String description;
//
// @Column(name = "discard")
// private String discard;
//
// @Column(name = "createtime")
// private Date createtime;
//
// @Column(name = "modifytime")
// private Date modifytime;
//
// /**
// * @return id
// */
// public String getId() {
// return id;
// }
//
// /**
// * @param id
// */
// public void setId(String id) {
// this.id = id == null ? null : id.trim();
// }
//
// /**
// * @return username
// */
// public String getUsername() {
// return username;
// }
//
// /**
// * @param username
// */
// public void setUsername(String username) {
// this.username = username == null ? null : username.trim();
// }
//
// /**
// * @return password
// */
// public String getPassword() {
// return password;
// }
//
// /**
// * @param password
// */
// public void setPassword(String password) {
// this.password = password == null ? null : password.trim();
// }
//
// /**
// * @return description
// */
// public String getDescription() {
// return description;
// }
//
// /**
// * @param description
// */
// public void setDescription(String description) {
// this.description = description == null ? null : description.trim();
// }
//
// /**
// * @return discard
// */
// public String getDiscard() {
// return discard;
// }
//
// /**
// * @param discard
// */
// public void setDiscard(String discard) {
// this.discard = discard == null ? null : discard.trim();
// }
//
// /**
// * @return createtime
// */
// public Date getCreatetime() {
// return createtime;
// }
//
// /**
// * @param createtime
// */
// public void setCreatetime(Date createtime) {
// this.createtime = createtime;
// }
//
// /**
// * @return modifytime
// */
// public Date getModifytime() {
// return modifytime;
// }
//
// /**
// * @param modifytime
// */
// public void setModifytime(Date modifytime) {
// this.modifytime = modifytime;
// }
// }
//
// Path: cjs_ssms_web/src/main/java/com/chengjs/cjsssmsweb/service/master/IUserManagerService.java
// public interface IUserManagerService {
//
// Set<String> findRoleNames(String UserName);
//
// Set<String> findPermissionNames(Set<String> roleNames);
//
// UUser findUserByUserName(String UserName);
//
// void registerUser(UUser uUser);
//
// }
// Path: cjs_ssms_web/src/main/java/com/chengjs/cjsssmsweb/components/shiro/UUserRealm.java
import com.chengjs.cjsssmsweb.mybatis.pojo.master.UUser;
import com.chengjs.cjsssmsweb.service.master.IUserManagerService;
import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.SimpleAuthenticationInfo;
import org.apache.shiro.authz.AuthorizationInfo;
import org.apache.shiro.authz.SimpleAuthorizationInfo;
import org.apache.shiro.realm.AuthorizingRealm;
import org.apache.shiro.subject.PrincipalCollection;
import javax.annotation.Resource;
import java.util.Set;
package com.chengjs.cjsssmsweb.components.shiro;
/**
* UserRealm:
* Realm: 其实现的数据模型规定了如何进行授权 与RDBMS LDAP等交流, 完全控制授权模型的创建和定义
* author: <a href="mailto:[email protected]">chengjs</a>, version:1.0.0, 2017/8/25
*/
public class UUserRealm extends AuthorizingRealm {
@Resource
private IUserManagerService userMService;
/**
* 权限认证
*
* @param principals
* @return AuthorizationInfo
*/
@Override
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
String principal_username = principals.getPrimaryPrincipal().toString();
SimpleAuthorizationInfo info = new SimpleAuthorizationInfo();
Set<String> roleNames = userMService.findRoleNames(principal_username);
Set<String> permissionNames = userMService.findPermissionNames(roleNames);
info.setRoles(roleNames);
//基于权限的授权相比基于角色的授权更好,更灵活,更符合实际情况
info.setStringPermissions(permissionNames);
return info;
}
/**
* 登录认证,在权限认证前执行
*
* @param token
* @return AuthenticationInfo
* @throws AuthenticationException
*/
@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
String username = token.getPrincipal().toString(); | UUser user = userMService.findUserByUserName(username); |
MiniPa/cjs_ssms | cjs_ssms_web/src/main/java/com/chengjs/cjsssmsweb/components/shiro/UserRealm.java | // Path: cjs_ssms_web/src/main/java/com/chengjs/cjsssmsweb/mybatis/pojo/master/UUser.java
// @Table(name = "u_user")
// public class UUser {
// @Id
// @Column(name = "id")
// @GeneratedValue(strategy = GenerationType.IDENTITY, generator = "SELECT replace(t.uuid,\"-\",\"\") FROM (SELECT uuid() uuid FROM dual) t")
// private String id;
//
// @Column(name = "username")
// private String username;
//
// @Column(name = "password")
// private String password;
//
// @Column(name = "description")
// private String description;
//
// @Column(name = "discard")
// private String discard;
//
// @Column(name = "createtime")
// private Date createtime;
//
// @Column(name = "modifytime")
// private Date modifytime;
//
// /**
// * @return id
// */
// public String getId() {
// return id;
// }
//
// /**
// * @param id
// */
// public void setId(String id) {
// this.id = id == null ? null : id.trim();
// }
//
// /**
// * @return username
// */
// public String getUsername() {
// return username;
// }
//
// /**
// * @param username
// */
// public void setUsername(String username) {
// this.username = username == null ? null : username.trim();
// }
//
// /**
// * @return password
// */
// public String getPassword() {
// return password;
// }
//
// /**
// * @param password
// */
// public void setPassword(String password) {
// this.password = password == null ? null : password.trim();
// }
//
// /**
// * @return description
// */
// public String getDescription() {
// return description;
// }
//
// /**
// * @param description
// */
// public void setDescription(String description) {
// this.description = description == null ? null : description.trim();
// }
//
// /**
// * @return discard
// */
// public String getDiscard() {
// return discard;
// }
//
// /**
// * @param discard
// */
// public void setDiscard(String discard) {
// this.discard = discard == null ? null : discard.trim();
// }
//
// /**
// * @return createtime
// */
// public Date getCreatetime() {
// return createtime;
// }
//
// /**
// * @param createtime
// */
// public void setCreatetime(Date createtime) {
// this.createtime = createtime;
// }
//
// /**
// * @return modifytime
// */
// public Date getModifytime() {
// return modifytime;
// }
//
// /**
// * @param modifytime
// */
// public void setModifytime(Date modifytime) {
// this.modifytime = modifytime;
// }
// }
//
// Path: cjs_ssms_web/src/main/java/com/chengjs/cjsssmsweb/service/master/IUserFrontService.java
// public interface IUserFrontService {
//
// public UUser getUserById(String userid);
// public UUser findByLogin(UUser user) ;
//
// public int createUser(UUser user) ;
// public Page<UUser> findByParams(UUser user, int pageNo, int limit) ;
//
// int deleteByPrimaryKey(String userid);
// int updateByPrimaryKeySelective(UUser user);
//
// int findAllCount(UUser user) ;
// List<UUser> findHotUser() ;
// List<UUser> findAllByQuery(UUser user) ;
//
// /**
// * 分页查询
// * @param map
// * @return
// */
// public List<UUser> list(Map<String, Object> map) ;
//
// public Long getTotal(Map<String, Object> map);
//
//
// /**
// * Shiro的登录验证,通过用户名查询用户信息
// * @param username
// * @return
// */
// public UUser findUserByUsername(String username) ;
//
// Set<String> findRoleNames(String username);
//
// Set<String> findPermissionNames(Set<String> roleNames);
//
// boolean registerUser(UUser user);
// }
| import com.chengjs.cjsssmsweb.mybatis.pojo.master.UUser;
import com.chengjs.cjsssmsweb.service.master.IUserFrontService;
import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.SimpleAuthenticationInfo;
import org.apache.shiro.authz.AuthorizationInfo;
import org.apache.shiro.authz.SimpleAuthorizationInfo;
import org.apache.shiro.realm.AuthorizingRealm;
import org.apache.shiro.subject.PrincipalCollection;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.Set; | package com.chengjs.cjsssmsweb.components.shiro;
/**
* UserRealm:
*
* eao issue: 多Reaml配置 TODO
*
* Realm: 其实现的数据模型规定了如何进行授权 与RDBMS LDAP等交流, 完全控制授权模型的创建和定义
* author: <a href="mailto:[email protected]">chengjs</a>, version:1.0.0, 2017/8/25
*/
public class UserRealm extends AuthorizingRealm {
@Autowired | // Path: cjs_ssms_web/src/main/java/com/chengjs/cjsssmsweb/mybatis/pojo/master/UUser.java
// @Table(name = "u_user")
// public class UUser {
// @Id
// @Column(name = "id")
// @GeneratedValue(strategy = GenerationType.IDENTITY, generator = "SELECT replace(t.uuid,\"-\",\"\") FROM (SELECT uuid() uuid FROM dual) t")
// private String id;
//
// @Column(name = "username")
// private String username;
//
// @Column(name = "password")
// private String password;
//
// @Column(name = "description")
// private String description;
//
// @Column(name = "discard")
// private String discard;
//
// @Column(name = "createtime")
// private Date createtime;
//
// @Column(name = "modifytime")
// private Date modifytime;
//
// /**
// * @return id
// */
// public String getId() {
// return id;
// }
//
// /**
// * @param id
// */
// public void setId(String id) {
// this.id = id == null ? null : id.trim();
// }
//
// /**
// * @return username
// */
// public String getUsername() {
// return username;
// }
//
// /**
// * @param username
// */
// public void setUsername(String username) {
// this.username = username == null ? null : username.trim();
// }
//
// /**
// * @return password
// */
// public String getPassword() {
// return password;
// }
//
// /**
// * @param password
// */
// public void setPassword(String password) {
// this.password = password == null ? null : password.trim();
// }
//
// /**
// * @return description
// */
// public String getDescription() {
// return description;
// }
//
// /**
// * @param description
// */
// public void setDescription(String description) {
// this.description = description == null ? null : description.trim();
// }
//
// /**
// * @return discard
// */
// public String getDiscard() {
// return discard;
// }
//
// /**
// * @param discard
// */
// public void setDiscard(String discard) {
// this.discard = discard == null ? null : discard.trim();
// }
//
// /**
// * @return createtime
// */
// public Date getCreatetime() {
// return createtime;
// }
//
// /**
// * @param createtime
// */
// public void setCreatetime(Date createtime) {
// this.createtime = createtime;
// }
//
// /**
// * @return modifytime
// */
// public Date getModifytime() {
// return modifytime;
// }
//
// /**
// * @param modifytime
// */
// public void setModifytime(Date modifytime) {
// this.modifytime = modifytime;
// }
// }
//
// Path: cjs_ssms_web/src/main/java/com/chengjs/cjsssmsweb/service/master/IUserFrontService.java
// public interface IUserFrontService {
//
// public UUser getUserById(String userid);
// public UUser findByLogin(UUser user) ;
//
// public int createUser(UUser user) ;
// public Page<UUser> findByParams(UUser user, int pageNo, int limit) ;
//
// int deleteByPrimaryKey(String userid);
// int updateByPrimaryKeySelective(UUser user);
//
// int findAllCount(UUser user) ;
// List<UUser> findHotUser() ;
// List<UUser> findAllByQuery(UUser user) ;
//
// /**
// * 分页查询
// * @param map
// * @return
// */
// public List<UUser> list(Map<String, Object> map) ;
//
// public Long getTotal(Map<String, Object> map);
//
//
// /**
// * Shiro的登录验证,通过用户名查询用户信息
// * @param username
// * @return
// */
// public UUser findUserByUsername(String username) ;
//
// Set<String> findRoleNames(String username);
//
// Set<String> findPermissionNames(Set<String> roleNames);
//
// boolean registerUser(UUser user);
// }
// Path: cjs_ssms_web/src/main/java/com/chengjs/cjsssmsweb/components/shiro/UserRealm.java
import com.chengjs.cjsssmsweb.mybatis.pojo.master.UUser;
import com.chengjs.cjsssmsweb.service.master.IUserFrontService;
import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.SimpleAuthenticationInfo;
import org.apache.shiro.authz.AuthorizationInfo;
import org.apache.shiro.authz.SimpleAuthorizationInfo;
import org.apache.shiro.realm.AuthorizingRealm;
import org.apache.shiro.subject.PrincipalCollection;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.Set;
package com.chengjs.cjsssmsweb.components.shiro;
/**
* UserRealm:
*
* eao issue: 多Reaml配置 TODO
*
* Realm: 其实现的数据模型规定了如何进行授权 与RDBMS LDAP等交流, 完全控制授权模型的创建和定义
* author: <a href="mailto:[email protected]">chengjs</a>, version:1.0.0, 2017/8/25
*/
public class UserRealm extends AuthorizingRealm {
@Autowired | private IUserFrontService userFService; |
MiniPa/cjs_ssms | cjs_ssms_web/src/main/java/com/chengjs/cjsssmsweb/common/util/resources/PropertiesUtil.java | // Path: cjs_ssms_web/src/main/java/com/chengjs/cjsssmsweb/enums/EnvEnum.java
// public enum EnvEnum {
//
// /** 系统环境默认配置properties文件位置 */
// CJS_SSMS_PROP_PATH("/env-config.properties", "系统环境默认配置properties文件位置"),
//
// /** lucene索引位置--env-config.properties 里配置此路径实际位置 */
// LUCENE_INDEX_PATH("lucene.store", "lucene索引文件位置"),
//
// /** 系统请求路径配置 8080*/
// IP8080("http://localhost:8080/","系统请求路径配置 8080"),
//
// /** 系统请求路径配置 9000*/
// IP9000("http://localhost:9000/","系统请求路径配置 9000")
//
//
//
//
//
//
//
//
// ;
//
// /*===================================== string Enum General Method =====================================*/
//
// /** 枚举值 */
// private final String val;
//
// /** 枚举描述 */
// private final String message;
//
// /**
// * 构建一个 EvnEnum 。
// * @param val 枚举值。
// * @param message 枚举描述。
// */
// private EnvEnum(String val, String message) {
// this.val = val;
// this.message = message;
// }
//
// /**
// * 得到枚举值。
// * @return 枚举值。
// */
// public String getVal() {
// return val;
// }
//
// /**
// * 得到枚举描述。
// * @return 枚举描述。
// */
// public String getMessage() {
// return message;
// }
//
// /**
// * 得到枚举值。
// * @return 枚举值。
// */
// public String val() {
// return val;
// }
//
// /**
// * 得到枚举描述。
// * @return 枚举描述。
// */
// public String message() {
// return message;
// }
//
// /**
// * 通过枚举值查找枚举值。
// * @param val 查找枚举值的枚举值。
// * @return 枚举值对应的枚举值。
// * @throws IllegalArgumentException 如果 val 没有对应的 EvnEnum 。
// */
// public static EnvEnum findStatus(String val) {
// for (EnvEnum status : values()) {
// if (status.getVal().equals(val)) {
// return status;
// }
// }
// throw new IllegalArgumentException("ResultInfo EvnEnum not legal:" + val);
// }
//
// /**
// * 获取全部枚举值。
// *
// * @return 全部枚举值。
// */
// public static List<EnvEnum> getAllStatus() {
// List<EnvEnum> list = new ArrayList<EnvEnum>();
// for (EnvEnum status : values()) {
// list.add(status);
// }
// return list;
// }
//
// /**
// * 获取全部枚举值。
// *
// * @return 全部枚举值。
// */
// public static List<String> getAllStatusVal() {
// List<String> list = new ArrayList<String>();
// for (EnvEnum status : values()) {
// list.add(status.val());
// }
// return list;
// }
//
//
// }
| import com.chengjs.cjsssmsweb.enums.EnvEnum;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.UnsupportedEncodingException;
import java.util.Iterator;
import java.util.Properties;
import java.util.Set; | package com.chengjs.cjsssmsweb.common.util.resources;
/**
* PropertiesUtil:
* author: Chengjs, version:1.0.0, 2017-08-05
*/
public class PropertiesUtil {
private static Logger log = LoggerFactory.getLogger(PropertiesUtil.class);
private static Properties prop = new Properties();
private Long lastModified = 0l;// TODO 热加载
static {
try { | // Path: cjs_ssms_web/src/main/java/com/chengjs/cjsssmsweb/enums/EnvEnum.java
// public enum EnvEnum {
//
// /** 系统环境默认配置properties文件位置 */
// CJS_SSMS_PROP_PATH("/env-config.properties", "系统环境默认配置properties文件位置"),
//
// /** lucene索引位置--env-config.properties 里配置此路径实际位置 */
// LUCENE_INDEX_PATH("lucene.store", "lucene索引文件位置"),
//
// /** 系统请求路径配置 8080*/
// IP8080("http://localhost:8080/","系统请求路径配置 8080"),
//
// /** 系统请求路径配置 9000*/
// IP9000("http://localhost:9000/","系统请求路径配置 9000")
//
//
//
//
//
//
//
//
// ;
//
// /*===================================== string Enum General Method =====================================*/
//
// /** 枚举值 */
// private final String val;
//
// /** 枚举描述 */
// private final String message;
//
// /**
// * 构建一个 EvnEnum 。
// * @param val 枚举值。
// * @param message 枚举描述。
// */
// private EnvEnum(String val, String message) {
// this.val = val;
// this.message = message;
// }
//
// /**
// * 得到枚举值。
// * @return 枚举值。
// */
// public String getVal() {
// return val;
// }
//
// /**
// * 得到枚举描述。
// * @return 枚举描述。
// */
// public String getMessage() {
// return message;
// }
//
// /**
// * 得到枚举值。
// * @return 枚举值。
// */
// public String val() {
// return val;
// }
//
// /**
// * 得到枚举描述。
// * @return 枚举描述。
// */
// public String message() {
// return message;
// }
//
// /**
// * 通过枚举值查找枚举值。
// * @param val 查找枚举值的枚举值。
// * @return 枚举值对应的枚举值。
// * @throws IllegalArgumentException 如果 val 没有对应的 EvnEnum 。
// */
// public static EnvEnum findStatus(String val) {
// for (EnvEnum status : values()) {
// if (status.getVal().equals(val)) {
// return status;
// }
// }
// throw new IllegalArgumentException("ResultInfo EvnEnum not legal:" + val);
// }
//
// /**
// * 获取全部枚举值。
// *
// * @return 全部枚举值。
// */
// public static List<EnvEnum> getAllStatus() {
// List<EnvEnum> list = new ArrayList<EnvEnum>();
// for (EnvEnum status : values()) {
// list.add(status);
// }
// return list;
// }
//
// /**
// * 获取全部枚举值。
// *
// * @return 全部枚举值。
// */
// public static List<String> getAllStatusVal() {
// List<String> list = new ArrayList<String>();
// for (EnvEnum status : values()) {
// list.add(status.val());
// }
// return list;
// }
//
//
// }
// Path: cjs_ssms_web/src/main/java/com/chengjs/cjsssmsweb/common/util/resources/PropertiesUtil.java
import com.chengjs.cjsssmsweb.enums.EnvEnum;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.UnsupportedEncodingException;
import java.util.Iterator;
import java.util.Properties;
import java.util.Set;
package com.chengjs.cjsssmsweb.common.util.resources;
/**
* PropertiesUtil:
* author: Chengjs, version:1.0.0, 2017-08-05
*/
public class PropertiesUtil {
private static Logger log = LoggerFactory.getLogger(PropertiesUtil.class);
private static Properties prop = new Properties();
private Long lastModified = 0l;// TODO 热加载
static {
try { | prop.load(PropertiesUtil.class.getResourceAsStream(EnvEnum.CJS_SSMS_PROP_PATH.val())); |
MiniPa/cjs_ssms | cjs_ssms_web/src/main/java/com/chengjs/cjsssmsweb/service/master/IUserFrontService.java | // Path: cjs_ssms_web/src/main/java/com/chengjs/cjsssmsweb/mybatis/pojo/master/UUser.java
// @Table(name = "u_user")
// public class UUser {
// @Id
// @Column(name = "id")
// @GeneratedValue(strategy = GenerationType.IDENTITY, generator = "SELECT replace(t.uuid,\"-\",\"\") FROM (SELECT uuid() uuid FROM dual) t")
// private String id;
//
// @Column(name = "username")
// private String username;
//
// @Column(name = "password")
// private String password;
//
// @Column(name = "description")
// private String description;
//
// @Column(name = "discard")
// private String discard;
//
// @Column(name = "createtime")
// private Date createtime;
//
// @Column(name = "modifytime")
// private Date modifytime;
//
// /**
// * @return id
// */
// public String getId() {
// return id;
// }
//
// /**
// * @param id
// */
// public void setId(String id) {
// this.id = id == null ? null : id.trim();
// }
//
// /**
// * @return username
// */
// public String getUsername() {
// return username;
// }
//
// /**
// * @param username
// */
// public void setUsername(String username) {
// this.username = username == null ? null : username.trim();
// }
//
// /**
// * @return password
// */
// public String getPassword() {
// return password;
// }
//
// /**
// * @param password
// */
// public void setPassword(String password) {
// this.password = password == null ? null : password.trim();
// }
//
// /**
// * @return description
// */
// public String getDescription() {
// return description;
// }
//
// /**
// * @param description
// */
// public void setDescription(String description) {
// this.description = description == null ? null : description.trim();
// }
//
// /**
// * @return discard
// */
// public String getDiscard() {
// return discard;
// }
//
// /**
// * @param discard
// */
// public void setDiscard(String discard) {
// this.discard = discard == null ? null : discard.trim();
// }
//
// /**
// * @return createtime
// */
// public Date getCreatetime() {
// return createtime;
// }
//
// /**
// * @param createtime
// */
// public void setCreatetime(Date createtime) {
// this.createtime = createtime;
// }
//
// /**
// * @return modifytime
// */
// public Date getModifytime() {
// return modifytime;
// }
//
// /**
// * @param modifytime
// */
// public void setModifytime(Date modifytime) {
// this.modifytime = modifytime;
// }
// }
//
// Path: cjs_ssms_web/src/main/java/com/chengjs/cjsssmsweb/util/page/Page.java
// public class Page<T> implements Serializable {
// private static final long serialVersionUID = 1L;
// /**
// * 每页显示的数量
// **/
// private int limit;
// /**
// * 总条数
// **/
// private int total;
// /**
// * 当前页数
// **/
// private int pageNo;
// /**
// * 存放集合
// **/
// private List<T> rows = new ArrayList<T>();
//
// public int getOffset() {
// return (pageNo - 1) * limit;
// }
//
// public void setOffset(int offset) {
// }
//
// public void setTotal(int total) {
// this.total = total;
// }
//
// public int getLimit() {
// return limit;
// }
//
// public void setLimit(int limit) {
// this.limit = limit;
// }
//
//
// public List<T> getRows() {
// return rows;
// }
//
// public void setRows(List<T> rows) {
// this.rows = rows;
// }
//
// // 计算总页数
// public int getTotalPages() {
// int totalPages;
// if (total % limit == 0) {
// totalPages = total / limit;
// } else {
// totalPages = (total / limit) + 1;
// }
// return totalPages;
// }
//
// public int getTotal() {
// return total;
// }
//
// public int getOffsets() {
// return (pageNo - 1) * limit;
// }
//
// public int getEndIndex() {
// if (getOffsets() + limit > total) {
// return total;
// } else {
// return getOffsets() + limit;
// }
// }
//
// public int getPageNo() {
// return pageNo;
// }
//
// public void setPageNo(int pageNo) {
// this.pageNo = pageNo;
// }
// }
| import com.chengjs.cjsssmsweb.mybatis.pojo.master.UUser;
import com.chengjs.cjsssmsweb.util.page.Page;
import java.util.List;
import java.util.Map;
import java.util.Set; | package com.chengjs.cjsssmsweb.service.master;
/**
* IUserFrontService:
* author: <a href="mailto:[email protected]">chengjs</a>, version:1.0.0, 21:18
*/
public interface IUserFrontService {
public UUser getUserById(String userid);
public UUser findByLogin(UUser user) ;
public int createUser(UUser user) ; | // Path: cjs_ssms_web/src/main/java/com/chengjs/cjsssmsweb/mybatis/pojo/master/UUser.java
// @Table(name = "u_user")
// public class UUser {
// @Id
// @Column(name = "id")
// @GeneratedValue(strategy = GenerationType.IDENTITY, generator = "SELECT replace(t.uuid,\"-\",\"\") FROM (SELECT uuid() uuid FROM dual) t")
// private String id;
//
// @Column(name = "username")
// private String username;
//
// @Column(name = "password")
// private String password;
//
// @Column(name = "description")
// private String description;
//
// @Column(name = "discard")
// private String discard;
//
// @Column(name = "createtime")
// private Date createtime;
//
// @Column(name = "modifytime")
// private Date modifytime;
//
// /**
// * @return id
// */
// public String getId() {
// return id;
// }
//
// /**
// * @param id
// */
// public void setId(String id) {
// this.id = id == null ? null : id.trim();
// }
//
// /**
// * @return username
// */
// public String getUsername() {
// return username;
// }
//
// /**
// * @param username
// */
// public void setUsername(String username) {
// this.username = username == null ? null : username.trim();
// }
//
// /**
// * @return password
// */
// public String getPassword() {
// return password;
// }
//
// /**
// * @param password
// */
// public void setPassword(String password) {
// this.password = password == null ? null : password.trim();
// }
//
// /**
// * @return description
// */
// public String getDescription() {
// return description;
// }
//
// /**
// * @param description
// */
// public void setDescription(String description) {
// this.description = description == null ? null : description.trim();
// }
//
// /**
// * @return discard
// */
// public String getDiscard() {
// return discard;
// }
//
// /**
// * @param discard
// */
// public void setDiscard(String discard) {
// this.discard = discard == null ? null : discard.trim();
// }
//
// /**
// * @return createtime
// */
// public Date getCreatetime() {
// return createtime;
// }
//
// /**
// * @param createtime
// */
// public void setCreatetime(Date createtime) {
// this.createtime = createtime;
// }
//
// /**
// * @return modifytime
// */
// public Date getModifytime() {
// return modifytime;
// }
//
// /**
// * @param modifytime
// */
// public void setModifytime(Date modifytime) {
// this.modifytime = modifytime;
// }
// }
//
// Path: cjs_ssms_web/src/main/java/com/chengjs/cjsssmsweb/util/page/Page.java
// public class Page<T> implements Serializable {
// private static final long serialVersionUID = 1L;
// /**
// * 每页显示的数量
// **/
// private int limit;
// /**
// * 总条数
// **/
// private int total;
// /**
// * 当前页数
// **/
// private int pageNo;
// /**
// * 存放集合
// **/
// private List<T> rows = new ArrayList<T>();
//
// public int getOffset() {
// return (pageNo - 1) * limit;
// }
//
// public void setOffset(int offset) {
// }
//
// public void setTotal(int total) {
// this.total = total;
// }
//
// public int getLimit() {
// return limit;
// }
//
// public void setLimit(int limit) {
// this.limit = limit;
// }
//
//
// public List<T> getRows() {
// return rows;
// }
//
// public void setRows(List<T> rows) {
// this.rows = rows;
// }
//
// // 计算总页数
// public int getTotalPages() {
// int totalPages;
// if (total % limit == 0) {
// totalPages = total / limit;
// } else {
// totalPages = (total / limit) + 1;
// }
// return totalPages;
// }
//
// public int getTotal() {
// return total;
// }
//
// public int getOffsets() {
// return (pageNo - 1) * limit;
// }
//
// public int getEndIndex() {
// if (getOffsets() + limit > total) {
// return total;
// } else {
// return getOffsets() + limit;
// }
// }
//
// public int getPageNo() {
// return pageNo;
// }
//
// public void setPageNo(int pageNo) {
// this.pageNo = pageNo;
// }
// }
// Path: cjs_ssms_web/src/main/java/com/chengjs/cjsssmsweb/service/master/IUserFrontService.java
import com.chengjs.cjsssmsweb.mybatis.pojo.master.UUser;
import com.chengjs.cjsssmsweb.util.page.Page;
import java.util.List;
import java.util.Map;
import java.util.Set;
package com.chengjs.cjsssmsweb.service.master;
/**
* IUserFrontService:
* author: <a href="mailto:[email protected]">chengjs</a>, version:1.0.0, 21:18
*/
public interface IUserFrontService {
public UUser getUserById(String userid);
public UUser findByLogin(UUser user) ;
public int createUser(UUser user) ; | public Page<UUser> findByParams(UUser user, int pageNo, int limit) ; |
MiniPa/cjs_ssms | cjs_ssms_web/src/main/java/com/chengjs/cjsssmsweb/components/cxf/WSClientTest.java | // Path: cjs_ssms_web/src/main/java/com/chengjs/cjsssmsweb/enums/EnvEnum.java
// public enum EnvEnum {
//
// /** 系统环境默认配置properties文件位置 */
// CJS_SSMS_PROP_PATH("/env-config.properties", "系统环境默认配置properties文件位置"),
//
// /** lucene索引位置--env-config.properties 里配置此路径实际位置 */
// LUCENE_INDEX_PATH("lucene.store", "lucene索引文件位置"),
//
// /** 系统请求路径配置 8080*/
// IP8080("http://localhost:8080/","系统请求路径配置 8080"),
//
// /** 系统请求路径配置 9000*/
// IP9000("http://localhost:9000/","系统请求路径配置 9000")
//
//
//
//
//
//
//
//
// ;
//
// /*===================================== string Enum General Method =====================================*/
//
// /** 枚举值 */
// private final String val;
//
// /** 枚举描述 */
// private final String message;
//
// /**
// * 构建一个 EvnEnum 。
// * @param val 枚举值。
// * @param message 枚举描述。
// */
// private EnvEnum(String val, String message) {
// this.val = val;
// this.message = message;
// }
//
// /**
// * 得到枚举值。
// * @return 枚举值。
// */
// public String getVal() {
// return val;
// }
//
// /**
// * 得到枚举描述。
// * @return 枚举描述。
// */
// public String getMessage() {
// return message;
// }
//
// /**
// * 得到枚举值。
// * @return 枚举值。
// */
// public String val() {
// return val;
// }
//
// /**
// * 得到枚举描述。
// * @return 枚举描述。
// */
// public String message() {
// return message;
// }
//
// /**
// * 通过枚举值查找枚举值。
// * @param val 查找枚举值的枚举值。
// * @return 枚举值对应的枚举值。
// * @throws IllegalArgumentException 如果 val 没有对应的 EvnEnum 。
// */
// public static EnvEnum findStatus(String val) {
// for (EnvEnum status : values()) {
// if (status.getVal().equals(val)) {
// return status;
// }
// }
// throw new IllegalArgumentException("ResultInfo EvnEnum not legal:" + val);
// }
//
// /**
// * 获取全部枚举值。
// *
// * @return 全部枚举值。
// */
// public static List<EnvEnum> getAllStatus() {
// List<EnvEnum> list = new ArrayList<EnvEnum>();
// for (EnvEnum status : values()) {
// list.add(status);
// }
// return list;
// }
//
// /**
// * 获取全部枚举值。
// *
// * @return 全部枚举值。
// */
// public static List<String> getAllStatusVal() {
// List<String> list = new ArrayList<String>();
// for (EnvEnum status : values()) {
// list.add(status.val());
// }
// return list;
// }
//
//
// }
| import com.chengjs.cjsssmsweb.enums.EnvEnum;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL; | package com.chengjs.cjsssmsweb.components.cxf;
/**
* WS2ClientTest: WebService后端UrlConnection调用
*
* @author: <a href="mailto:[email protected]">chengjs_minipa</a>, version:1.0.0, 2017/9/2
*/
public class WSClientTest {
/**
* 方法名
*/
private static final String METHOD = "say";
/**
* 请求参数
*/
private static final String PARAM = "chengjs";
/**
* 参数指代接口命名空间,可在wsdl请求返回信息中找到
*/
private static final String SERVICE_NAMESPACE = "http://cxf.components.cjsssmsweb.chengjs.com/";
/**
* 调用接口:http://blog.csdn.net/u011165335/article/details/51345224
* http://www.cnblogs.com/siqi/archive/2013/12/15/3475222.html
* @param args
*/
public static void main(String[] args) throws IOException {
//服务的地址
// URL wsUrl = new URL(EnvEnum.IP9000.getVal()+"wSSample"); | // Path: cjs_ssms_web/src/main/java/com/chengjs/cjsssmsweb/enums/EnvEnum.java
// public enum EnvEnum {
//
// /** 系统环境默认配置properties文件位置 */
// CJS_SSMS_PROP_PATH("/env-config.properties", "系统环境默认配置properties文件位置"),
//
// /** lucene索引位置--env-config.properties 里配置此路径实际位置 */
// LUCENE_INDEX_PATH("lucene.store", "lucene索引文件位置"),
//
// /** 系统请求路径配置 8080*/
// IP8080("http://localhost:8080/","系统请求路径配置 8080"),
//
// /** 系统请求路径配置 9000*/
// IP9000("http://localhost:9000/","系统请求路径配置 9000")
//
//
//
//
//
//
//
//
// ;
//
// /*===================================== string Enum General Method =====================================*/
//
// /** 枚举值 */
// private final String val;
//
// /** 枚举描述 */
// private final String message;
//
// /**
// * 构建一个 EvnEnum 。
// * @param val 枚举值。
// * @param message 枚举描述。
// */
// private EnvEnum(String val, String message) {
// this.val = val;
// this.message = message;
// }
//
// /**
// * 得到枚举值。
// * @return 枚举值。
// */
// public String getVal() {
// return val;
// }
//
// /**
// * 得到枚举描述。
// * @return 枚举描述。
// */
// public String getMessage() {
// return message;
// }
//
// /**
// * 得到枚举值。
// * @return 枚举值。
// */
// public String val() {
// return val;
// }
//
// /**
// * 得到枚举描述。
// * @return 枚举描述。
// */
// public String message() {
// return message;
// }
//
// /**
// * 通过枚举值查找枚举值。
// * @param val 查找枚举值的枚举值。
// * @return 枚举值对应的枚举值。
// * @throws IllegalArgumentException 如果 val 没有对应的 EvnEnum 。
// */
// public static EnvEnum findStatus(String val) {
// for (EnvEnum status : values()) {
// if (status.getVal().equals(val)) {
// return status;
// }
// }
// throw new IllegalArgumentException("ResultInfo EvnEnum not legal:" + val);
// }
//
// /**
// * 获取全部枚举值。
// *
// * @return 全部枚举值。
// */
// public static List<EnvEnum> getAllStatus() {
// List<EnvEnum> list = new ArrayList<EnvEnum>();
// for (EnvEnum status : values()) {
// list.add(status);
// }
// return list;
// }
//
// /**
// * 获取全部枚举值。
// *
// * @return 全部枚举值。
// */
// public static List<String> getAllStatusVal() {
// List<String> list = new ArrayList<String>();
// for (EnvEnum status : values()) {
// list.add(status.val());
// }
// return list;
// }
//
//
// }
// Path: cjs_ssms_web/src/main/java/com/chengjs/cjsssmsweb/components/cxf/WSClientTest.java
import com.chengjs.cjsssmsweb.enums.EnvEnum;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
package com.chengjs.cjsssmsweb.components.cxf;
/**
* WS2ClientTest: WebService后端UrlConnection调用
*
* @author: <a href="mailto:[email protected]">chengjs_minipa</a>, version:1.0.0, 2017/9/2
*/
public class WSClientTest {
/**
* 方法名
*/
private static final String METHOD = "say";
/**
* 请求参数
*/
private static final String PARAM = "chengjs";
/**
* 参数指代接口命名空间,可在wsdl请求返回信息中找到
*/
private static final String SERVICE_NAMESPACE = "http://cxf.components.cjsssmsweb.chengjs.com/";
/**
* 调用接口:http://blog.csdn.net/u011165335/article/details/51345224
* http://www.cnblogs.com/siqi/archive/2013/12/15/3475222.html
* @param args
*/
public static void main(String[] args) throws IOException {
//服务的地址
// URL wsUrl = new URL(EnvEnum.IP9000.getVal()+"wSSample"); | URL wsUrl = new URL(EnvEnum.IP8080.getVal()+"webservice/wSSample");/*webservice是web.xml中配置的 tomcat发布接口测试*/ |
MiniPa/cjs_ssms | cjs_ssms_web/src/main/java/com/chengjs/cjsssmsweb/common/util/codec/MD5Util.java | // Path: cjs_ssms_web/src/main/java/com/chengjs/cjsssmsweb/common/util/StringUtil.java
// public class StringUtil {
//
// /**
// * 字符串是否为空,包括blank
// *
// * @param str
// * @return
// */
// public static boolean isNullOrEmpty(String str) {
// return null != str && 0 != str.trim().length() ? false : true;
// }
//
// /**
// * 返回"null" 或者 toString
// *
// * @param obj
// * @return
// */
// public static boolean reNullOrEmpty(Object obj) {
// return obj == null || "".equals(obj.toString());
// }
//
// /**
// * 判断是否是空
// *
// * @param str
// * @return
// */
// public static boolean isEmpty(String str) {
// if (str == null || "".equals(str.trim())) {
// return true;
// } else {
// return false;
// }
// }
//
// /**
// * 判断是否不是空
// *
// * @param str
// * @return
// */
// public static boolean isNotEmpty(String str) {
// if ((str != null) && !"".equals(str.trim())) {
// return true;
// } else {
// return false;
// }
// }
//
// /**
// * 格式化模糊查询
// *
// * @param str
// * @return
// */
// public static String formatLike(String str) {
// if (isNotEmpty(str)) {
// return "%" + str + "%";
// } else {
// return null;
// }
// }
//
// /**
// * 返回"null"或者toString
// *
// * @param obj
// * @return
// */
// public static String toString(Object obj) {
// if (obj == null) return "null";
// return obj.toString();
// }
//
// /**
// * 用标签来连接string
// *
// * @param s
// * @param delimiter
// * @return
// */
// public static String join(Collection s, String delimiter) {
// StringBuffer buffer = new StringBuffer();
// Iterator iter = s.iterator();
// while (iter.hasNext()) {
// buffer.append(iter.next());
// if (iter.hasNext()) {
// buffer.append(delimiter);
// }
// }
// return buffer.toString();
// }
//
// /**
// * 首字母变大写
// * @param name
// * @return
// */
// public static String captureName(String name) {
// /*效率低的方法*/
// /* name = name.substring(0, 1).toUpperCase() + name.substring(1);
// return name;*/
//
// /*高效率方法*/
// char[] cs = name.toCharArray();
// cs[0] -= 32;
// return String.valueOf(cs);
// }
//
// /**
// * 去除%
// * @param str
// * @return
// */
// public static String reSqlLikeStr(String str) {
// return str.replace("%", "");
// }
//
//
// }
| import com.chengjs.cjsssmsweb.common.util.StringUtil;
import org.apache.shiro.crypto.hash.Md5Hash; | package com.chengjs.cjsssmsweb.common.util.codec;
/**
* MD5Util: 基于shiro的MD5加密
* author: <a href="mailto:[email protected]">chengjs</a>, version:1.0.0, 2017/8/25
*/
public class MD5Util {
public static final String DEFAULT_SALT = "minipa_chengjs";
/**
* 指定加密盐
* @param str
* @param salt
* @return
*/
public static String md5(String str, String salt){ | // Path: cjs_ssms_web/src/main/java/com/chengjs/cjsssmsweb/common/util/StringUtil.java
// public class StringUtil {
//
// /**
// * 字符串是否为空,包括blank
// *
// * @param str
// * @return
// */
// public static boolean isNullOrEmpty(String str) {
// return null != str && 0 != str.trim().length() ? false : true;
// }
//
// /**
// * 返回"null" 或者 toString
// *
// * @param obj
// * @return
// */
// public static boolean reNullOrEmpty(Object obj) {
// return obj == null || "".equals(obj.toString());
// }
//
// /**
// * 判断是否是空
// *
// * @param str
// * @return
// */
// public static boolean isEmpty(String str) {
// if (str == null || "".equals(str.trim())) {
// return true;
// } else {
// return false;
// }
// }
//
// /**
// * 判断是否不是空
// *
// * @param str
// * @return
// */
// public static boolean isNotEmpty(String str) {
// if ((str != null) && !"".equals(str.trim())) {
// return true;
// } else {
// return false;
// }
// }
//
// /**
// * 格式化模糊查询
// *
// * @param str
// * @return
// */
// public static String formatLike(String str) {
// if (isNotEmpty(str)) {
// return "%" + str + "%";
// } else {
// return null;
// }
// }
//
// /**
// * 返回"null"或者toString
// *
// * @param obj
// * @return
// */
// public static String toString(Object obj) {
// if (obj == null) return "null";
// return obj.toString();
// }
//
// /**
// * 用标签来连接string
// *
// * @param s
// * @param delimiter
// * @return
// */
// public static String join(Collection s, String delimiter) {
// StringBuffer buffer = new StringBuffer();
// Iterator iter = s.iterator();
// while (iter.hasNext()) {
// buffer.append(iter.next());
// if (iter.hasNext()) {
// buffer.append(delimiter);
// }
// }
// return buffer.toString();
// }
//
// /**
// * 首字母变大写
// * @param name
// * @return
// */
// public static String captureName(String name) {
// /*效率低的方法*/
// /* name = name.substring(0, 1).toUpperCase() + name.substring(1);
// return name;*/
//
// /*高效率方法*/
// char[] cs = name.toCharArray();
// cs[0] -= 32;
// return String.valueOf(cs);
// }
//
// /**
// * 去除%
// * @param str
// * @return
// */
// public static String reSqlLikeStr(String str) {
// return str.replace("%", "");
// }
//
//
// }
// Path: cjs_ssms_web/src/main/java/com/chengjs/cjsssmsweb/common/util/codec/MD5Util.java
import com.chengjs.cjsssmsweb.common.util.StringUtil;
import org.apache.shiro.crypto.hash.Md5Hash;
package com.chengjs.cjsssmsweb.common.util.codec;
/**
* MD5Util: 基于shiro的MD5加密
* author: <a href="mailto:[email protected]">chengjs</a>, version:1.0.0, 2017/8/25
*/
public class MD5Util {
public static final String DEFAULT_SALT = "minipa_chengjs";
/**
* 指定加密盐
* @param str
* @param salt
* @return
*/
public static String md5(String str, String salt){ | if (StringUtil.isNullOrEmpty(salt)) { |
MiniPa/cjs_ssms | cjs_ssms_web/src/main/java/com/chengjs/cjsssmsweb/service/master/IUserManagerService.java | // Path: cjs_ssms_web/src/main/java/com/chengjs/cjsssmsweb/mybatis/pojo/master/UUser.java
// @Table(name = "u_user")
// public class UUser {
// @Id
// @Column(name = "id")
// @GeneratedValue(strategy = GenerationType.IDENTITY, generator = "SELECT replace(t.uuid,\"-\",\"\") FROM (SELECT uuid() uuid FROM dual) t")
// private String id;
//
// @Column(name = "username")
// private String username;
//
// @Column(name = "password")
// private String password;
//
// @Column(name = "description")
// private String description;
//
// @Column(name = "discard")
// private String discard;
//
// @Column(name = "createtime")
// private Date createtime;
//
// @Column(name = "modifytime")
// private Date modifytime;
//
// /**
// * @return id
// */
// public String getId() {
// return id;
// }
//
// /**
// * @param id
// */
// public void setId(String id) {
// this.id = id == null ? null : id.trim();
// }
//
// /**
// * @return username
// */
// public String getUsername() {
// return username;
// }
//
// /**
// * @param username
// */
// public void setUsername(String username) {
// this.username = username == null ? null : username.trim();
// }
//
// /**
// * @return password
// */
// public String getPassword() {
// return password;
// }
//
// /**
// * @param password
// */
// public void setPassword(String password) {
// this.password = password == null ? null : password.trim();
// }
//
// /**
// * @return description
// */
// public String getDescription() {
// return description;
// }
//
// /**
// * @param description
// */
// public void setDescription(String description) {
// this.description = description == null ? null : description.trim();
// }
//
// /**
// * @return discard
// */
// public String getDiscard() {
// return discard;
// }
//
// /**
// * @param discard
// */
// public void setDiscard(String discard) {
// this.discard = discard == null ? null : discard.trim();
// }
//
// /**
// * @return createtime
// */
// public Date getCreatetime() {
// return createtime;
// }
//
// /**
// * @param createtime
// */
// public void setCreatetime(Date createtime) {
// this.createtime = createtime;
// }
//
// /**
// * @return modifytime
// */
// public Date getModifytime() {
// return modifytime;
// }
//
// /**
// * @param modifytime
// */
// public void setModifytime(Date modifytime) {
// this.modifytime = modifytime;
// }
// }
| import com.chengjs.cjsssmsweb.mybatis.pojo.master.UUser;
import java.util.Set; | package com.chengjs.cjsssmsweb.service.master;
/**
* ISelectService:
* author: <a href="mailto:[email protected]">chengjs</a>, version:1.0.0, 2017/8/24
*/
public interface IUserManagerService {
Set<String> findRoleNames(String UserName);
Set<String> findPermissionNames(Set<String> roleNames);
| // Path: cjs_ssms_web/src/main/java/com/chengjs/cjsssmsweb/mybatis/pojo/master/UUser.java
// @Table(name = "u_user")
// public class UUser {
// @Id
// @Column(name = "id")
// @GeneratedValue(strategy = GenerationType.IDENTITY, generator = "SELECT replace(t.uuid,\"-\",\"\") FROM (SELECT uuid() uuid FROM dual) t")
// private String id;
//
// @Column(name = "username")
// private String username;
//
// @Column(name = "password")
// private String password;
//
// @Column(name = "description")
// private String description;
//
// @Column(name = "discard")
// private String discard;
//
// @Column(name = "createtime")
// private Date createtime;
//
// @Column(name = "modifytime")
// private Date modifytime;
//
// /**
// * @return id
// */
// public String getId() {
// return id;
// }
//
// /**
// * @param id
// */
// public void setId(String id) {
// this.id = id == null ? null : id.trim();
// }
//
// /**
// * @return username
// */
// public String getUsername() {
// return username;
// }
//
// /**
// * @param username
// */
// public void setUsername(String username) {
// this.username = username == null ? null : username.trim();
// }
//
// /**
// * @return password
// */
// public String getPassword() {
// return password;
// }
//
// /**
// * @param password
// */
// public void setPassword(String password) {
// this.password = password == null ? null : password.trim();
// }
//
// /**
// * @return description
// */
// public String getDescription() {
// return description;
// }
//
// /**
// * @param description
// */
// public void setDescription(String description) {
// this.description = description == null ? null : description.trim();
// }
//
// /**
// * @return discard
// */
// public String getDiscard() {
// return discard;
// }
//
// /**
// * @param discard
// */
// public void setDiscard(String discard) {
// this.discard = discard == null ? null : discard.trim();
// }
//
// /**
// * @return createtime
// */
// public Date getCreatetime() {
// return createtime;
// }
//
// /**
// * @param createtime
// */
// public void setCreatetime(Date createtime) {
// this.createtime = createtime;
// }
//
// /**
// * @return modifytime
// */
// public Date getModifytime() {
// return modifytime;
// }
//
// /**
// * @param modifytime
// */
// public void setModifytime(Date modifytime) {
// this.modifytime = modifytime;
// }
// }
// Path: cjs_ssms_web/src/main/java/com/chengjs/cjsssmsweb/service/master/IUserManagerService.java
import com.chengjs.cjsssmsweb.mybatis.pojo.master.UUser;
import java.util.Set;
package com.chengjs.cjsssmsweb.service.master;
/**
* ISelectService:
* author: <a href="mailto:[email protected]">chengjs</a>, version:1.0.0, 2017/8/24
*/
public interface IUserManagerService {
Set<String> findRoleNames(String UserName);
Set<String> findPermissionNames(Set<String> roleNames);
| UUser findUserByUserName(String UserName); |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.