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 |
|---|---|---|---|---|---|---|
broamski/cantilever | src/main/java/com/dogeops/cantilever/logreader/HTTPLogReader.java | // Path: src/main/java/com/dogeops/cantilever/utils/ConfigurationSingleton.java
// public enum ConfigurationSingleton {
// instance;
// private static final Logger logger = Logger
// .getLogger(ConfigurationSingleton.class.getName());
//
// private Properties props = new Properties();
//
// private ConfigurationSingleton() {
// }
//
// public void readConfigFile(String config_path) {
// try {
// InputStream input = new FileInputStream(config_path);
// props.load(input);
// input.close();
// } catch (IOException e) {
// cease(logger, e.getMessage());
// }
// }
//
// public String getConfigItem(String val) {
// try {
// if (props.isEmpty()) {
// throw new Exception("Propery file object is empty. "
// + "This likely indicates that the config singleton "
// + "was not properly initialized via readConfigFile.");
// }
// if (props.getProperty(val) == null) {
// throw new Exception("The property " + val
// + " is missing from the configurtion file.");
// }
// return props.getProperty(val);
// } catch (Exception e) {
// cease(logger, e.getMessage());
// return null;
// }
// }
// }
//
// Path: src/main/java/com/dogeops/cantilever/utils/Timer.java
// public class Timer {
//
// private long start;
// private long stop;
// private long elapsed;
//
// public void start() {
// start = System.currentTimeMillis();
// }
//
// public void stop() {
// stop = System.currentTimeMillis();
// }
//
// public long getElapsed() {
// elapsed = stop - start;
// return elapsed;
// }
// }
//
// Path: src/main/java/com/dogeops/cantilever/utils/Util.java
// public static void cease(Logger logger, String message) {
// logger.error(message);
// System.exit(1);
// }
| import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.log4j.Logger;
import com.dogeops.cantilever.utils.ConfigurationSingleton;
import com.dogeops.cantilever.utils.Timer;
import com.google.gson.Gson;
import static com.dogeops.cantilever.utils.Util.cease; | package com.dogeops.cantilever.logreader;
public class HTTPLogReader {
private static final Logger logger = Logger.getLogger(HTTPLogReader.class
.getName());
private int fileCount = 0;
public void readLogs(String path) {
logger.info("Reading logs in " + path + "....");
String log_regex = ConfigurationSingleton.instance
.getConfigItem("log.convert.regex"); | // Path: src/main/java/com/dogeops/cantilever/utils/ConfigurationSingleton.java
// public enum ConfigurationSingleton {
// instance;
// private static final Logger logger = Logger
// .getLogger(ConfigurationSingleton.class.getName());
//
// private Properties props = new Properties();
//
// private ConfigurationSingleton() {
// }
//
// public void readConfigFile(String config_path) {
// try {
// InputStream input = new FileInputStream(config_path);
// props.load(input);
// input.close();
// } catch (IOException e) {
// cease(logger, e.getMessage());
// }
// }
//
// public String getConfigItem(String val) {
// try {
// if (props.isEmpty()) {
// throw new Exception("Propery file object is empty. "
// + "This likely indicates that the config singleton "
// + "was not properly initialized via readConfigFile.");
// }
// if (props.getProperty(val) == null) {
// throw new Exception("The property " + val
// + " is missing from the configurtion file.");
// }
// return props.getProperty(val);
// } catch (Exception e) {
// cease(logger, e.getMessage());
// return null;
// }
// }
// }
//
// Path: src/main/java/com/dogeops/cantilever/utils/Timer.java
// public class Timer {
//
// private long start;
// private long stop;
// private long elapsed;
//
// public void start() {
// start = System.currentTimeMillis();
// }
//
// public void stop() {
// stop = System.currentTimeMillis();
// }
//
// public long getElapsed() {
// elapsed = stop - start;
// return elapsed;
// }
// }
//
// Path: src/main/java/com/dogeops/cantilever/utils/Util.java
// public static void cease(Logger logger, String message) {
// logger.error(message);
// System.exit(1);
// }
// Path: src/main/java/com/dogeops/cantilever/logreader/HTTPLogReader.java
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.log4j.Logger;
import com.dogeops.cantilever.utils.ConfigurationSingleton;
import com.dogeops.cantilever.utils.Timer;
import com.google.gson.Gson;
import static com.dogeops.cantilever.utils.Util.cease;
package com.dogeops.cantilever.logreader;
public class HTTPLogReader {
private static final Logger logger = Logger.getLogger(HTTPLogReader.class
.getName());
private int fileCount = 0;
public void readLogs(String path) {
logger.info("Reading logs in " + path + "....");
String log_regex = ConfigurationSingleton.instance
.getConfigItem("log.convert.regex"); | Timer t = new Timer(); |
broamski/cantilever | src/main/java/com/dogeops/cantilever/logreader/HTTPLogReader.java | // Path: src/main/java/com/dogeops/cantilever/utils/ConfigurationSingleton.java
// public enum ConfigurationSingleton {
// instance;
// private static final Logger logger = Logger
// .getLogger(ConfigurationSingleton.class.getName());
//
// private Properties props = new Properties();
//
// private ConfigurationSingleton() {
// }
//
// public void readConfigFile(String config_path) {
// try {
// InputStream input = new FileInputStream(config_path);
// props.load(input);
// input.close();
// } catch (IOException e) {
// cease(logger, e.getMessage());
// }
// }
//
// public String getConfigItem(String val) {
// try {
// if (props.isEmpty()) {
// throw new Exception("Propery file object is empty. "
// + "This likely indicates that the config singleton "
// + "was not properly initialized via readConfigFile.");
// }
// if (props.getProperty(val) == null) {
// throw new Exception("The property " + val
// + " is missing from the configurtion file.");
// }
// return props.getProperty(val);
// } catch (Exception e) {
// cease(logger, e.getMessage());
// return null;
// }
// }
// }
//
// Path: src/main/java/com/dogeops/cantilever/utils/Timer.java
// public class Timer {
//
// private long start;
// private long stop;
// private long elapsed;
//
// public void start() {
// start = System.currentTimeMillis();
// }
//
// public void stop() {
// stop = System.currentTimeMillis();
// }
//
// public long getElapsed() {
// elapsed = stop - start;
// return elapsed;
// }
// }
//
// Path: src/main/java/com/dogeops/cantilever/utils/Util.java
// public static void cease(Logger logger, String message) {
// logger.error(message);
// System.exit(1);
// }
| import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.log4j.Logger;
import com.dogeops.cantilever.utils.ConfigurationSingleton;
import com.dogeops.cantilever.utils.Timer;
import com.google.gson.Gson;
import static com.dogeops.cantilever.utils.Util.cease; | if (folder.exists()) {
for (File file : folder.listFiles()) {
fileCount++;
logger.info("Pasring file: " + file.getAbsolutePath());
try {
BufferedReader br = new BufferedReader(new FileReader(
file.getAbsolutePath()));
String line = null;
while ((line = br.readLine()) != null) {
logger.trace(line);
line = line.trim();
Pattern p = Pattern.compile(log_regex);
Matcher m = p.matcher(line);
try {
m.find();
HTTPLogObject hl = new HTTPLogObject(
m.group("TIMESTAMP"), m.group("METHOD"),
m.group("REQUEST"), m.group("BYTES"), m
.group("USERAGENT").replace("\"",
""));
ReplayCache.instance.addToCache(hl);
} catch (Exception e) {
logger.error("Unparsable line: " + line + " - "
+ e.getMessage());
}
}
br.close();
} catch (FileNotFoundException e) { | // Path: src/main/java/com/dogeops/cantilever/utils/ConfigurationSingleton.java
// public enum ConfigurationSingleton {
// instance;
// private static final Logger logger = Logger
// .getLogger(ConfigurationSingleton.class.getName());
//
// private Properties props = new Properties();
//
// private ConfigurationSingleton() {
// }
//
// public void readConfigFile(String config_path) {
// try {
// InputStream input = new FileInputStream(config_path);
// props.load(input);
// input.close();
// } catch (IOException e) {
// cease(logger, e.getMessage());
// }
// }
//
// public String getConfigItem(String val) {
// try {
// if (props.isEmpty()) {
// throw new Exception("Propery file object is empty. "
// + "This likely indicates that the config singleton "
// + "was not properly initialized via readConfigFile.");
// }
// if (props.getProperty(val) == null) {
// throw new Exception("The property " + val
// + " is missing from the configurtion file.");
// }
// return props.getProperty(val);
// } catch (Exception e) {
// cease(logger, e.getMessage());
// return null;
// }
// }
// }
//
// Path: src/main/java/com/dogeops/cantilever/utils/Timer.java
// public class Timer {
//
// private long start;
// private long stop;
// private long elapsed;
//
// public void start() {
// start = System.currentTimeMillis();
// }
//
// public void stop() {
// stop = System.currentTimeMillis();
// }
//
// public long getElapsed() {
// elapsed = stop - start;
// return elapsed;
// }
// }
//
// Path: src/main/java/com/dogeops/cantilever/utils/Util.java
// public static void cease(Logger logger, String message) {
// logger.error(message);
// System.exit(1);
// }
// Path: src/main/java/com/dogeops/cantilever/logreader/HTTPLogReader.java
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.log4j.Logger;
import com.dogeops.cantilever.utils.ConfigurationSingleton;
import com.dogeops.cantilever.utils.Timer;
import com.google.gson.Gson;
import static com.dogeops.cantilever.utils.Util.cease;
if (folder.exists()) {
for (File file : folder.listFiles()) {
fileCount++;
logger.info("Pasring file: " + file.getAbsolutePath());
try {
BufferedReader br = new BufferedReader(new FileReader(
file.getAbsolutePath()));
String line = null;
while ((line = br.readLine()) != null) {
logger.trace(line);
line = line.trim();
Pattern p = Pattern.compile(log_regex);
Matcher m = p.matcher(line);
try {
m.find();
HTTPLogObject hl = new HTTPLogObject(
m.group("TIMESTAMP"), m.group("METHOD"),
m.group("REQUEST"), m.group("BYTES"), m
.group("USERAGENT").replace("\"",
""));
ReplayCache.instance.addToCache(hl);
} catch (Exception e) {
logger.error("Unparsable line: " + line + " - "
+ e.getMessage());
}
}
br.close();
} catch (FileNotFoundException e) { | cease(logger, e.getMessage()); |
broamski/cantilever | src/main/java/com/dogeops/cantilever/beam/LoopControl.java | // Path: src/main/java/com/dogeops/cantilever/messagequeue/MessageQueueFactory.java
// public class MessageQueueFactory {
// private static final Logger logger = Logger.getLogger(MessageQueueFactory.class
// .getName());
//
// public enum QueueTypes {
// AMQ, SQS, NAN;
// public static QueueTypes toQueue(String str) {
// try {
// return valueOf(str);
// } catch (Exception ex) {
// return NAN;
// }
// }
// }
//
// public MessageQueueInterface getQueue(String type) {
//
// switch (QueueTypes.toQueue(type))
// {
// case AMQ:
// return new ActiveMQ();
// case SQS:
// return new AmazonSQS();
// default:
// Util.cease(logger, "Invalid Message Queue. Quitting.");
// return null;
// }
// }
// }
//
// Path: src/main/java/com/dogeops/cantilever/messagequeue/MessageQueueInterface.java
// public interface MessageQueueInterface {
// public void connect(String hostname, String queue_name);
// public void disconnect();
// public void deliver(String payload);
// public void consume(HTTPAsyncLogMessageListener ml);
// }
//
// Path: src/main/java/com/dogeops/cantilever/utils/ConfigurationSingleton.java
// public enum ConfigurationSingleton {
// instance;
// private static final Logger logger = Logger
// .getLogger(ConfigurationSingleton.class.getName());
//
// private Properties props = new Properties();
//
// private ConfigurationSingleton() {
// }
//
// public void readConfigFile(String config_path) {
// try {
// InputStream input = new FileInputStream(config_path);
// props.load(input);
// input.close();
// } catch (IOException e) {
// cease(logger, e.getMessage());
// }
// }
//
// public String getConfigItem(String val) {
// try {
// if (props.isEmpty()) {
// throw new Exception("Propery file object is empty. "
// + "This likely indicates that the config singleton "
// + "was not properly initialized via readConfigFile.");
// }
// if (props.getProperty(val) == null) {
// throw new Exception("The property " + val
// + " is missing from the configurtion file.");
// }
// return props.getProperty(val);
// } catch (Exception e) {
// cease(logger, e.getMessage());
// return null;
// }
// }
// }
//
// Path: src/main/java/com/dogeops/cantilever/utils/Timer.java
// public class Timer {
//
// private long start;
// private long stop;
// private long elapsed;
//
// public void start() {
// start = System.currentTimeMillis();
// }
//
// public void stop() {
// stop = System.currentTimeMillis();
// }
//
// public long getElapsed() {
// elapsed = stop - start;
// return elapsed;
// }
// }
//
// Path: src/main/java/com/dogeops/cantilever/utils/Util.java
// public class Util {
// public static void cease(Logger logger, String message) {
// logger.error(message);
// System.exit(1);
// }
// }
| import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.TimeZone;
import org.apache.log4j.Logger;
import com.dogeops.cantilever.messagequeue.MessageQueueFactory;
import com.dogeops.cantilever.messagequeue.MessageQueueInterface;
import com.dogeops.cantilever.utils.ConfigurationSingleton;
import com.dogeops.cantilever.utils.Timer;
import com.dogeops.cantilever.utils.Util; | package com.dogeops.cantilever.beam;
public class LoopControl {
private static final Logger logger = Logger.getLogger(LoopControl.class
.getName());
public void execute() { | // Path: src/main/java/com/dogeops/cantilever/messagequeue/MessageQueueFactory.java
// public class MessageQueueFactory {
// private static final Logger logger = Logger.getLogger(MessageQueueFactory.class
// .getName());
//
// public enum QueueTypes {
// AMQ, SQS, NAN;
// public static QueueTypes toQueue(String str) {
// try {
// return valueOf(str);
// } catch (Exception ex) {
// return NAN;
// }
// }
// }
//
// public MessageQueueInterface getQueue(String type) {
//
// switch (QueueTypes.toQueue(type))
// {
// case AMQ:
// return new ActiveMQ();
// case SQS:
// return new AmazonSQS();
// default:
// Util.cease(logger, "Invalid Message Queue. Quitting.");
// return null;
// }
// }
// }
//
// Path: src/main/java/com/dogeops/cantilever/messagequeue/MessageQueueInterface.java
// public interface MessageQueueInterface {
// public void connect(String hostname, String queue_name);
// public void disconnect();
// public void deliver(String payload);
// public void consume(HTTPAsyncLogMessageListener ml);
// }
//
// Path: src/main/java/com/dogeops/cantilever/utils/ConfigurationSingleton.java
// public enum ConfigurationSingleton {
// instance;
// private static final Logger logger = Logger
// .getLogger(ConfigurationSingleton.class.getName());
//
// private Properties props = new Properties();
//
// private ConfigurationSingleton() {
// }
//
// public void readConfigFile(String config_path) {
// try {
// InputStream input = new FileInputStream(config_path);
// props.load(input);
// input.close();
// } catch (IOException e) {
// cease(logger, e.getMessage());
// }
// }
//
// public String getConfigItem(String val) {
// try {
// if (props.isEmpty()) {
// throw new Exception("Propery file object is empty. "
// + "This likely indicates that the config singleton "
// + "was not properly initialized via readConfigFile.");
// }
// if (props.getProperty(val) == null) {
// throw new Exception("The property " + val
// + " is missing from the configurtion file.");
// }
// return props.getProperty(val);
// } catch (Exception e) {
// cease(logger, e.getMessage());
// return null;
// }
// }
// }
//
// Path: src/main/java/com/dogeops/cantilever/utils/Timer.java
// public class Timer {
//
// private long start;
// private long stop;
// private long elapsed;
//
// public void start() {
// start = System.currentTimeMillis();
// }
//
// public void stop() {
// stop = System.currentTimeMillis();
// }
//
// public long getElapsed() {
// elapsed = stop - start;
// return elapsed;
// }
// }
//
// Path: src/main/java/com/dogeops/cantilever/utils/Util.java
// public class Util {
// public static void cease(Logger logger, String message) {
// logger.error(message);
// System.exit(1);
// }
// }
// Path: src/main/java/com/dogeops/cantilever/beam/LoopControl.java
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.TimeZone;
import org.apache.log4j.Logger;
import com.dogeops.cantilever.messagequeue.MessageQueueFactory;
import com.dogeops.cantilever.messagequeue.MessageQueueInterface;
import com.dogeops.cantilever.utils.ConfigurationSingleton;
import com.dogeops.cantilever.utils.Timer;
import com.dogeops.cantilever.utils.Util;
package com.dogeops.cantilever.beam;
public class LoopControl {
private static final Logger logger = Logger.getLogger(LoopControl.class
.getName());
public void execute() { | String inputDateFormat = ConfigurationSingleton.instance |
broamski/cantilever | src/main/java/com/dogeops/cantilever/beam/LoopControl.java | // Path: src/main/java/com/dogeops/cantilever/messagequeue/MessageQueueFactory.java
// public class MessageQueueFactory {
// private static final Logger logger = Logger.getLogger(MessageQueueFactory.class
// .getName());
//
// public enum QueueTypes {
// AMQ, SQS, NAN;
// public static QueueTypes toQueue(String str) {
// try {
// return valueOf(str);
// } catch (Exception ex) {
// return NAN;
// }
// }
// }
//
// public MessageQueueInterface getQueue(String type) {
//
// switch (QueueTypes.toQueue(type))
// {
// case AMQ:
// return new ActiveMQ();
// case SQS:
// return new AmazonSQS();
// default:
// Util.cease(logger, "Invalid Message Queue. Quitting.");
// return null;
// }
// }
// }
//
// Path: src/main/java/com/dogeops/cantilever/messagequeue/MessageQueueInterface.java
// public interface MessageQueueInterface {
// public void connect(String hostname, String queue_name);
// public void disconnect();
// public void deliver(String payload);
// public void consume(HTTPAsyncLogMessageListener ml);
// }
//
// Path: src/main/java/com/dogeops/cantilever/utils/ConfigurationSingleton.java
// public enum ConfigurationSingleton {
// instance;
// private static final Logger logger = Logger
// .getLogger(ConfigurationSingleton.class.getName());
//
// private Properties props = new Properties();
//
// private ConfigurationSingleton() {
// }
//
// public void readConfigFile(String config_path) {
// try {
// InputStream input = new FileInputStream(config_path);
// props.load(input);
// input.close();
// } catch (IOException e) {
// cease(logger, e.getMessage());
// }
// }
//
// public String getConfigItem(String val) {
// try {
// if (props.isEmpty()) {
// throw new Exception("Propery file object is empty. "
// + "This likely indicates that the config singleton "
// + "was not properly initialized via readConfigFile.");
// }
// if (props.getProperty(val) == null) {
// throw new Exception("The property " + val
// + " is missing from the configurtion file.");
// }
// return props.getProperty(val);
// } catch (Exception e) {
// cease(logger, e.getMessage());
// return null;
// }
// }
// }
//
// Path: src/main/java/com/dogeops/cantilever/utils/Timer.java
// public class Timer {
//
// private long start;
// private long stop;
// private long elapsed;
//
// public void start() {
// start = System.currentTimeMillis();
// }
//
// public void stop() {
// stop = System.currentTimeMillis();
// }
//
// public long getElapsed() {
// elapsed = stop - start;
// return elapsed;
// }
// }
//
// Path: src/main/java/com/dogeops/cantilever/utils/Util.java
// public class Util {
// public static void cease(Logger logger, String message) {
// logger.error(message);
// System.exit(1);
// }
// }
| import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.TimeZone;
import org.apache.log4j.Logger;
import com.dogeops.cantilever.messagequeue.MessageQueueFactory;
import com.dogeops.cantilever.messagequeue.MessageQueueInterface;
import com.dogeops.cantilever.utils.ConfigurationSingleton;
import com.dogeops.cantilever.utils.Timer;
import com.dogeops.cantilever.utils.Util; | package com.dogeops.cantilever.beam;
public class LoopControl {
private static final Logger logger = Logger.getLogger(LoopControl.class
.getName());
public void execute() {
String inputDateFormat = ConfigurationSingleton.instance
.getConfigItem("replay.dateformat");
SimpleDateFormat dateFormat = new SimpleDateFormat(inputDateFormat);
try {
String inputStartTime = ConfigurationSingleton.instance
.getConfigItem("replay.starttime");
Date tmpStart = dateFormat.parse(inputStartTime);
Calendar startTime = new GregorianCalendar(
TimeZone.getTimeZone("GMT"));
startTime.setTime(tmpStart);
String inputEndTime = ConfigurationSingleton.instance
.getConfigItem("replay.endtime");
Date tmpEnd = dateFormat.parse(inputEndTime);
Calendar endTime = new GregorianCalendar(
TimeZone.getTimeZone("GMT"));
endTime.setTime(tmpEnd);
// How long to run the scheduler.
long run_time = (endTime.getTimeInMillis() - startTime
.getTimeInMillis());
logger.debug("Staring at: " + startTime.getTime()
+ " and Ending at: " + endTime.getTime() + ", running for "
+ run_time + " ms");
| // Path: src/main/java/com/dogeops/cantilever/messagequeue/MessageQueueFactory.java
// public class MessageQueueFactory {
// private static final Logger logger = Logger.getLogger(MessageQueueFactory.class
// .getName());
//
// public enum QueueTypes {
// AMQ, SQS, NAN;
// public static QueueTypes toQueue(String str) {
// try {
// return valueOf(str);
// } catch (Exception ex) {
// return NAN;
// }
// }
// }
//
// public MessageQueueInterface getQueue(String type) {
//
// switch (QueueTypes.toQueue(type))
// {
// case AMQ:
// return new ActiveMQ();
// case SQS:
// return new AmazonSQS();
// default:
// Util.cease(logger, "Invalid Message Queue. Quitting.");
// return null;
// }
// }
// }
//
// Path: src/main/java/com/dogeops/cantilever/messagequeue/MessageQueueInterface.java
// public interface MessageQueueInterface {
// public void connect(String hostname, String queue_name);
// public void disconnect();
// public void deliver(String payload);
// public void consume(HTTPAsyncLogMessageListener ml);
// }
//
// Path: src/main/java/com/dogeops/cantilever/utils/ConfigurationSingleton.java
// public enum ConfigurationSingleton {
// instance;
// private static final Logger logger = Logger
// .getLogger(ConfigurationSingleton.class.getName());
//
// private Properties props = new Properties();
//
// private ConfigurationSingleton() {
// }
//
// public void readConfigFile(String config_path) {
// try {
// InputStream input = new FileInputStream(config_path);
// props.load(input);
// input.close();
// } catch (IOException e) {
// cease(logger, e.getMessage());
// }
// }
//
// public String getConfigItem(String val) {
// try {
// if (props.isEmpty()) {
// throw new Exception("Propery file object is empty. "
// + "This likely indicates that the config singleton "
// + "was not properly initialized via readConfigFile.");
// }
// if (props.getProperty(val) == null) {
// throw new Exception("The property " + val
// + " is missing from the configurtion file.");
// }
// return props.getProperty(val);
// } catch (Exception e) {
// cease(logger, e.getMessage());
// return null;
// }
// }
// }
//
// Path: src/main/java/com/dogeops/cantilever/utils/Timer.java
// public class Timer {
//
// private long start;
// private long stop;
// private long elapsed;
//
// public void start() {
// start = System.currentTimeMillis();
// }
//
// public void stop() {
// stop = System.currentTimeMillis();
// }
//
// public long getElapsed() {
// elapsed = stop - start;
// return elapsed;
// }
// }
//
// Path: src/main/java/com/dogeops/cantilever/utils/Util.java
// public class Util {
// public static void cease(Logger logger, String message) {
// logger.error(message);
// System.exit(1);
// }
// }
// Path: src/main/java/com/dogeops/cantilever/beam/LoopControl.java
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.TimeZone;
import org.apache.log4j.Logger;
import com.dogeops.cantilever.messagequeue.MessageQueueFactory;
import com.dogeops.cantilever.messagequeue.MessageQueueInterface;
import com.dogeops.cantilever.utils.ConfigurationSingleton;
import com.dogeops.cantilever.utils.Timer;
import com.dogeops.cantilever.utils.Util;
package com.dogeops.cantilever.beam;
public class LoopControl {
private static final Logger logger = Logger.getLogger(LoopControl.class
.getName());
public void execute() {
String inputDateFormat = ConfigurationSingleton.instance
.getConfigItem("replay.dateformat");
SimpleDateFormat dateFormat = new SimpleDateFormat(inputDateFormat);
try {
String inputStartTime = ConfigurationSingleton.instance
.getConfigItem("replay.starttime");
Date tmpStart = dateFormat.parse(inputStartTime);
Calendar startTime = new GregorianCalendar(
TimeZone.getTimeZone("GMT"));
startTime.setTime(tmpStart);
String inputEndTime = ConfigurationSingleton.instance
.getConfigItem("replay.endtime");
Date tmpEnd = dateFormat.parse(inputEndTime);
Calendar endTime = new GregorianCalendar(
TimeZone.getTimeZone("GMT"));
endTime.setTime(tmpEnd);
// How long to run the scheduler.
long run_time = (endTime.getTimeInMillis() - startTime
.getTimeInMillis());
logger.debug("Staring at: " + startTime.getTime()
+ " and Ending at: " + endTime.getTime() + ", running for "
+ run_time + " ms");
| MessageQueueFactory mqf = new MessageQueueFactory(); |
broamski/cantilever | src/main/java/com/dogeops/cantilever/beam/LoopControl.java | // Path: src/main/java/com/dogeops/cantilever/messagequeue/MessageQueueFactory.java
// public class MessageQueueFactory {
// private static final Logger logger = Logger.getLogger(MessageQueueFactory.class
// .getName());
//
// public enum QueueTypes {
// AMQ, SQS, NAN;
// public static QueueTypes toQueue(String str) {
// try {
// return valueOf(str);
// } catch (Exception ex) {
// return NAN;
// }
// }
// }
//
// public MessageQueueInterface getQueue(String type) {
//
// switch (QueueTypes.toQueue(type))
// {
// case AMQ:
// return new ActiveMQ();
// case SQS:
// return new AmazonSQS();
// default:
// Util.cease(logger, "Invalid Message Queue. Quitting.");
// return null;
// }
// }
// }
//
// Path: src/main/java/com/dogeops/cantilever/messagequeue/MessageQueueInterface.java
// public interface MessageQueueInterface {
// public void connect(String hostname, String queue_name);
// public void disconnect();
// public void deliver(String payload);
// public void consume(HTTPAsyncLogMessageListener ml);
// }
//
// Path: src/main/java/com/dogeops/cantilever/utils/ConfigurationSingleton.java
// public enum ConfigurationSingleton {
// instance;
// private static final Logger logger = Logger
// .getLogger(ConfigurationSingleton.class.getName());
//
// private Properties props = new Properties();
//
// private ConfigurationSingleton() {
// }
//
// public void readConfigFile(String config_path) {
// try {
// InputStream input = new FileInputStream(config_path);
// props.load(input);
// input.close();
// } catch (IOException e) {
// cease(logger, e.getMessage());
// }
// }
//
// public String getConfigItem(String val) {
// try {
// if (props.isEmpty()) {
// throw new Exception("Propery file object is empty. "
// + "This likely indicates that the config singleton "
// + "was not properly initialized via readConfigFile.");
// }
// if (props.getProperty(val) == null) {
// throw new Exception("The property " + val
// + " is missing from the configurtion file.");
// }
// return props.getProperty(val);
// } catch (Exception e) {
// cease(logger, e.getMessage());
// return null;
// }
// }
// }
//
// Path: src/main/java/com/dogeops/cantilever/utils/Timer.java
// public class Timer {
//
// private long start;
// private long stop;
// private long elapsed;
//
// public void start() {
// start = System.currentTimeMillis();
// }
//
// public void stop() {
// stop = System.currentTimeMillis();
// }
//
// public long getElapsed() {
// elapsed = stop - start;
// return elapsed;
// }
// }
//
// Path: src/main/java/com/dogeops/cantilever/utils/Util.java
// public class Util {
// public static void cease(Logger logger, String message) {
// logger.error(message);
// System.exit(1);
// }
// }
| import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.TimeZone;
import org.apache.log4j.Logger;
import com.dogeops.cantilever.messagequeue.MessageQueueFactory;
import com.dogeops.cantilever.messagequeue.MessageQueueInterface;
import com.dogeops.cantilever.utils.ConfigurationSingleton;
import com.dogeops.cantilever.utils.Timer;
import com.dogeops.cantilever.utils.Util; | package com.dogeops.cantilever.beam;
public class LoopControl {
private static final Logger logger = Logger.getLogger(LoopControl.class
.getName());
public void execute() {
String inputDateFormat = ConfigurationSingleton.instance
.getConfigItem("replay.dateformat");
SimpleDateFormat dateFormat = new SimpleDateFormat(inputDateFormat);
try {
String inputStartTime = ConfigurationSingleton.instance
.getConfigItem("replay.starttime");
Date tmpStart = dateFormat.parse(inputStartTime);
Calendar startTime = new GregorianCalendar(
TimeZone.getTimeZone("GMT"));
startTime.setTime(tmpStart);
String inputEndTime = ConfigurationSingleton.instance
.getConfigItem("replay.endtime");
Date tmpEnd = dateFormat.parse(inputEndTime);
Calendar endTime = new GregorianCalendar(
TimeZone.getTimeZone("GMT"));
endTime.setTime(tmpEnd);
// How long to run the scheduler.
long run_time = (endTime.getTimeInMillis() - startTime
.getTimeInMillis());
logger.debug("Staring at: " + startTime.getTime()
+ " and Ending at: " + endTime.getTime() + ", running for "
+ run_time + " ms");
MessageQueueFactory mqf = new MessageQueueFactory();
| // Path: src/main/java/com/dogeops/cantilever/messagequeue/MessageQueueFactory.java
// public class MessageQueueFactory {
// private static final Logger logger = Logger.getLogger(MessageQueueFactory.class
// .getName());
//
// public enum QueueTypes {
// AMQ, SQS, NAN;
// public static QueueTypes toQueue(String str) {
// try {
// return valueOf(str);
// } catch (Exception ex) {
// return NAN;
// }
// }
// }
//
// public MessageQueueInterface getQueue(String type) {
//
// switch (QueueTypes.toQueue(type))
// {
// case AMQ:
// return new ActiveMQ();
// case SQS:
// return new AmazonSQS();
// default:
// Util.cease(logger, "Invalid Message Queue. Quitting.");
// return null;
// }
// }
// }
//
// Path: src/main/java/com/dogeops/cantilever/messagequeue/MessageQueueInterface.java
// public interface MessageQueueInterface {
// public void connect(String hostname, String queue_name);
// public void disconnect();
// public void deliver(String payload);
// public void consume(HTTPAsyncLogMessageListener ml);
// }
//
// Path: src/main/java/com/dogeops/cantilever/utils/ConfigurationSingleton.java
// public enum ConfigurationSingleton {
// instance;
// private static final Logger logger = Logger
// .getLogger(ConfigurationSingleton.class.getName());
//
// private Properties props = new Properties();
//
// private ConfigurationSingleton() {
// }
//
// public void readConfigFile(String config_path) {
// try {
// InputStream input = new FileInputStream(config_path);
// props.load(input);
// input.close();
// } catch (IOException e) {
// cease(logger, e.getMessage());
// }
// }
//
// public String getConfigItem(String val) {
// try {
// if (props.isEmpty()) {
// throw new Exception("Propery file object is empty. "
// + "This likely indicates that the config singleton "
// + "was not properly initialized via readConfigFile.");
// }
// if (props.getProperty(val) == null) {
// throw new Exception("The property " + val
// + " is missing from the configurtion file.");
// }
// return props.getProperty(val);
// } catch (Exception e) {
// cease(logger, e.getMessage());
// return null;
// }
// }
// }
//
// Path: src/main/java/com/dogeops/cantilever/utils/Timer.java
// public class Timer {
//
// private long start;
// private long stop;
// private long elapsed;
//
// public void start() {
// start = System.currentTimeMillis();
// }
//
// public void stop() {
// stop = System.currentTimeMillis();
// }
//
// public long getElapsed() {
// elapsed = stop - start;
// return elapsed;
// }
// }
//
// Path: src/main/java/com/dogeops/cantilever/utils/Util.java
// public class Util {
// public static void cease(Logger logger, String message) {
// logger.error(message);
// System.exit(1);
// }
// }
// Path: src/main/java/com/dogeops/cantilever/beam/LoopControl.java
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.TimeZone;
import org.apache.log4j.Logger;
import com.dogeops.cantilever.messagequeue.MessageQueueFactory;
import com.dogeops.cantilever.messagequeue.MessageQueueInterface;
import com.dogeops.cantilever.utils.ConfigurationSingleton;
import com.dogeops.cantilever.utils.Timer;
import com.dogeops.cantilever.utils.Util;
package com.dogeops.cantilever.beam;
public class LoopControl {
private static final Logger logger = Logger.getLogger(LoopControl.class
.getName());
public void execute() {
String inputDateFormat = ConfigurationSingleton.instance
.getConfigItem("replay.dateformat");
SimpleDateFormat dateFormat = new SimpleDateFormat(inputDateFormat);
try {
String inputStartTime = ConfigurationSingleton.instance
.getConfigItem("replay.starttime");
Date tmpStart = dateFormat.parse(inputStartTime);
Calendar startTime = new GregorianCalendar(
TimeZone.getTimeZone("GMT"));
startTime.setTime(tmpStart);
String inputEndTime = ConfigurationSingleton.instance
.getConfigItem("replay.endtime");
Date tmpEnd = dateFormat.parse(inputEndTime);
Calendar endTime = new GregorianCalendar(
TimeZone.getTimeZone("GMT"));
endTime.setTime(tmpEnd);
// How long to run the scheduler.
long run_time = (endTime.getTimeInMillis() - startTime
.getTimeInMillis());
logger.debug("Staring at: " + startTime.getTime()
+ " and Ending at: " + endTime.getTime() + ", running for "
+ run_time + " ms");
MessageQueueFactory mqf = new MessageQueueFactory();
| MessageQueueInterface mqi = mqf.getQueue(ConfigurationSingleton.instance |
broamski/cantilever | src/main/java/com/dogeops/cantilever/beam/LoopControl.java | // Path: src/main/java/com/dogeops/cantilever/messagequeue/MessageQueueFactory.java
// public class MessageQueueFactory {
// private static final Logger logger = Logger.getLogger(MessageQueueFactory.class
// .getName());
//
// public enum QueueTypes {
// AMQ, SQS, NAN;
// public static QueueTypes toQueue(String str) {
// try {
// return valueOf(str);
// } catch (Exception ex) {
// return NAN;
// }
// }
// }
//
// public MessageQueueInterface getQueue(String type) {
//
// switch (QueueTypes.toQueue(type))
// {
// case AMQ:
// return new ActiveMQ();
// case SQS:
// return new AmazonSQS();
// default:
// Util.cease(logger, "Invalid Message Queue. Quitting.");
// return null;
// }
// }
// }
//
// Path: src/main/java/com/dogeops/cantilever/messagequeue/MessageQueueInterface.java
// public interface MessageQueueInterface {
// public void connect(String hostname, String queue_name);
// public void disconnect();
// public void deliver(String payload);
// public void consume(HTTPAsyncLogMessageListener ml);
// }
//
// Path: src/main/java/com/dogeops/cantilever/utils/ConfigurationSingleton.java
// public enum ConfigurationSingleton {
// instance;
// private static final Logger logger = Logger
// .getLogger(ConfigurationSingleton.class.getName());
//
// private Properties props = new Properties();
//
// private ConfigurationSingleton() {
// }
//
// public void readConfigFile(String config_path) {
// try {
// InputStream input = new FileInputStream(config_path);
// props.load(input);
// input.close();
// } catch (IOException e) {
// cease(logger, e.getMessage());
// }
// }
//
// public String getConfigItem(String val) {
// try {
// if (props.isEmpty()) {
// throw new Exception("Propery file object is empty. "
// + "This likely indicates that the config singleton "
// + "was not properly initialized via readConfigFile.");
// }
// if (props.getProperty(val) == null) {
// throw new Exception("The property " + val
// + " is missing from the configurtion file.");
// }
// return props.getProperty(val);
// } catch (Exception e) {
// cease(logger, e.getMessage());
// return null;
// }
// }
// }
//
// Path: src/main/java/com/dogeops/cantilever/utils/Timer.java
// public class Timer {
//
// private long start;
// private long stop;
// private long elapsed;
//
// public void start() {
// start = System.currentTimeMillis();
// }
//
// public void stop() {
// stop = System.currentTimeMillis();
// }
//
// public long getElapsed() {
// elapsed = stop - start;
// return elapsed;
// }
// }
//
// Path: src/main/java/com/dogeops/cantilever/utils/Util.java
// public class Util {
// public static void cease(Logger logger, String message) {
// logger.error(message);
// System.exit(1);
// }
// }
| import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.TimeZone;
import org.apache.log4j.Logger;
import com.dogeops.cantilever.messagequeue.MessageQueueFactory;
import com.dogeops.cantilever.messagequeue.MessageQueueInterface;
import com.dogeops.cantilever.utils.ConfigurationSingleton;
import com.dogeops.cantilever.utils.Timer;
import com.dogeops.cantilever.utils.Util; | .getConfigItem("replay.starttime");
Date tmpStart = dateFormat.parse(inputStartTime);
Calendar startTime = new GregorianCalendar(
TimeZone.getTimeZone("GMT"));
startTime.setTime(tmpStart);
String inputEndTime = ConfigurationSingleton.instance
.getConfigItem("replay.endtime");
Date tmpEnd = dateFormat.parse(inputEndTime);
Calendar endTime = new GregorianCalendar(
TimeZone.getTimeZone("GMT"));
endTime.setTime(tmpEnd);
// How long to run the scheduler.
long run_time = (endTime.getTimeInMillis() - startTime
.getTimeInMillis());
logger.debug("Staring at: " + startTime.getTime()
+ " and Ending at: " + endTime.getTime() + ", running for "
+ run_time + " ms");
MessageQueueFactory mqf = new MessageQueueFactory();
MessageQueueInterface mqi = mqf.getQueue(ConfigurationSingleton.instance
.getConfigItem("replay.queue.type"));
mqi.connect(ConfigurationSingleton.instance
.getConfigItem("replay.queue.hostname"), ConfigurationSingleton.instance
.getConfigItem("replay.queue.queuename"));
for (int i = 0; i <= (run_time / 1000); i++) { | // Path: src/main/java/com/dogeops/cantilever/messagequeue/MessageQueueFactory.java
// public class MessageQueueFactory {
// private static final Logger logger = Logger.getLogger(MessageQueueFactory.class
// .getName());
//
// public enum QueueTypes {
// AMQ, SQS, NAN;
// public static QueueTypes toQueue(String str) {
// try {
// return valueOf(str);
// } catch (Exception ex) {
// return NAN;
// }
// }
// }
//
// public MessageQueueInterface getQueue(String type) {
//
// switch (QueueTypes.toQueue(type))
// {
// case AMQ:
// return new ActiveMQ();
// case SQS:
// return new AmazonSQS();
// default:
// Util.cease(logger, "Invalid Message Queue. Quitting.");
// return null;
// }
// }
// }
//
// Path: src/main/java/com/dogeops/cantilever/messagequeue/MessageQueueInterface.java
// public interface MessageQueueInterface {
// public void connect(String hostname, String queue_name);
// public void disconnect();
// public void deliver(String payload);
// public void consume(HTTPAsyncLogMessageListener ml);
// }
//
// Path: src/main/java/com/dogeops/cantilever/utils/ConfigurationSingleton.java
// public enum ConfigurationSingleton {
// instance;
// private static final Logger logger = Logger
// .getLogger(ConfigurationSingleton.class.getName());
//
// private Properties props = new Properties();
//
// private ConfigurationSingleton() {
// }
//
// public void readConfigFile(String config_path) {
// try {
// InputStream input = new FileInputStream(config_path);
// props.load(input);
// input.close();
// } catch (IOException e) {
// cease(logger, e.getMessage());
// }
// }
//
// public String getConfigItem(String val) {
// try {
// if (props.isEmpty()) {
// throw new Exception("Propery file object is empty. "
// + "This likely indicates that the config singleton "
// + "was not properly initialized via readConfigFile.");
// }
// if (props.getProperty(val) == null) {
// throw new Exception("The property " + val
// + " is missing from the configurtion file.");
// }
// return props.getProperty(val);
// } catch (Exception e) {
// cease(logger, e.getMessage());
// return null;
// }
// }
// }
//
// Path: src/main/java/com/dogeops/cantilever/utils/Timer.java
// public class Timer {
//
// private long start;
// private long stop;
// private long elapsed;
//
// public void start() {
// start = System.currentTimeMillis();
// }
//
// public void stop() {
// stop = System.currentTimeMillis();
// }
//
// public long getElapsed() {
// elapsed = stop - start;
// return elapsed;
// }
// }
//
// Path: src/main/java/com/dogeops/cantilever/utils/Util.java
// public class Util {
// public static void cease(Logger logger, String message) {
// logger.error(message);
// System.exit(1);
// }
// }
// Path: src/main/java/com/dogeops/cantilever/beam/LoopControl.java
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.TimeZone;
import org.apache.log4j.Logger;
import com.dogeops.cantilever.messagequeue.MessageQueueFactory;
import com.dogeops.cantilever.messagequeue.MessageQueueInterface;
import com.dogeops.cantilever.utils.ConfigurationSingleton;
import com.dogeops.cantilever.utils.Timer;
import com.dogeops.cantilever.utils.Util;
.getConfigItem("replay.starttime");
Date tmpStart = dateFormat.parse(inputStartTime);
Calendar startTime = new GregorianCalendar(
TimeZone.getTimeZone("GMT"));
startTime.setTime(tmpStart);
String inputEndTime = ConfigurationSingleton.instance
.getConfigItem("replay.endtime");
Date tmpEnd = dateFormat.parse(inputEndTime);
Calendar endTime = new GregorianCalendar(
TimeZone.getTimeZone("GMT"));
endTime.setTime(tmpEnd);
// How long to run the scheduler.
long run_time = (endTime.getTimeInMillis() - startTime
.getTimeInMillis());
logger.debug("Staring at: " + startTime.getTime()
+ " and Ending at: " + endTime.getTime() + ", running for "
+ run_time + " ms");
MessageQueueFactory mqf = new MessageQueueFactory();
MessageQueueInterface mqi = mqf.getQueue(ConfigurationSingleton.instance
.getConfigItem("replay.queue.type"));
mqi.connect(ConfigurationSingleton.instance
.getConfigItem("replay.queue.hostname"), ConfigurationSingleton.instance
.getConfigItem("replay.queue.queuename"));
for (int i = 0; i <= (run_time / 1000); i++) { | Timer t = new Timer(); |
broamski/cantilever | src/main/java/com/dogeops/cantilever/beam/LoopControl.java | // Path: src/main/java/com/dogeops/cantilever/messagequeue/MessageQueueFactory.java
// public class MessageQueueFactory {
// private static final Logger logger = Logger.getLogger(MessageQueueFactory.class
// .getName());
//
// public enum QueueTypes {
// AMQ, SQS, NAN;
// public static QueueTypes toQueue(String str) {
// try {
// return valueOf(str);
// } catch (Exception ex) {
// return NAN;
// }
// }
// }
//
// public MessageQueueInterface getQueue(String type) {
//
// switch (QueueTypes.toQueue(type))
// {
// case AMQ:
// return new ActiveMQ();
// case SQS:
// return new AmazonSQS();
// default:
// Util.cease(logger, "Invalid Message Queue. Quitting.");
// return null;
// }
// }
// }
//
// Path: src/main/java/com/dogeops/cantilever/messagequeue/MessageQueueInterface.java
// public interface MessageQueueInterface {
// public void connect(String hostname, String queue_name);
// public void disconnect();
// public void deliver(String payload);
// public void consume(HTTPAsyncLogMessageListener ml);
// }
//
// Path: src/main/java/com/dogeops/cantilever/utils/ConfigurationSingleton.java
// public enum ConfigurationSingleton {
// instance;
// private static final Logger logger = Logger
// .getLogger(ConfigurationSingleton.class.getName());
//
// private Properties props = new Properties();
//
// private ConfigurationSingleton() {
// }
//
// public void readConfigFile(String config_path) {
// try {
// InputStream input = new FileInputStream(config_path);
// props.load(input);
// input.close();
// } catch (IOException e) {
// cease(logger, e.getMessage());
// }
// }
//
// public String getConfigItem(String val) {
// try {
// if (props.isEmpty()) {
// throw new Exception("Propery file object is empty. "
// + "This likely indicates that the config singleton "
// + "was not properly initialized via readConfigFile.");
// }
// if (props.getProperty(val) == null) {
// throw new Exception("The property " + val
// + " is missing from the configurtion file.");
// }
// return props.getProperty(val);
// } catch (Exception e) {
// cease(logger, e.getMessage());
// return null;
// }
// }
// }
//
// Path: src/main/java/com/dogeops/cantilever/utils/Timer.java
// public class Timer {
//
// private long start;
// private long stop;
// private long elapsed;
//
// public void start() {
// start = System.currentTimeMillis();
// }
//
// public void stop() {
// stop = System.currentTimeMillis();
// }
//
// public long getElapsed() {
// elapsed = stop - start;
// return elapsed;
// }
// }
//
// Path: src/main/java/com/dogeops/cantilever/utils/Util.java
// public class Util {
// public static void cease(Logger logger, String message) {
// logger.error(message);
// System.exit(1);
// }
// }
| import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.TimeZone;
import org.apache.log4j.Logger;
import com.dogeops.cantilever.messagequeue.MessageQueueFactory;
import com.dogeops.cantilever.messagequeue.MessageQueueInterface;
import com.dogeops.cantilever.utils.ConfigurationSingleton;
import com.dogeops.cantilever.utils.Timer;
import com.dogeops.cantilever.utils.Util; |
logger.debug("Staring at: " + startTime.getTime()
+ " and Ending at: " + endTime.getTime() + ", running for "
+ run_time + " ms");
MessageQueueFactory mqf = new MessageQueueFactory();
MessageQueueInterface mqi = mqf.getQueue(ConfigurationSingleton.instance
.getConfigItem("replay.queue.type"));
mqi.connect(ConfigurationSingleton.instance
.getConfigItem("replay.queue.hostname"), ConfigurationSingleton.instance
.getConfigItem("replay.queue.queuename"));
for (int i = 0; i <= (run_time / 1000); i++) {
Timer t = new Timer();
t.start();
new MomentFetcher(startTime, mqi);
t.stop();
if (t.getElapsed() >= 1000) {
logger.debug("Fetch took " + t.getElapsed() + ", this could be a problem....");
} else {
logger.debug("Fetch took: " + t.getElapsed()
+ "ms. Ofsetting pause by " + t.getElapsed() + "ms");
Thread.sleep(1000 - t.getElapsed());
}
}
mqi.disconnect();
} catch (ParseException e) { | // Path: src/main/java/com/dogeops/cantilever/messagequeue/MessageQueueFactory.java
// public class MessageQueueFactory {
// private static final Logger logger = Logger.getLogger(MessageQueueFactory.class
// .getName());
//
// public enum QueueTypes {
// AMQ, SQS, NAN;
// public static QueueTypes toQueue(String str) {
// try {
// return valueOf(str);
// } catch (Exception ex) {
// return NAN;
// }
// }
// }
//
// public MessageQueueInterface getQueue(String type) {
//
// switch (QueueTypes.toQueue(type))
// {
// case AMQ:
// return new ActiveMQ();
// case SQS:
// return new AmazonSQS();
// default:
// Util.cease(logger, "Invalid Message Queue. Quitting.");
// return null;
// }
// }
// }
//
// Path: src/main/java/com/dogeops/cantilever/messagequeue/MessageQueueInterface.java
// public interface MessageQueueInterface {
// public void connect(String hostname, String queue_name);
// public void disconnect();
// public void deliver(String payload);
// public void consume(HTTPAsyncLogMessageListener ml);
// }
//
// Path: src/main/java/com/dogeops/cantilever/utils/ConfigurationSingleton.java
// public enum ConfigurationSingleton {
// instance;
// private static final Logger logger = Logger
// .getLogger(ConfigurationSingleton.class.getName());
//
// private Properties props = new Properties();
//
// private ConfigurationSingleton() {
// }
//
// public void readConfigFile(String config_path) {
// try {
// InputStream input = new FileInputStream(config_path);
// props.load(input);
// input.close();
// } catch (IOException e) {
// cease(logger, e.getMessage());
// }
// }
//
// public String getConfigItem(String val) {
// try {
// if (props.isEmpty()) {
// throw new Exception("Propery file object is empty. "
// + "This likely indicates that the config singleton "
// + "was not properly initialized via readConfigFile.");
// }
// if (props.getProperty(val) == null) {
// throw new Exception("The property " + val
// + " is missing from the configurtion file.");
// }
// return props.getProperty(val);
// } catch (Exception e) {
// cease(logger, e.getMessage());
// return null;
// }
// }
// }
//
// Path: src/main/java/com/dogeops/cantilever/utils/Timer.java
// public class Timer {
//
// private long start;
// private long stop;
// private long elapsed;
//
// public void start() {
// start = System.currentTimeMillis();
// }
//
// public void stop() {
// stop = System.currentTimeMillis();
// }
//
// public long getElapsed() {
// elapsed = stop - start;
// return elapsed;
// }
// }
//
// Path: src/main/java/com/dogeops/cantilever/utils/Util.java
// public class Util {
// public static void cease(Logger logger, String message) {
// logger.error(message);
// System.exit(1);
// }
// }
// Path: src/main/java/com/dogeops/cantilever/beam/LoopControl.java
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.TimeZone;
import org.apache.log4j.Logger;
import com.dogeops.cantilever.messagequeue.MessageQueueFactory;
import com.dogeops.cantilever.messagequeue.MessageQueueInterface;
import com.dogeops.cantilever.utils.ConfigurationSingleton;
import com.dogeops.cantilever.utils.Timer;
import com.dogeops.cantilever.utils.Util;
logger.debug("Staring at: " + startTime.getTime()
+ " and Ending at: " + endTime.getTime() + ", running for "
+ run_time + " ms");
MessageQueueFactory mqf = new MessageQueueFactory();
MessageQueueInterface mqi = mqf.getQueue(ConfigurationSingleton.instance
.getConfigItem("replay.queue.type"));
mqi.connect(ConfigurationSingleton.instance
.getConfigItem("replay.queue.hostname"), ConfigurationSingleton.instance
.getConfigItem("replay.queue.queuename"));
for (int i = 0; i <= (run_time / 1000); i++) {
Timer t = new Timer();
t.start();
new MomentFetcher(startTime, mqi);
t.stop();
if (t.getElapsed() >= 1000) {
logger.debug("Fetch took " + t.getElapsed() + ", this could be a problem....");
} else {
logger.debug("Fetch took: " + t.getElapsed()
+ "ms. Ofsetting pause by " + t.getElapsed() + "ms");
Thread.sleep(1000 - t.getElapsed());
}
}
mqi.disconnect();
} catch (ParseException e) { | Util.cease(logger, e.getMessage()); |
broamski/cantilever | src/main/java/com/dogeops/cantilever/logreader/HTTPLogObject.java | // Path: src/main/java/com/dogeops/cantilever/utils/ConfigurationSingleton.java
// public enum ConfigurationSingleton {
// instance;
// private static final Logger logger = Logger
// .getLogger(ConfigurationSingleton.class.getName());
//
// private Properties props = new Properties();
//
// private ConfigurationSingleton() {
// }
//
// public void readConfigFile(String config_path) {
// try {
// InputStream input = new FileInputStream(config_path);
// props.load(input);
// input.close();
// } catch (IOException e) {
// cease(logger, e.getMessage());
// }
// }
//
// public String getConfigItem(String val) {
// try {
// if (props.isEmpty()) {
// throw new Exception("Propery file object is empty. "
// + "This likely indicates that the config singleton "
// + "was not properly initialized via readConfigFile.");
// }
// if (props.getProperty(val) == null) {
// throw new Exception("The property " + val
// + " is missing from the configurtion file.");
// }
// return props.getProperty(val);
// } catch (Exception e) {
// cease(logger, e.getMessage());
// return null;
// }
// }
// }
| import com.dogeops.cantilever.utils.ConfigurationSingleton;
import com.google.gson.Gson; | package com.dogeops.cantilever.logreader;
public class HTTPLogObject {
private String timestamp, method, request, bytes, useragent;
private String requesting_resver, request_payload, url_request;
private String[] headers;
public HTTPLogObject(String timestamp, String method, String request,
String bytes, String useragent) {
this.timestamp = timestamp;
this.method = method;
this.request = request;
this.bytes = bytes;
this.useragent = useragent;
buildRequestPayload();
}
private void buildHeaderArray() { | // Path: src/main/java/com/dogeops/cantilever/utils/ConfigurationSingleton.java
// public enum ConfigurationSingleton {
// instance;
// private static final Logger logger = Logger
// .getLogger(ConfigurationSingleton.class.getName());
//
// private Properties props = new Properties();
//
// private ConfigurationSingleton() {
// }
//
// public void readConfigFile(String config_path) {
// try {
// InputStream input = new FileInputStream(config_path);
// props.load(input);
// input.close();
// } catch (IOException e) {
// cease(logger, e.getMessage());
// }
// }
//
// public String getConfigItem(String val) {
// try {
// if (props.isEmpty()) {
// throw new Exception("Propery file object is empty. "
// + "This likely indicates that the config singleton "
// + "was not properly initialized via readConfigFile.");
// }
// if (props.getProperty(val) == null) {
// throw new Exception("The property " + val
// + " is missing from the configurtion file.");
// }
// return props.getProperty(val);
// } catch (Exception e) {
// cease(logger, e.getMessage());
// return null;
// }
// }
// }
// Path: src/main/java/com/dogeops/cantilever/logreader/HTTPLogObject.java
import com.dogeops.cantilever.utils.ConfigurationSingleton;
import com.google.gson.Gson;
package com.dogeops.cantilever.logreader;
public class HTTPLogObject {
private String timestamp, method, request, bytes, useragent;
private String requesting_resver, request_payload, url_request;
private String[] headers;
public HTTPLogObject(String timestamp, String method, String request,
String bytes, String useragent) {
this.timestamp = timestamp;
this.method = method;
this.request = request;
this.bytes = bytes;
this.useragent = useragent;
buildRequestPayload();
}
private void buildHeaderArray() { | String header_input = ConfigurationSingleton.instance |
broamski/cantilever | src/main/java/com/dogeops/cantilever/truss/client/apache/HTTPPostRequest.java | // Path: src/main/java/com/dogeops/cantilever/logreader/HTTPLogObject.java
// public class HTTPLogObject {
// private String timestamp, method, request, bytes, useragent;
// private String requesting_resver, request_payload, url_request;
// private String[] headers;
//
// public HTTPLogObject(String timestamp, String method, String request,
// String bytes, String useragent) {
// this.timestamp = timestamp;
// this.method = method;
// this.request = request;
// this.bytes = bytes;
// this.useragent = useragent;
//
// buildRequestPayload();
// }
//
// private void buildHeaderArray() {
// String header_input = ConfigurationSingleton.instance
// .getConfigItem("replay.request.headers");
// String header_delimiter = ConfigurationSingleton.instance
// .getConfigItem("replay.request.headers.delimiter");
// this.headers = header_input.split(header_delimiter);
// }
//
// private void buildRequestPayload() {
// this.requesting_resver = ConfigurationSingleton.instance
// .getConfigItem("replay.request.servername");
// buildHeaderArray();
// buildURLRequest();
// Gson gson = new Gson();
// this.request_payload = gson.toJson(this);
// }
//
// private void buildURLRequest() {
// String http_port = ConfigurationSingleton.instance
// .getConfigItem("replay.request.port");
// String http_protocol = ConfigurationSingleton.instance.getConfigItem(
// "replay.request.protocol").toLowerCase();
//
// if (http_port.equals("80") || http_port.equals("443")) {
// http_port = "";
// } else {
// http_port = ":" + http_port;
// }
// this.url_request = http_protocol + "://" + this.requesting_resver
// + this.request + http_port;
// }
//
// public String getTimestamp() {
// return this.timestamp;
// }
//
// public String getPayload() {
// return this.request_payload;
// }
//
// public String getRequest() {
// return this.request;
// }
//
// public String[] getHeaders() {
// return this.headers;
// }
//
// public String getServerName() {
// return this.requesting_resver;
// }
//
// public String getMethod() {
// return this.method;
// }
//
// public String getUseragent() {
// return this.useragent;
// }
//
// public String getURLRequest() {
// return this.url_request;
// }
// }
//
// Path: src/main/java/com/dogeops/cantilever/utils/ConfigurationSingleton.java
// public enum ConfigurationSingleton {
// instance;
// private static final Logger logger = Logger
// .getLogger(ConfigurationSingleton.class.getName());
//
// private Properties props = new Properties();
//
// private ConfigurationSingleton() {
// }
//
// public void readConfigFile(String config_path) {
// try {
// InputStream input = new FileInputStream(config_path);
// props.load(input);
// input.close();
// } catch (IOException e) {
// cease(logger, e.getMessage());
// }
// }
//
// public String getConfigItem(String val) {
// try {
// if (props.isEmpty()) {
// throw new Exception("Propery file object is empty. "
// + "This likely indicates that the config singleton "
// + "was not properly initialized via readConfigFile.");
// }
// if (props.getProperty(val) == null) {
// throw new Exception("The property " + val
// + " is missing from the configurtion file.");
// }
// return props.getProperty(val);
// } catch (Exception e) {
// cease(logger, e.getMessage());
// return null;
// }
// }
// }
| import java.util.ArrayList;
import java.util.List;
import org.apache.http.NameValuePair;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.protocol.BasicHttpContext;
import org.apache.http.protocol.HttpContext;
import org.apache.log4j.Logger;
import com.dogeops.cantilever.logreader.HTTPLogObject;
import com.dogeops.cantilever.utils.ConfigurationSingleton; | package com.dogeops.cantilever.truss.client.apache;
/*
* This is an extremely basic implementation until it is determined
* how to differentiate and insert the POST entity using the config file
*/
public class HTTPPostRequest extends Thread {
private static final Logger logger = Logger.getLogger(HTTPPostRequest.class
.getName());
private CloseableHttpClient httpClient;
private HttpContext context;
private HttpPost httppost; | // Path: src/main/java/com/dogeops/cantilever/logreader/HTTPLogObject.java
// public class HTTPLogObject {
// private String timestamp, method, request, bytes, useragent;
// private String requesting_resver, request_payload, url_request;
// private String[] headers;
//
// public HTTPLogObject(String timestamp, String method, String request,
// String bytes, String useragent) {
// this.timestamp = timestamp;
// this.method = method;
// this.request = request;
// this.bytes = bytes;
// this.useragent = useragent;
//
// buildRequestPayload();
// }
//
// private void buildHeaderArray() {
// String header_input = ConfigurationSingleton.instance
// .getConfigItem("replay.request.headers");
// String header_delimiter = ConfigurationSingleton.instance
// .getConfigItem("replay.request.headers.delimiter");
// this.headers = header_input.split(header_delimiter);
// }
//
// private void buildRequestPayload() {
// this.requesting_resver = ConfigurationSingleton.instance
// .getConfigItem("replay.request.servername");
// buildHeaderArray();
// buildURLRequest();
// Gson gson = new Gson();
// this.request_payload = gson.toJson(this);
// }
//
// private void buildURLRequest() {
// String http_port = ConfigurationSingleton.instance
// .getConfigItem("replay.request.port");
// String http_protocol = ConfigurationSingleton.instance.getConfigItem(
// "replay.request.protocol").toLowerCase();
//
// if (http_port.equals("80") || http_port.equals("443")) {
// http_port = "";
// } else {
// http_port = ":" + http_port;
// }
// this.url_request = http_protocol + "://" + this.requesting_resver
// + this.request + http_port;
// }
//
// public String getTimestamp() {
// return this.timestamp;
// }
//
// public String getPayload() {
// return this.request_payload;
// }
//
// public String getRequest() {
// return this.request;
// }
//
// public String[] getHeaders() {
// return this.headers;
// }
//
// public String getServerName() {
// return this.requesting_resver;
// }
//
// public String getMethod() {
// return this.method;
// }
//
// public String getUseragent() {
// return this.useragent;
// }
//
// public String getURLRequest() {
// return this.url_request;
// }
// }
//
// Path: src/main/java/com/dogeops/cantilever/utils/ConfigurationSingleton.java
// public enum ConfigurationSingleton {
// instance;
// private static final Logger logger = Logger
// .getLogger(ConfigurationSingleton.class.getName());
//
// private Properties props = new Properties();
//
// private ConfigurationSingleton() {
// }
//
// public void readConfigFile(String config_path) {
// try {
// InputStream input = new FileInputStream(config_path);
// props.load(input);
// input.close();
// } catch (IOException e) {
// cease(logger, e.getMessage());
// }
// }
//
// public String getConfigItem(String val) {
// try {
// if (props.isEmpty()) {
// throw new Exception("Propery file object is empty. "
// + "This likely indicates that the config singleton "
// + "was not properly initialized via readConfigFile.");
// }
// if (props.getProperty(val) == null) {
// throw new Exception("The property " + val
// + " is missing from the configurtion file.");
// }
// return props.getProperty(val);
// } catch (Exception e) {
// cease(logger, e.getMessage());
// return null;
// }
// }
// }
// Path: src/main/java/com/dogeops/cantilever/truss/client/apache/HTTPPostRequest.java
import java.util.ArrayList;
import java.util.List;
import org.apache.http.NameValuePair;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.protocol.BasicHttpContext;
import org.apache.http.protocol.HttpContext;
import org.apache.log4j.Logger;
import com.dogeops.cantilever.logreader.HTTPLogObject;
import com.dogeops.cantilever.utils.ConfigurationSingleton;
package com.dogeops.cantilever.truss.client.apache;
/*
* This is an extremely basic implementation until it is determined
* how to differentiate and insert the POST entity using the config file
*/
public class HTTPPostRequest extends Thread {
private static final Logger logger = Logger.getLogger(HTTPPostRequest.class
.getName());
private CloseableHttpClient httpClient;
private HttpContext context;
private HttpPost httppost; | private HTTPLogObject http_log; |
broamski/cantilever | src/main/java/com/dogeops/cantilever/truss/client/apache/HTTPPostRequest.java | // Path: src/main/java/com/dogeops/cantilever/logreader/HTTPLogObject.java
// public class HTTPLogObject {
// private String timestamp, method, request, bytes, useragent;
// private String requesting_resver, request_payload, url_request;
// private String[] headers;
//
// public HTTPLogObject(String timestamp, String method, String request,
// String bytes, String useragent) {
// this.timestamp = timestamp;
// this.method = method;
// this.request = request;
// this.bytes = bytes;
// this.useragent = useragent;
//
// buildRequestPayload();
// }
//
// private void buildHeaderArray() {
// String header_input = ConfigurationSingleton.instance
// .getConfigItem("replay.request.headers");
// String header_delimiter = ConfigurationSingleton.instance
// .getConfigItem("replay.request.headers.delimiter");
// this.headers = header_input.split(header_delimiter);
// }
//
// private void buildRequestPayload() {
// this.requesting_resver = ConfigurationSingleton.instance
// .getConfigItem("replay.request.servername");
// buildHeaderArray();
// buildURLRequest();
// Gson gson = new Gson();
// this.request_payload = gson.toJson(this);
// }
//
// private void buildURLRequest() {
// String http_port = ConfigurationSingleton.instance
// .getConfigItem("replay.request.port");
// String http_protocol = ConfigurationSingleton.instance.getConfigItem(
// "replay.request.protocol").toLowerCase();
//
// if (http_port.equals("80") || http_port.equals("443")) {
// http_port = "";
// } else {
// http_port = ":" + http_port;
// }
// this.url_request = http_protocol + "://" + this.requesting_resver
// + this.request + http_port;
// }
//
// public String getTimestamp() {
// return this.timestamp;
// }
//
// public String getPayload() {
// return this.request_payload;
// }
//
// public String getRequest() {
// return this.request;
// }
//
// public String[] getHeaders() {
// return this.headers;
// }
//
// public String getServerName() {
// return this.requesting_resver;
// }
//
// public String getMethod() {
// return this.method;
// }
//
// public String getUseragent() {
// return this.useragent;
// }
//
// public String getURLRequest() {
// return this.url_request;
// }
// }
//
// Path: src/main/java/com/dogeops/cantilever/utils/ConfigurationSingleton.java
// public enum ConfigurationSingleton {
// instance;
// private static final Logger logger = Logger
// .getLogger(ConfigurationSingleton.class.getName());
//
// private Properties props = new Properties();
//
// private ConfigurationSingleton() {
// }
//
// public void readConfigFile(String config_path) {
// try {
// InputStream input = new FileInputStream(config_path);
// props.load(input);
// input.close();
// } catch (IOException e) {
// cease(logger, e.getMessage());
// }
// }
//
// public String getConfigItem(String val) {
// try {
// if (props.isEmpty()) {
// throw new Exception("Propery file object is empty. "
// + "This likely indicates that the config singleton "
// + "was not properly initialized via readConfigFile.");
// }
// if (props.getProperty(val) == null) {
// throw new Exception("The property " + val
// + " is missing from the configurtion file.");
// }
// return props.getProperty(val);
// } catch (Exception e) {
// cease(logger, e.getMessage());
// return null;
// }
// }
// }
| import java.util.ArrayList;
import java.util.List;
import org.apache.http.NameValuePair;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.protocol.BasicHttpContext;
import org.apache.http.protocol.HttpContext;
import org.apache.log4j.Logger;
import com.dogeops.cantilever.logreader.HTTPLogObject;
import com.dogeops.cantilever.utils.ConfigurationSingleton; | package com.dogeops.cantilever.truss.client.apache;
/*
* This is an extremely basic implementation until it is determined
* how to differentiate and insert the POST entity using the config file
*/
public class HTTPPostRequest extends Thread {
private static final Logger logger = Logger.getLogger(HTTPPostRequest.class
.getName());
private CloseableHttpClient httpClient;
private HttpContext context;
private HttpPost httppost;
private HTTPLogObject http_log;
public HTTPPostRequest(HTTPLogObject http_log, CloseableHttpClient httpClient) {
this.http_log = http_log;
this.httpClient = httpClient;
this.context = new BasicHttpContext();
}
public void run() {
// I'm unsure why we access these particular config items from the
// config singleton and not-prop them like we do in the HTTP Log Object
// Low priority, but should be reviewed at some point
| // Path: src/main/java/com/dogeops/cantilever/logreader/HTTPLogObject.java
// public class HTTPLogObject {
// private String timestamp, method, request, bytes, useragent;
// private String requesting_resver, request_payload, url_request;
// private String[] headers;
//
// public HTTPLogObject(String timestamp, String method, String request,
// String bytes, String useragent) {
// this.timestamp = timestamp;
// this.method = method;
// this.request = request;
// this.bytes = bytes;
// this.useragent = useragent;
//
// buildRequestPayload();
// }
//
// private void buildHeaderArray() {
// String header_input = ConfigurationSingleton.instance
// .getConfigItem("replay.request.headers");
// String header_delimiter = ConfigurationSingleton.instance
// .getConfigItem("replay.request.headers.delimiter");
// this.headers = header_input.split(header_delimiter);
// }
//
// private void buildRequestPayload() {
// this.requesting_resver = ConfigurationSingleton.instance
// .getConfigItem("replay.request.servername");
// buildHeaderArray();
// buildURLRequest();
// Gson gson = new Gson();
// this.request_payload = gson.toJson(this);
// }
//
// private void buildURLRequest() {
// String http_port = ConfigurationSingleton.instance
// .getConfigItem("replay.request.port");
// String http_protocol = ConfigurationSingleton.instance.getConfigItem(
// "replay.request.protocol").toLowerCase();
//
// if (http_port.equals("80") || http_port.equals("443")) {
// http_port = "";
// } else {
// http_port = ":" + http_port;
// }
// this.url_request = http_protocol + "://" + this.requesting_resver
// + this.request + http_port;
// }
//
// public String getTimestamp() {
// return this.timestamp;
// }
//
// public String getPayload() {
// return this.request_payload;
// }
//
// public String getRequest() {
// return this.request;
// }
//
// public String[] getHeaders() {
// return this.headers;
// }
//
// public String getServerName() {
// return this.requesting_resver;
// }
//
// public String getMethod() {
// return this.method;
// }
//
// public String getUseragent() {
// return this.useragent;
// }
//
// public String getURLRequest() {
// return this.url_request;
// }
// }
//
// Path: src/main/java/com/dogeops/cantilever/utils/ConfigurationSingleton.java
// public enum ConfigurationSingleton {
// instance;
// private static final Logger logger = Logger
// .getLogger(ConfigurationSingleton.class.getName());
//
// private Properties props = new Properties();
//
// private ConfigurationSingleton() {
// }
//
// public void readConfigFile(String config_path) {
// try {
// InputStream input = new FileInputStream(config_path);
// props.load(input);
// input.close();
// } catch (IOException e) {
// cease(logger, e.getMessage());
// }
// }
//
// public String getConfigItem(String val) {
// try {
// if (props.isEmpty()) {
// throw new Exception("Propery file object is empty. "
// + "This likely indicates that the config singleton "
// + "was not properly initialized via readConfigFile.");
// }
// if (props.getProperty(val) == null) {
// throw new Exception("The property " + val
// + " is missing from the configurtion file.");
// }
// return props.getProperty(val);
// } catch (Exception e) {
// cease(logger, e.getMessage());
// return null;
// }
// }
// }
// Path: src/main/java/com/dogeops/cantilever/truss/client/apache/HTTPPostRequest.java
import java.util.ArrayList;
import java.util.List;
import org.apache.http.NameValuePair;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.protocol.BasicHttpContext;
import org.apache.http.protocol.HttpContext;
import org.apache.log4j.Logger;
import com.dogeops.cantilever.logreader.HTTPLogObject;
import com.dogeops.cantilever.utils.ConfigurationSingleton;
package com.dogeops.cantilever.truss.client.apache;
/*
* This is an extremely basic implementation until it is determined
* how to differentiate and insert the POST entity using the config file
*/
public class HTTPPostRequest extends Thread {
private static final Logger logger = Logger.getLogger(HTTPPostRequest.class
.getName());
private CloseableHttpClient httpClient;
private HttpContext context;
private HttpPost httppost;
private HTTPLogObject http_log;
public HTTPPostRequest(HTTPLogObject http_log, CloseableHttpClient httpClient) {
this.http_log = http_log;
this.httpClient = httpClient;
this.context = new BasicHttpContext();
}
public void run() {
// I'm unsure why we access these particular config items from the
// config singleton and not-prop them like we do in the HTTP Log Object
// Low priority, but should be reviewed at some point
| String http_port = ConfigurationSingleton.instance.getConfigItem("replay.request.port"); |
broamski/cantilever | src/main/java/com/dogeops/cantilever/truss/POSTPayloadCacheBuilder.java | // Path: src/main/java/com/dogeops/cantilever/utils/ConfigurationSingleton.java
// public enum ConfigurationSingleton {
// instance;
// private static final Logger logger = Logger
// .getLogger(ConfigurationSingleton.class.getName());
//
// private Properties props = new Properties();
//
// private ConfigurationSingleton() {
// }
//
// public void readConfigFile(String config_path) {
// try {
// InputStream input = new FileInputStream(config_path);
// props.load(input);
// input.close();
// } catch (IOException e) {
// cease(logger, e.getMessage());
// }
// }
//
// public String getConfigItem(String val) {
// try {
// if (props.isEmpty()) {
// throw new Exception("Propery file object is empty. "
// + "This likely indicates that the config singleton "
// + "was not properly initialized via readConfigFile.");
// }
// if (props.getProperty(val) == null) {
// throw new Exception("The property " + val
// + " is missing from the configurtion file.");
// }
// return props.getProperty(val);
// } catch (Exception e) {
// cease(logger, e.getMessage());
// return null;
// }
// }
// }
| import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import org.apache.log4j.Logger;
import com.dogeops.cantilever.utils.ConfigurationSingleton; | package com.dogeops.cantilever.truss;
public class POSTPayloadCacheBuilder {
private static final Logger logger = Logger.getLogger(POSTPayloadCacheBuilder.class
.getName());
private final String post_payload_config_key = "truss.post.patterns";
public POSTPayloadCacheBuilder() { | // Path: src/main/java/com/dogeops/cantilever/utils/ConfigurationSingleton.java
// public enum ConfigurationSingleton {
// instance;
// private static final Logger logger = Logger
// .getLogger(ConfigurationSingleton.class.getName());
//
// private Properties props = new Properties();
//
// private ConfigurationSingleton() {
// }
//
// public void readConfigFile(String config_path) {
// try {
// InputStream input = new FileInputStream(config_path);
// props.load(input);
// input.close();
// } catch (IOException e) {
// cease(logger, e.getMessage());
// }
// }
//
// public String getConfigItem(String val) {
// try {
// if (props.isEmpty()) {
// throw new Exception("Propery file object is empty. "
// + "This likely indicates that the config singleton "
// + "was not properly initialized via readConfigFile.");
// }
// if (props.getProperty(val) == null) {
// throw new Exception("The property " + val
// + " is missing from the configurtion file.");
// }
// return props.getProperty(val);
// } catch (Exception e) {
// cease(logger, e.getMessage());
// return null;
// }
// }
// }
// Path: src/main/java/com/dogeops/cantilever/truss/POSTPayloadCacheBuilder.java
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import org.apache.log4j.Logger;
import com.dogeops.cantilever.utils.ConfigurationSingleton;
package com.dogeops.cantilever.truss;
public class POSTPayloadCacheBuilder {
private static final Logger logger = Logger.getLogger(POSTPayloadCacheBuilder.class
.getName());
private final String post_payload_config_key = "truss.post.patterns";
public POSTPayloadCacheBuilder() { | File pattern_file = new File(ConfigurationSingleton.instance |
broamski/cantilever | src/main/java/com/dogeops/cantilever/truss/GETHeaderCacheBuilder.java | // Path: src/main/java/com/dogeops/cantilever/utils/ConfigurationSingleton.java
// public enum ConfigurationSingleton {
// instance;
// private static final Logger logger = Logger
// .getLogger(ConfigurationSingleton.class.getName());
//
// private Properties props = new Properties();
//
// private ConfigurationSingleton() {
// }
//
// public void readConfigFile(String config_path) {
// try {
// InputStream input = new FileInputStream(config_path);
// props.load(input);
// input.close();
// } catch (IOException e) {
// cease(logger, e.getMessage());
// }
// }
//
// public String getConfigItem(String val) {
// try {
// if (props.isEmpty()) {
// throw new Exception("Propery file object is empty. "
// + "This likely indicates that the config singleton "
// + "was not properly initialized via readConfigFile.");
// }
// if (props.getProperty(val) == null) {
// throw new Exception("The property " + val
// + " is missing from the configurtion file.");
// }
// return props.getProperty(val);
// } catch (Exception e) {
// cease(logger, e.getMessage());
// return null;
// }
// }
// }
| import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import org.apache.log4j.Logger;
import com.dogeops.cantilever.utils.ConfigurationSingleton; | package com.dogeops.cantilever.truss;
public class GETHeaderCacheBuilder {
private static final Logger logger = Logger.getLogger(GETHeaderCacheBuilder.class
.getName());
private final String get_config_key = "truss.get.headers";
public GETHeaderCacheBuilder() { | // Path: src/main/java/com/dogeops/cantilever/utils/ConfigurationSingleton.java
// public enum ConfigurationSingleton {
// instance;
// private static final Logger logger = Logger
// .getLogger(ConfigurationSingleton.class.getName());
//
// private Properties props = new Properties();
//
// private ConfigurationSingleton() {
// }
//
// public void readConfigFile(String config_path) {
// try {
// InputStream input = new FileInputStream(config_path);
// props.load(input);
// input.close();
// } catch (IOException e) {
// cease(logger, e.getMessage());
// }
// }
//
// public String getConfigItem(String val) {
// try {
// if (props.isEmpty()) {
// throw new Exception("Propery file object is empty. "
// + "This likely indicates that the config singleton "
// + "was not properly initialized via readConfigFile.");
// }
// if (props.getProperty(val) == null) {
// throw new Exception("The property " + val
// + " is missing from the configurtion file.");
// }
// return props.getProperty(val);
// } catch (Exception e) {
// cease(logger, e.getMessage());
// return null;
// }
// }
// }
// Path: src/main/java/com/dogeops/cantilever/truss/GETHeaderCacheBuilder.java
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import org.apache.log4j.Logger;
import com.dogeops.cantilever.utils.ConfigurationSingleton;
package com.dogeops.cantilever.truss;
public class GETHeaderCacheBuilder {
private static final Logger logger = Logger.getLogger(GETHeaderCacheBuilder.class
.getName());
private final String get_config_key = "truss.get.headers";
public GETHeaderCacheBuilder() { | File pattern_file = new File(ConfigurationSingleton.instance |
broamski/cantilever | src/main/java/com/dogeops/cantilever/truss/client/ning/HTTPAsyncLogMessageListener.java | // Path: src/main/java/com/dogeops/cantilever/logreader/HTTPLogObject.java
// public class HTTPLogObject {
// private String timestamp, method, request, bytes, useragent;
// private String requesting_resver, request_payload, url_request;
// private String[] headers;
//
// public HTTPLogObject(String timestamp, String method, String request,
// String bytes, String useragent) {
// this.timestamp = timestamp;
// this.method = method;
// this.request = request;
// this.bytes = bytes;
// this.useragent = useragent;
//
// buildRequestPayload();
// }
//
// private void buildHeaderArray() {
// String header_input = ConfigurationSingleton.instance
// .getConfigItem("replay.request.headers");
// String header_delimiter = ConfigurationSingleton.instance
// .getConfigItem("replay.request.headers.delimiter");
// this.headers = header_input.split(header_delimiter);
// }
//
// private void buildRequestPayload() {
// this.requesting_resver = ConfigurationSingleton.instance
// .getConfigItem("replay.request.servername");
// buildHeaderArray();
// buildURLRequest();
// Gson gson = new Gson();
// this.request_payload = gson.toJson(this);
// }
//
// private void buildURLRequest() {
// String http_port = ConfigurationSingleton.instance
// .getConfigItem("replay.request.port");
// String http_protocol = ConfigurationSingleton.instance.getConfigItem(
// "replay.request.protocol").toLowerCase();
//
// if (http_port.equals("80") || http_port.equals("443")) {
// http_port = "";
// } else {
// http_port = ":" + http_port;
// }
// this.url_request = http_protocol + "://" + this.requesting_resver
// + this.request + http_port;
// }
//
// public String getTimestamp() {
// return this.timestamp;
// }
//
// public String getPayload() {
// return this.request_payload;
// }
//
// public String getRequest() {
// return this.request;
// }
//
// public String[] getHeaders() {
// return this.headers;
// }
//
// public String getServerName() {
// return this.requesting_resver;
// }
//
// public String getMethod() {
// return this.method;
// }
//
// public String getUseragent() {
// return this.useragent;
// }
//
// public String getURLRequest() {
// return this.url_request;
// }
// }
| import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.TextMessage;
import org.apache.log4j.Logger;
import com.dogeops.cantilever.logreader.HTTPLogObject;
import com.google.gson.Gson;
import com.ning.http.client.AsyncHttpClient;
import com.ning.http.client.AsyncHttpClientConfig;
import com.ning.http.client.AsyncHttpClientConfig.Builder; |
public HTTPAsyncLogMessageListener() {
builder = new AsyncHttpClientConfig.Builder();
builder.setCompressionEnabled(true)
.setMaximumConnectionsPerHost(100)
.setRequestTimeoutInMs(15000)
.build();
client = new AsyncHttpClient(builder.build());
}
public enum AcceptableMethods {
GET, POST, NAN;
public static AcceptableMethods getValue(String str) {
try {
return valueOf(str);
} catch (Exception e) {
logger.error(e.getMessage());
return NAN;
}
}
}
public void onMessage(Message message) {
if (message instanceof TextMessage) {
TextMessage textMessage = (TextMessage) message;
String text;
try {
text = textMessage.getText();
Gson gson = new Gson(); | // Path: src/main/java/com/dogeops/cantilever/logreader/HTTPLogObject.java
// public class HTTPLogObject {
// private String timestamp, method, request, bytes, useragent;
// private String requesting_resver, request_payload, url_request;
// private String[] headers;
//
// public HTTPLogObject(String timestamp, String method, String request,
// String bytes, String useragent) {
// this.timestamp = timestamp;
// this.method = method;
// this.request = request;
// this.bytes = bytes;
// this.useragent = useragent;
//
// buildRequestPayload();
// }
//
// private void buildHeaderArray() {
// String header_input = ConfigurationSingleton.instance
// .getConfigItem("replay.request.headers");
// String header_delimiter = ConfigurationSingleton.instance
// .getConfigItem("replay.request.headers.delimiter");
// this.headers = header_input.split(header_delimiter);
// }
//
// private void buildRequestPayload() {
// this.requesting_resver = ConfigurationSingleton.instance
// .getConfigItem("replay.request.servername");
// buildHeaderArray();
// buildURLRequest();
// Gson gson = new Gson();
// this.request_payload = gson.toJson(this);
// }
//
// private void buildURLRequest() {
// String http_port = ConfigurationSingleton.instance
// .getConfigItem("replay.request.port");
// String http_protocol = ConfigurationSingleton.instance.getConfigItem(
// "replay.request.protocol").toLowerCase();
//
// if (http_port.equals("80") || http_port.equals("443")) {
// http_port = "";
// } else {
// http_port = ":" + http_port;
// }
// this.url_request = http_protocol + "://" + this.requesting_resver
// + this.request + http_port;
// }
//
// public String getTimestamp() {
// return this.timestamp;
// }
//
// public String getPayload() {
// return this.request_payload;
// }
//
// public String getRequest() {
// return this.request;
// }
//
// public String[] getHeaders() {
// return this.headers;
// }
//
// public String getServerName() {
// return this.requesting_resver;
// }
//
// public String getMethod() {
// return this.method;
// }
//
// public String getUseragent() {
// return this.useragent;
// }
//
// public String getURLRequest() {
// return this.url_request;
// }
// }
// Path: src/main/java/com/dogeops/cantilever/truss/client/ning/HTTPAsyncLogMessageListener.java
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.TextMessage;
import org.apache.log4j.Logger;
import com.dogeops.cantilever.logreader.HTTPLogObject;
import com.google.gson.Gson;
import com.ning.http.client.AsyncHttpClient;
import com.ning.http.client.AsyncHttpClientConfig;
import com.ning.http.client.AsyncHttpClientConfig.Builder;
public HTTPAsyncLogMessageListener() {
builder = new AsyncHttpClientConfig.Builder();
builder.setCompressionEnabled(true)
.setMaximumConnectionsPerHost(100)
.setRequestTimeoutInMs(15000)
.build();
client = new AsyncHttpClient(builder.build());
}
public enum AcceptableMethods {
GET, POST, NAN;
public static AcceptableMethods getValue(String str) {
try {
return valueOf(str);
} catch (Exception e) {
logger.error(e.getMessage());
return NAN;
}
}
}
public void onMessage(Message message) {
if (message instanceof TextMessage) {
TextMessage textMessage = (TextMessage) message;
String text;
try {
text = textMessage.getText();
Gson gson = new Gson(); | HTTPLogObject http_log = gson.fromJson(text, HTTPLogObject.class); |
broamski/cantilever | src/main/java/com/dogeops/cantilever/beam/BeamServer.java | // Path: src/main/java/com/dogeops/cantilever/logreader/HTTPLogReader.java
// public class HTTPLogReader {
// private static final Logger logger = Logger.getLogger(HTTPLogReader.class
// .getName());
// private int fileCount = 0;
//
// public void readLogs(String path) {
// logger.info("Reading logs in " + path + "....");
// String log_regex = ConfigurationSingleton.instance
// .getConfigItem("log.convert.regex");
// Timer t = new Timer();
// t.start();
// File folder = new File(path);
// if (folder.exists()) {
// for (File file : folder.listFiles()) {
// fileCount++;
// logger.info("Pasring file: " + file.getAbsolutePath());
// try {
// BufferedReader br = new BufferedReader(new FileReader(
// file.getAbsolutePath()));
// String line = null;
// while ((line = br.readLine()) != null) {
// logger.trace(line);
// line = line.trim();
//
// Pattern p = Pattern.compile(log_regex);
// Matcher m = p.matcher(line);
// try {
// m.find();
// HTTPLogObject hl = new HTTPLogObject(
// m.group("TIMESTAMP"), m.group("METHOD"),
// m.group("REQUEST"), m.group("BYTES"), m
// .group("USERAGENT").replace("\"",
// ""));
//
// ReplayCache.instance.addToCache(hl);
// } catch (Exception e) {
// logger.error("Unparsable line: " + line + " - "
// + e.getMessage());
// }
// }
// br.close();
// } catch (FileNotFoundException e) {
// cease(logger, e.getMessage());
// } catch (IOException e) {
// cease(logger, e.getMessage());
// }
// }
// t.stop();
// logger.info(fileCount + " files parsed in " + t.getElapsed()
// + " ms");
// } else {
// cease(logger, "Could not find folder " + path);
// }
// }
// }
//
// Path: src/main/java/com/dogeops/cantilever/utils/Configuration.java
// public class Configuration {
// private static void usage(Options options) {
// HelpFormatter formatter = new HelpFormatter();
// formatter.printHelp("Usage options:", options);
// }
//
// public void getConfigFile(String[] args) {
// Options opt = new Options();
// Option op = new Option("config", true,
// "Full path to config file: /opt/cantilever/cantilever.config");
// op.setRequired(true);
// opt.addOption(op);
//
// CommandLineParser parser = new BasicParser();
// CommandLine cmd;
//
// try {
// cmd = parser.parse(opt, args);
// ConfigurationSingleton.instance.readConfigFile(cmd
// .getOptionValue("config"));
//
// } catch (ParseException pe) {
// usage(opt);
// }
// }
// }
//
// Path: src/main/java/com/dogeops/cantilever/utils/ConfigurationSingleton.java
// public enum ConfigurationSingleton {
// instance;
// private static final Logger logger = Logger
// .getLogger(ConfigurationSingleton.class.getName());
//
// private Properties props = new Properties();
//
// private ConfigurationSingleton() {
// }
//
// public void readConfigFile(String config_path) {
// try {
// InputStream input = new FileInputStream(config_path);
// props.load(input);
// input.close();
// } catch (IOException e) {
// cease(logger, e.getMessage());
// }
// }
//
// public String getConfigItem(String val) {
// try {
// if (props.isEmpty()) {
// throw new Exception("Propery file object is empty. "
// + "This likely indicates that the config singleton "
// + "was not properly initialized via readConfigFile.");
// }
// if (props.getProperty(val) == null) {
// throw new Exception("The property " + val
// + " is missing from the configurtion file.");
// }
// return props.getProperty(val);
// } catch (Exception e) {
// cease(logger, e.getMessage());
// return null;
// }
// }
// }
| import org.apache.log4j.Logger;
import com.dogeops.cantilever.logreader.HTTPLogReader;
import com.dogeops.cantilever.utils.Configuration;
import com.dogeops.cantilever.utils.ConfigurationSingleton; | package com.dogeops.cantilever.beam;
public class BeamServer {
private static final Logger logger = Logger.getLogger(BeamServer.class
.getName());
public static void main(String[] args) { | // Path: src/main/java/com/dogeops/cantilever/logreader/HTTPLogReader.java
// public class HTTPLogReader {
// private static final Logger logger = Logger.getLogger(HTTPLogReader.class
// .getName());
// private int fileCount = 0;
//
// public void readLogs(String path) {
// logger.info("Reading logs in " + path + "....");
// String log_regex = ConfigurationSingleton.instance
// .getConfigItem("log.convert.regex");
// Timer t = new Timer();
// t.start();
// File folder = new File(path);
// if (folder.exists()) {
// for (File file : folder.listFiles()) {
// fileCount++;
// logger.info("Pasring file: " + file.getAbsolutePath());
// try {
// BufferedReader br = new BufferedReader(new FileReader(
// file.getAbsolutePath()));
// String line = null;
// while ((line = br.readLine()) != null) {
// logger.trace(line);
// line = line.trim();
//
// Pattern p = Pattern.compile(log_regex);
// Matcher m = p.matcher(line);
// try {
// m.find();
// HTTPLogObject hl = new HTTPLogObject(
// m.group("TIMESTAMP"), m.group("METHOD"),
// m.group("REQUEST"), m.group("BYTES"), m
// .group("USERAGENT").replace("\"",
// ""));
//
// ReplayCache.instance.addToCache(hl);
// } catch (Exception e) {
// logger.error("Unparsable line: " + line + " - "
// + e.getMessage());
// }
// }
// br.close();
// } catch (FileNotFoundException e) {
// cease(logger, e.getMessage());
// } catch (IOException e) {
// cease(logger, e.getMessage());
// }
// }
// t.stop();
// logger.info(fileCount + " files parsed in " + t.getElapsed()
// + " ms");
// } else {
// cease(logger, "Could not find folder " + path);
// }
// }
// }
//
// Path: src/main/java/com/dogeops/cantilever/utils/Configuration.java
// public class Configuration {
// private static void usage(Options options) {
// HelpFormatter formatter = new HelpFormatter();
// formatter.printHelp("Usage options:", options);
// }
//
// public void getConfigFile(String[] args) {
// Options opt = new Options();
// Option op = new Option("config", true,
// "Full path to config file: /opt/cantilever/cantilever.config");
// op.setRequired(true);
// opt.addOption(op);
//
// CommandLineParser parser = new BasicParser();
// CommandLine cmd;
//
// try {
// cmd = parser.parse(opt, args);
// ConfigurationSingleton.instance.readConfigFile(cmd
// .getOptionValue("config"));
//
// } catch (ParseException pe) {
// usage(opt);
// }
// }
// }
//
// Path: src/main/java/com/dogeops/cantilever/utils/ConfigurationSingleton.java
// public enum ConfigurationSingleton {
// instance;
// private static final Logger logger = Logger
// .getLogger(ConfigurationSingleton.class.getName());
//
// private Properties props = new Properties();
//
// private ConfigurationSingleton() {
// }
//
// public void readConfigFile(String config_path) {
// try {
// InputStream input = new FileInputStream(config_path);
// props.load(input);
// input.close();
// } catch (IOException e) {
// cease(logger, e.getMessage());
// }
// }
//
// public String getConfigItem(String val) {
// try {
// if (props.isEmpty()) {
// throw new Exception("Propery file object is empty. "
// + "This likely indicates that the config singleton "
// + "was not properly initialized via readConfigFile.");
// }
// if (props.getProperty(val) == null) {
// throw new Exception("The property " + val
// + " is missing from the configurtion file.");
// }
// return props.getProperty(val);
// } catch (Exception e) {
// cease(logger, e.getMessage());
// return null;
// }
// }
// }
// Path: src/main/java/com/dogeops/cantilever/beam/BeamServer.java
import org.apache.log4j.Logger;
import com.dogeops.cantilever.logreader.HTTPLogReader;
import com.dogeops.cantilever.utils.Configuration;
import com.dogeops.cantilever.utils.ConfigurationSingleton;
package com.dogeops.cantilever.beam;
public class BeamServer {
private static final Logger logger = Logger.getLogger(BeamServer.class
.getName());
public static void main(String[] args) { | Configuration config = new Configuration(); |
broamski/cantilever | src/main/java/com/dogeops/cantilever/beam/BeamServer.java | // Path: src/main/java/com/dogeops/cantilever/logreader/HTTPLogReader.java
// public class HTTPLogReader {
// private static final Logger logger = Logger.getLogger(HTTPLogReader.class
// .getName());
// private int fileCount = 0;
//
// public void readLogs(String path) {
// logger.info("Reading logs in " + path + "....");
// String log_regex = ConfigurationSingleton.instance
// .getConfigItem("log.convert.regex");
// Timer t = new Timer();
// t.start();
// File folder = new File(path);
// if (folder.exists()) {
// for (File file : folder.listFiles()) {
// fileCount++;
// logger.info("Pasring file: " + file.getAbsolutePath());
// try {
// BufferedReader br = new BufferedReader(new FileReader(
// file.getAbsolutePath()));
// String line = null;
// while ((line = br.readLine()) != null) {
// logger.trace(line);
// line = line.trim();
//
// Pattern p = Pattern.compile(log_regex);
// Matcher m = p.matcher(line);
// try {
// m.find();
// HTTPLogObject hl = new HTTPLogObject(
// m.group("TIMESTAMP"), m.group("METHOD"),
// m.group("REQUEST"), m.group("BYTES"), m
// .group("USERAGENT").replace("\"",
// ""));
//
// ReplayCache.instance.addToCache(hl);
// } catch (Exception e) {
// logger.error("Unparsable line: " + line + " - "
// + e.getMessage());
// }
// }
// br.close();
// } catch (FileNotFoundException e) {
// cease(logger, e.getMessage());
// } catch (IOException e) {
// cease(logger, e.getMessage());
// }
// }
// t.stop();
// logger.info(fileCount + " files parsed in " + t.getElapsed()
// + " ms");
// } else {
// cease(logger, "Could not find folder " + path);
// }
// }
// }
//
// Path: src/main/java/com/dogeops/cantilever/utils/Configuration.java
// public class Configuration {
// private static void usage(Options options) {
// HelpFormatter formatter = new HelpFormatter();
// formatter.printHelp("Usage options:", options);
// }
//
// public void getConfigFile(String[] args) {
// Options opt = new Options();
// Option op = new Option("config", true,
// "Full path to config file: /opt/cantilever/cantilever.config");
// op.setRequired(true);
// opt.addOption(op);
//
// CommandLineParser parser = new BasicParser();
// CommandLine cmd;
//
// try {
// cmd = parser.parse(opt, args);
// ConfigurationSingleton.instance.readConfigFile(cmd
// .getOptionValue("config"));
//
// } catch (ParseException pe) {
// usage(opt);
// }
// }
// }
//
// Path: src/main/java/com/dogeops/cantilever/utils/ConfigurationSingleton.java
// public enum ConfigurationSingleton {
// instance;
// private static final Logger logger = Logger
// .getLogger(ConfigurationSingleton.class.getName());
//
// private Properties props = new Properties();
//
// private ConfigurationSingleton() {
// }
//
// public void readConfigFile(String config_path) {
// try {
// InputStream input = new FileInputStream(config_path);
// props.load(input);
// input.close();
// } catch (IOException e) {
// cease(logger, e.getMessage());
// }
// }
//
// public String getConfigItem(String val) {
// try {
// if (props.isEmpty()) {
// throw new Exception("Propery file object is empty. "
// + "This likely indicates that the config singleton "
// + "was not properly initialized via readConfigFile.");
// }
// if (props.getProperty(val) == null) {
// throw new Exception("The property " + val
// + " is missing from the configurtion file.");
// }
// return props.getProperty(val);
// } catch (Exception e) {
// cease(logger, e.getMessage());
// return null;
// }
// }
// }
| import org.apache.log4j.Logger;
import com.dogeops.cantilever.logreader.HTTPLogReader;
import com.dogeops.cantilever.utils.Configuration;
import com.dogeops.cantilever.utils.ConfigurationSingleton; | package com.dogeops.cantilever.beam;
public class BeamServer {
private static final Logger logger = Logger.getLogger(BeamServer.class
.getName());
public static void main(String[] args) {
Configuration config = new Configuration();
config.getConfigFile(args);
| // Path: src/main/java/com/dogeops/cantilever/logreader/HTTPLogReader.java
// public class HTTPLogReader {
// private static final Logger logger = Logger.getLogger(HTTPLogReader.class
// .getName());
// private int fileCount = 0;
//
// public void readLogs(String path) {
// logger.info("Reading logs in " + path + "....");
// String log_regex = ConfigurationSingleton.instance
// .getConfigItem("log.convert.regex");
// Timer t = new Timer();
// t.start();
// File folder = new File(path);
// if (folder.exists()) {
// for (File file : folder.listFiles()) {
// fileCount++;
// logger.info("Pasring file: " + file.getAbsolutePath());
// try {
// BufferedReader br = new BufferedReader(new FileReader(
// file.getAbsolutePath()));
// String line = null;
// while ((line = br.readLine()) != null) {
// logger.trace(line);
// line = line.trim();
//
// Pattern p = Pattern.compile(log_regex);
// Matcher m = p.matcher(line);
// try {
// m.find();
// HTTPLogObject hl = new HTTPLogObject(
// m.group("TIMESTAMP"), m.group("METHOD"),
// m.group("REQUEST"), m.group("BYTES"), m
// .group("USERAGENT").replace("\"",
// ""));
//
// ReplayCache.instance.addToCache(hl);
// } catch (Exception e) {
// logger.error("Unparsable line: " + line + " - "
// + e.getMessage());
// }
// }
// br.close();
// } catch (FileNotFoundException e) {
// cease(logger, e.getMessage());
// } catch (IOException e) {
// cease(logger, e.getMessage());
// }
// }
// t.stop();
// logger.info(fileCount + " files parsed in " + t.getElapsed()
// + " ms");
// } else {
// cease(logger, "Could not find folder " + path);
// }
// }
// }
//
// Path: src/main/java/com/dogeops/cantilever/utils/Configuration.java
// public class Configuration {
// private static void usage(Options options) {
// HelpFormatter formatter = new HelpFormatter();
// formatter.printHelp("Usage options:", options);
// }
//
// public void getConfigFile(String[] args) {
// Options opt = new Options();
// Option op = new Option("config", true,
// "Full path to config file: /opt/cantilever/cantilever.config");
// op.setRequired(true);
// opt.addOption(op);
//
// CommandLineParser parser = new BasicParser();
// CommandLine cmd;
//
// try {
// cmd = parser.parse(opt, args);
// ConfigurationSingleton.instance.readConfigFile(cmd
// .getOptionValue("config"));
//
// } catch (ParseException pe) {
// usage(opt);
// }
// }
// }
//
// Path: src/main/java/com/dogeops/cantilever/utils/ConfigurationSingleton.java
// public enum ConfigurationSingleton {
// instance;
// private static final Logger logger = Logger
// .getLogger(ConfigurationSingleton.class.getName());
//
// private Properties props = new Properties();
//
// private ConfigurationSingleton() {
// }
//
// public void readConfigFile(String config_path) {
// try {
// InputStream input = new FileInputStream(config_path);
// props.load(input);
// input.close();
// } catch (IOException e) {
// cease(logger, e.getMessage());
// }
// }
//
// public String getConfigItem(String val) {
// try {
// if (props.isEmpty()) {
// throw new Exception("Propery file object is empty. "
// + "This likely indicates that the config singleton "
// + "was not properly initialized via readConfigFile.");
// }
// if (props.getProperty(val) == null) {
// throw new Exception("The property " + val
// + " is missing from the configurtion file.");
// }
// return props.getProperty(val);
// } catch (Exception e) {
// cease(logger, e.getMessage());
// return null;
// }
// }
// }
// Path: src/main/java/com/dogeops/cantilever/beam/BeamServer.java
import org.apache.log4j.Logger;
import com.dogeops.cantilever.logreader.HTTPLogReader;
import com.dogeops.cantilever.utils.Configuration;
import com.dogeops.cantilever.utils.ConfigurationSingleton;
package com.dogeops.cantilever.beam;
public class BeamServer {
private static final Logger logger = Logger.getLogger(BeamServer.class
.getName());
public static void main(String[] args) {
Configuration config = new Configuration();
config.getConfigFile(args);
| String pickup_dir = ConfigurationSingleton.instance |
broamski/cantilever | src/main/java/com/dogeops/cantilever/beam/BeamServer.java | // Path: src/main/java/com/dogeops/cantilever/logreader/HTTPLogReader.java
// public class HTTPLogReader {
// private static final Logger logger = Logger.getLogger(HTTPLogReader.class
// .getName());
// private int fileCount = 0;
//
// public void readLogs(String path) {
// logger.info("Reading logs in " + path + "....");
// String log_regex = ConfigurationSingleton.instance
// .getConfigItem("log.convert.regex");
// Timer t = new Timer();
// t.start();
// File folder = new File(path);
// if (folder.exists()) {
// for (File file : folder.listFiles()) {
// fileCount++;
// logger.info("Pasring file: " + file.getAbsolutePath());
// try {
// BufferedReader br = new BufferedReader(new FileReader(
// file.getAbsolutePath()));
// String line = null;
// while ((line = br.readLine()) != null) {
// logger.trace(line);
// line = line.trim();
//
// Pattern p = Pattern.compile(log_regex);
// Matcher m = p.matcher(line);
// try {
// m.find();
// HTTPLogObject hl = new HTTPLogObject(
// m.group("TIMESTAMP"), m.group("METHOD"),
// m.group("REQUEST"), m.group("BYTES"), m
// .group("USERAGENT").replace("\"",
// ""));
//
// ReplayCache.instance.addToCache(hl);
// } catch (Exception e) {
// logger.error("Unparsable line: " + line + " - "
// + e.getMessage());
// }
// }
// br.close();
// } catch (FileNotFoundException e) {
// cease(logger, e.getMessage());
// } catch (IOException e) {
// cease(logger, e.getMessage());
// }
// }
// t.stop();
// logger.info(fileCount + " files parsed in " + t.getElapsed()
// + " ms");
// } else {
// cease(logger, "Could not find folder " + path);
// }
// }
// }
//
// Path: src/main/java/com/dogeops/cantilever/utils/Configuration.java
// public class Configuration {
// private static void usage(Options options) {
// HelpFormatter formatter = new HelpFormatter();
// formatter.printHelp("Usage options:", options);
// }
//
// public void getConfigFile(String[] args) {
// Options opt = new Options();
// Option op = new Option("config", true,
// "Full path to config file: /opt/cantilever/cantilever.config");
// op.setRequired(true);
// opt.addOption(op);
//
// CommandLineParser parser = new BasicParser();
// CommandLine cmd;
//
// try {
// cmd = parser.parse(opt, args);
// ConfigurationSingleton.instance.readConfigFile(cmd
// .getOptionValue("config"));
//
// } catch (ParseException pe) {
// usage(opt);
// }
// }
// }
//
// Path: src/main/java/com/dogeops/cantilever/utils/ConfigurationSingleton.java
// public enum ConfigurationSingleton {
// instance;
// private static final Logger logger = Logger
// .getLogger(ConfigurationSingleton.class.getName());
//
// private Properties props = new Properties();
//
// private ConfigurationSingleton() {
// }
//
// public void readConfigFile(String config_path) {
// try {
// InputStream input = new FileInputStream(config_path);
// props.load(input);
// input.close();
// } catch (IOException e) {
// cease(logger, e.getMessage());
// }
// }
//
// public String getConfigItem(String val) {
// try {
// if (props.isEmpty()) {
// throw new Exception("Propery file object is empty. "
// + "This likely indicates that the config singleton "
// + "was not properly initialized via readConfigFile.");
// }
// if (props.getProperty(val) == null) {
// throw new Exception("The property " + val
// + " is missing from the configurtion file.");
// }
// return props.getProperty(val);
// } catch (Exception e) {
// cease(logger, e.getMessage());
// return null;
// }
// }
// }
| import org.apache.log4j.Logger;
import com.dogeops.cantilever.logreader.HTTPLogReader;
import com.dogeops.cantilever.utils.Configuration;
import com.dogeops.cantilever.utils.ConfigurationSingleton; | package com.dogeops.cantilever.beam;
public class BeamServer {
private static final Logger logger = Logger.getLogger(BeamServer.class
.getName());
public static void main(String[] args) {
Configuration config = new Configuration();
config.getConfigFile(args);
String pickup_dir = ConfigurationSingleton.instance
.getConfigItem("log.pickupdir");
| // Path: src/main/java/com/dogeops/cantilever/logreader/HTTPLogReader.java
// public class HTTPLogReader {
// private static final Logger logger = Logger.getLogger(HTTPLogReader.class
// .getName());
// private int fileCount = 0;
//
// public void readLogs(String path) {
// logger.info("Reading logs in " + path + "....");
// String log_regex = ConfigurationSingleton.instance
// .getConfigItem("log.convert.regex");
// Timer t = new Timer();
// t.start();
// File folder = new File(path);
// if (folder.exists()) {
// for (File file : folder.listFiles()) {
// fileCount++;
// logger.info("Pasring file: " + file.getAbsolutePath());
// try {
// BufferedReader br = new BufferedReader(new FileReader(
// file.getAbsolutePath()));
// String line = null;
// while ((line = br.readLine()) != null) {
// logger.trace(line);
// line = line.trim();
//
// Pattern p = Pattern.compile(log_regex);
// Matcher m = p.matcher(line);
// try {
// m.find();
// HTTPLogObject hl = new HTTPLogObject(
// m.group("TIMESTAMP"), m.group("METHOD"),
// m.group("REQUEST"), m.group("BYTES"), m
// .group("USERAGENT").replace("\"",
// ""));
//
// ReplayCache.instance.addToCache(hl);
// } catch (Exception e) {
// logger.error("Unparsable line: " + line + " - "
// + e.getMessage());
// }
// }
// br.close();
// } catch (FileNotFoundException e) {
// cease(logger, e.getMessage());
// } catch (IOException e) {
// cease(logger, e.getMessage());
// }
// }
// t.stop();
// logger.info(fileCount + " files parsed in " + t.getElapsed()
// + " ms");
// } else {
// cease(logger, "Could not find folder " + path);
// }
// }
// }
//
// Path: src/main/java/com/dogeops/cantilever/utils/Configuration.java
// public class Configuration {
// private static void usage(Options options) {
// HelpFormatter formatter = new HelpFormatter();
// formatter.printHelp("Usage options:", options);
// }
//
// public void getConfigFile(String[] args) {
// Options opt = new Options();
// Option op = new Option("config", true,
// "Full path to config file: /opt/cantilever/cantilever.config");
// op.setRequired(true);
// opt.addOption(op);
//
// CommandLineParser parser = new BasicParser();
// CommandLine cmd;
//
// try {
// cmd = parser.parse(opt, args);
// ConfigurationSingleton.instance.readConfigFile(cmd
// .getOptionValue("config"));
//
// } catch (ParseException pe) {
// usage(opt);
// }
// }
// }
//
// Path: src/main/java/com/dogeops/cantilever/utils/ConfigurationSingleton.java
// public enum ConfigurationSingleton {
// instance;
// private static final Logger logger = Logger
// .getLogger(ConfigurationSingleton.class.getName());
//
// private Properties props = new Properties();
//
// private ConfigurationSingleton() {
// }
//
// public void readConfigFile(String config_path) {
// try {
// InputStream input = new FileInputStream(config_path);
// props.load(input);
// input.close();
// } catch (IOException e) {
// cease(logger, e.getMessage());
// }
// }
//
// public String getConfigItem(String val) {
// try {
// if (props.isEmpty()) {
// throw new Exception("Propery file object is empty. "
// + "This likely indicates that the config singleton "
// + "was not properly initialized via readConfigFile.");
// }
// if (props.getProperty(val) == null) {
// throw new Exception("The property " + val
// + " is missing from the configurtion file.");
// }
// return props.getProperty(val);
// } catch (Exception e) {
// cease(logger, e.getMessage());
// return null;
// }
// }
// }
// Path: src/main/java/com/dogeops/cantilever/beam/BeamServer.java
import org.apache.log4j.Logger;
import com.dogeops.cantilever.logreader.HTTPLogReader;
import com.dogeops.cantilever.utils.Configuration;
import com.dogeops.cantilever.utils.ConfigurationSingleton;
package com.dogeops.cantilever.beam;
public class BeamServer {
private static final Logger logger = Logger.getLogger(BeamServer.class
.getName());
public static void main(String[] args) {
Configuration config = new Configuration();
config.getConfigFile(args);
String pickup_dir = ConfigurationSingleton.instance
.getConfigItem("log.pickupdir");
| HTTPLogReader log_reader = new HTTPLogReader(); |
broamski/cantilever | src/main/java/com/dogeops/cantilever/truss/client/apache/HTTPLogMessageListener.java | // Path: src/main/java/com/dogeops/cantilever/logreader/HTTPLogObject.java
// public class HTTPLogObject {
// private String timestamp, method, request, bytes, useragent;
// private String requesting_resver, request_payload, url_request;
// private String[] headers;
//
// public HTTPLogObject(String timestamp, String method, String request,
// String bytes, String useragent) {
// this.timestamp = timestamp;
// this.method = method;
// this.request = request;
// this.bytes = bytes;
// this.useragent = useragent;
//
// buildRequestPayload();
// }
//
// private void buildHeaderArray() {
// String header_input = ConfigurationSingleton.instance
// .getConfigItem("replay.request.headers");
// String header_delimiter = ConfigurationSingleton.instance
// .getConfigItem("replay.request.headers.delimiter");
// this.headers = header_input.split(header_delimiter);
// }
//
// private void buildRequestPayload() {
// this.requesting_resver = ConfigurationSingleton.instance
// .getConfigItem("replay.request.servername");
// buildHeaderArray();
// buildURLRequest();
// Gson gson = new Gson();
// this.request_payload = gson.toJson(this);
// }
//
// private void buildURLRequest() {
// String http_port = ConfigurationSingleton.instance
// .getConfigItem("replay.request.port");
// String http_protocol = ConfigurationSingleton.instance.getConfigItem(
// "replay.request.protocol").toLowerCase();
//
// if (http_port.equals("80") || http_port.equals("443")) {
// http_port = "";
// } else {
// http_port = ":" + http_port;
// }
// this.url_request = http_protocol + "://" + this.requesting_resver
// + this.request + http_port;
// }
//
// public String getTimestamp() {
// return this.timestamp;
// }
//
// public String getPayload() {
// return this.request_payload;
// }
//
// public String getRequest() {
// return this.request;
// }
//
// public String[] getHeaders() {
// return this.headers;
// }
//
// public String getServerName() {
// return this.requesting_resver;
// }
//
// public String getMethod() {
// return this.method;
// }
//
// public String getUseragent() {
// return this.useragent;
// }
//
// public String getURLRequest() {
// return this.url_request;
// }
// }
//
// Path: src/main/java/com/dogeops/cantilever/utils/ConfigurationSingleton.java
// public enum ConfigurationSingleton {
// instance;
// private static final Logger logger = Logger
// .getLogger(ConfigurationSingleton.class.getName());
//
// private Properties props = new Properties();
//
// private ConfigurationSingleton() {
// }
//
// public void readConfigFile(String config_path) {
// try {
// InputStream input = new FileInputStream(config_path);
// props.load(input);
// input.close();
// } catch (IOException e) {
// cease(logger, e.getMessage());
// }
// }
//
// public String getConfigItem(String val) {
// try {
// if (props.isEmpty()) {
// throw new Exception("Propery file object is empty. "
// + "This likely indicates that the config singleton "
// + "was not properly initialized via readConfigFile.");
// }
// if (props.getProperty(val) == null) {
// throw new Exception("The property " + val
// + " is missing from the configurtion file.");
// }
// return props.getProperty(val);
// } catch (Exception e) {
// cease(logger, e.getMessage());
// return null;
// }
// }
// }
| import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.TextMessage;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
import org.apache.log4j.Logger;
import com.dogeops.cantilever.logreader.HTTPLogObject;
import com.dogeops.cantilever.utils.ConfigurationSingleton;
import com.google.gson.Gson; | package com.dogeops.cantilever.truss.client.apache;
public class HTTPLogMessageListener implements MessageListener {
private static final Logger logger = Logger.getLogger(HTTPLogMessageListener.class
.getName());
public PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager();
public CloseableHttpClient httpclient = HttpClients.custom()
.setConnectionManager(cm)
.build();
public HTTPLogMessageListener() { | // Path: src/main/java/com/dogeops/cantilever/logreader/HTTPLogObject.java
// public class HTTPLogObject {
// private String timestamp, method, request, bytes, useragent;
// private String requesting_resver, request_payload, url_request;
// private String[] headers;
//
// public HTTPLogObject(String timestamp, String method, String request,
// String bytes, String useragent) {
// this.timestamp = timestamp;
// this.method = method;
// this.request = request;
// this.bytes = bytes;
// this.useragent = useragent;
//
// buildRequestPayload();
// }
//
// private void buildHeaderArray() {
// String header_input = ConfigurationSingleton.instance
// .getConfigItem("replay.request.headers");
// String header_delimiter = ConfigurationSingleton.instance
// .getConfigItem("replay.request.headers.delimiter");
// this.headers = header_input.split(header_delimiter);
// }
//
// private void buildRequestPayload() {
// this.requesting_resver = ConfigurationSingleton.instance
// .getConfigItem("replay.request.servername");
// buildHeaderArray();
// buildURLRequest();
// Gson gson = new Gson();
// this.request_payload = gson.toJson(this);
// }
//
// private void buildURLRequest() {
// String http_port = ConfigurationSingleton.instance
// .getConfigItem("replay.request.port");
// String http_protocol = ConfigurationSingleton.instance.getConfigItem(
// "replay.request.protocol").toLowerCase();
//
// if (http_port.equals("80") || http_port.equals("443")) {
// http_port = "";
// } else {
// http_port = ":" + http_port;
// }
// this.url_request = http_protocol + "://" + this.requesting_resver
// + this.request + http_port;
// }
//
// public String getTimestamp() {
// return this.timestamp;
// }
//
// public String getPayload() {
// return this.request_payload;
// }
//
// public String getRequest() {
// return this.request;
// }
//
// public String[] getHeaders() {
// return this.headers;
// }
//
// public String getServerName() {
// return this.requesting_resver;
// }
//
// public String getMethod() {
// return this.method;
// }
//
// public String getUseragent() {
// return this.useragent;
// }
//
// public String getURLRequest() {
// return this.url_request;
// }
// }
//
// Path: src/main/java/com/dogeops/cantilever/utils/ConfigurationSingleton.java
// public enum ConfigurationSingleton {
// instance;
// private static final Logger logger = Logger
// .getLogger(ConfigurationSingleton.class.getName());
//
// private Properties props = new Properties();
//
// private ConfigurationSingleton() {
// }
//
// public void readConfigFile(String config_path) {
// try {
// InputStream input = new FileInputStream(config_path);
// props.load(input);
// input.close();
// } catch (IOException e) {
// cease(logger, e.getMessage());
// }
// }
//
// public String getConfigItem(String val) {
// try {
// if (props.isEmpty()) {
// throw new Exception("Propery file object is empty. "
// + "This likely indicates that the config singleton "
// + "was not properly initialized via readConfigFile.");
// }
// if (props.getProperty(val) == null) {
// throw new Exception("The property " + val
// + " is missing from the configurtion file.");
// }
// return props.getProperty(val);
// } catch (Exception e) {
// cease(logger, e.getMessage());
// return null;
// }
// }
// }
// Path: src/main/java/com/dogeops/cantilever/truss/client/apache/HTTPLogMessageListener.java
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.TextMessage;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
import org.apache.log4j.Logger;
import com.dogeops.cantilever.logreader.HTTPLogObject;
import com.dogeops.cantilever.utils.ConfigurationSingleton;
import com.google.gson.Gson;
package com.dogeops.cantilever.truss.client.apache;
public class HTTPLogMessageListener implements MessageListener {
private static final Logger logger = Logger.getLogger(HTTPLogMessageListener.class
.getName());
public PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager();
public CloseableHttpClient httpclient = HttpClients.custom()
.setConnectionManager(cm)
.build();
public HTTPLogMessageListener() { | String str_truss_threads = ConfigurationSingleton.instance.getConfigItem("truss.threads"); |
broamski/cantilever | src/main/java/com/dogeops/cantilever/truss/client/apache/HTTPLogMessageListener.java | // Path: src/main/java/com/dogeops/cantilever/logreader/HTTPLogObject.java
// public class HTTPLogObject {
// private String timestamp, method, request, bytes, useragent;
// private String requesting_resver, request_payload, url_request;
// private String[] headers;
//
// public HTTPLogObject(String timestamp, String method, String request,
// String bytes, String useragent) {
// this.timestamp = timestamp;
// this.method = method;
// this.request = request;
// this.bytes = bytes;
// this.useragent = useragent;
//
// buildRequestPayload();
// }
//
// private void buildHeaderArray() {
// String header_input = ConfigurationSingleton.instance
// .getConfigItem("replay.request.headers");
// String header_delimiter = ConfigurationSingleton.instance
// .getConfigItem("replay.request.headers.delimiter");
// this.headers = header_input.split(header_delimiter);
// }
//
// private void buildRequestPayload() {
// this.requesting_resver = ConfigurationSingleton.instance
// .getConfigItem("replay.request.servername");
// buildHeaderArray();
// buildURLRequest();
// Gson gson = new Gson();
// this.request_payload = gson.toJson(this);
// }
//
// private void buildURLRequest() {
// String http_port = ConfigurationSingleton.instance
// .getConfigItem("replay.request.port");
// String http_protocol = ConfigurationSingleton.instance.getConfigItem(
// "replay.request.protocol").toLowerCase();
//
// if (http_port.equals("80") || http_port.equals("443")) {
// http_port = "";
// } else {
// http_port = ":" + http_port;
// }
// this.url_request = http_protocol + "://" + this.requesting_resver
// + this.request + http_port;
// }
//
// public String getTimestamp() {
// return this.timestamp;
// }
//
// public String getPayload() {
// return this.request_payload;
// }
//
// public String getRequest() {
// return this.request;
// }
//
// public String[] getHeaders() {
// return this.headers;
// }
//
// public String getServerName() {
// return this.requesting_resver;
// }
//
// public String getMethod() {
// return this.method;
// }
//
// public String getUseragent() {
// return this.useragent;
// }
//
// public String getURLRequest() {
// return this.url_request;
// }
// }
//
// Path: src/main/java/com/dogeops/cantilever/utils/ConfigurationSingleton.java
// public enum ConfigurationSingleton {
// instance;
// private static final Logger logger = Logger
// .getLogger(ConfigurationSingleton.class.getName());
//
// private Properties props = new Properties();
//
// private ConfigurationSingleton() {
// }
//
// public void readConfigFile(String config_path) {
// try {
// InputStream input = new FileInputStream(config_path);
// props.load(input);
// input.close();
// } catch (IOException e) {
// cease(logger, e.getMessage());
// }
// }
//
// public String getConfigItem(String val) {
// try {
// if (props.isEmpty()) {
// throw new Exception("Propery file object is empty. "
// + "This likely indicates that the config singleton "
// + "was not properly initialized via readConfigFile.");
// }
// if (props.getProperty(val) == null) {
// throw new Exception("The property " + val
// + " is missing from the configurtion file.");
// }
// return props.getProperty(val);
// } catch (Exception e) {
// cease(logger, e.getMessage());
// return null;
// }
// }
// }
| import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.TextMessage;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
import org.apache.log4j.Logger;
import com.dogeops.cantilever.logreader.HTTPLogObject;
import com.dogeops.cantilever.utils.ConfigurationSingleton;
import com.google.gson.Gson; |
public CloseableHttpClient httpclient = HttpClients.custom()
.setConnectionManager(cm)
.build();
public HTTPLogMessageListener() {
String str_truss_threads = ConfigurationSingleton.instance.getConfigItem("truss.threads");
int truss_threads = Integer.parseInt(str_truss_threads);
cm.setMaxTotal(truss_threads);
}
public enum AcceptableMethods {
GET, POST, NAN;
public static AcceptableMethods getValue(String str) {
try {
return valueOf(str);
} catch (Exception e) {
logger.error(e.getMessage());
return NAN;
}
}
}
public void onMessage(Message message) {
if (message instanceof TextMessage) {
TextMessage textMessage = (TextMessage) message;
String text;
try {
text = textMessage.getText();
Gson gson = new Gson(); | // Path: src/main/java/com/dogeops/cantilever/logreader/HTTPLogObject.java
// public class HTTPLogObject {
// private String timestamp, method, request, bytes, useragent;
// private String requesting_resver, request_payload, url_request;
// private String[] headers;
//
// public HTTPLogObject(String timestamp, String method, String request,
// String bytes, String useragent) {
// this.timestamp = timestamp;
// this.method = method;
// this.request = request;
// this.bytes = bytes;
// this.useragent = useragent;
//
// buildRequestPayload();
// }
//
// private void buildHeaderArray() {
// String header_input = ConfigurationSingleton.instance
// .getConfigItem("replay.request.headers");
// String header_delimiter = ConfigurationSingleton.instance
// .getConfigItem("replay.request.headers.delimiter");
// this.headers = header_input.split(header_delimiter);
// }
//
// private void buildRequestPayload() {
// this.requesting_resver = ConfigurationSingleton.instance
// .getConfigItem("replay.request.servername");
// buildHeaderArray();
// buildURLRequest();
// Gson gson = new Gson();
// this.request_payload = gson.toJson(this);
// }
//
// private void buildURLRequest() {
// String http_port = ConfigurationSingleton.instance
// .getConfigItem("replay.request.port");
// String http_protocol = ConfigurationSingleton.instance.getConfigItem(
// "replay.request.protocol").toLowerCase();
//
// if (http_port.equals("80") || http_port.equals("443")) {
// http_port = "";
// } else {
// http_port = ":" + http_port;
// }
// this.url_request = http_protocol + "://" + this.requesting_resver
// + this.request + http_port;
// }
//
// public String getTimestamp() {
// return this.timestamp;
// }
//
// public String getPayload() {
// return this.request_payload;
// }
//
// public String getRequest() {
// return this.request;
// }
//
// public String[] getHeaders() {
// return this.headers;
// }
//
// public String getServerName() {
// return this.requesting_resver;
// }
//
// public String getMethod() {
// return this.method;
// }
//
// public String getUseragent() {
// return this.useragent;
// }
//
// public String getURLRequest() {
// return this.url_request;
// }
// }
//
// Path: src/main/java/com/dogeops/cantilever/utils/ConfigurationSingleton.java
// public enum ConfigurationSingleton {
// instance;
// private static final Logger logger = Logger
// .getLogger(ConfigurationSingleton.class.getName());
//
// private Properties props = new Properties();
//
// private ConfigurationSingleton() {
// }
//
// public void readConfigFile(String config_path) {
// try {
// InputStream input = new FileInputStream(config_path);
// props.load(input);
// input.close();
// } catch (IOException e) {
// cease(logger, e.getMessage());
// }
// }
//
// public String getConfigItem(String val) {
// try {
// if (props.isEmpty()) {
// throw new Exception("Propery file object is empty. "
// + "This likely indicates that the config singleton "
// + "was not properly initialized via readConfigFile.");
// }
// if (props.getProperty(val) == null) {
// throw new Exception("The property " + val
// + " is missing from the configurtion file.");
// }
// return props.getProperty(val);
// } catch (Exception e) {
// cease(logger, e.getMessage());
// return null;
// }
// }
// }
// Path: src/main/java/com/dogeops/cantilever/truss/client/apache/HTTPLogMessageListener.java
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.TextMessage;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
import org.apache.log4j.Logger;
import com.dogeops.cantilever.logreader.HTTPLogObject;
import com.dogeops.cantilever.utils.ConfigurationSingleton;
import com.google.gson.Gson;
public CloseableHttpClient httpclient = HttpClients.custom()
.setConnectionManager(cm)
.build();
public HTTPLogMessageListener() {
String str_truss_threads = ConfigurationSingleton.instance.getConfigItem("truss.threads");
int truss_threads = Integer.parseInt(str_truss_threads);
cm.setMaxTotal(truss_threads);
}
public enum AcceptableMethods {
GET, POST, NAN;
public static AcceptableMethods getValue(String str) {
try {
return valueOf(str);
} catch (Exception e) {
logger.error(e.getMessage());
return NAN;
}
}
}
public void onMessage(Message message) {
if (message instanceof TextMessage) {
TextMessage textMessage = (TextMessage) message;
String text;
try {
text = textMessage.getText();
Gson gson = new Gson(); | HTTPLogObject http_log = gson.fromJson(text, HTTPLogObject.class); |
broamski/cantilever | src/main/java/com/dogeops/cantilever/truss/client/ning/HTTPAsyncGet.java | // Path: src/main/java/com/dogeops/cantilever/logreader/HTTPLogObject.java
// public class HTTPLogObject {
// private String timestamp, method, request, bytes, useragent;
// private String requesting_resver, request_payload, url_request;
// private String[] headers;
//
// public HTTPLogObject(String timestamp, String method, String request,
// String bytes, String useragent) {
// this.timestamp = timestamp;
// this.method = method;
// this.request = request;
// this.bytes = bytes;
// this.useragent = useragent;
//
// buildRequestPayload();
// }
//
// private void buildHeaderArray() {
// String header_input = ConfigurationSingleton.instance
// .getConfigItem("replay.request.headers");
// String header_delimiter = ConfigurationSingleton.instance
// .getConfigItem("replay.request.headers.delimiter");
// this.headers = header_input.split(header_delimiter);
// }
//
// private void buildRequestPayload() {
// this.requesting_resver = ConfigurationSingleton.instance
// .getConfigItem("replay.request.servername");
// buildHeaderArray();
// buildURLRequest();
// Gson gson = new Gson();
// this.request_payload = gson.toJson(this);
// }
//
// private void buildURLRequest() {
// String http_port = ConfigurationSingleton.instance
// .getConfigItem("replay.request.port");
// String http_protocol = ConfigurationSingleton.instance.getConfigItem(
// "replay.request.protocol").toLowerCase();
//
// if (http_port.equals("80") || http_port.equals("443")) {
// http_port = "";
// } else {
// http_port = ":" + http_port;
// }
// this.url_request = http_protocol + "://" + this.requesting_resver
// + this.request + http_port;
// }
//
// public String getTimestamp() {
// return this.timestamp;
// }
//
// public String getPayload() {
// return this.request_payload;
// }
//
// public String getRequest() {
// return this.request;
// }
//
// public String[] getHeaders() {
// return this.headers;
// }
//
// public String getServerName() {
// return this.requesting_resver;
// }
//
// public String getMethod() {
// return this.method;
// }
//
// public String getUseragent() {
// return this.useragent;
// }
//
// public String getURLRequest() {
// return this.url_request;
// }
// }
//
// Path: src/main/java/com/dogeops/cantilever/utils/ConfigurationSingleton.java
// public enum ConfigurationSingleton {
// instance;
// private static final Logger logger = Logger
// .getLogger(ConfigurationSingleton.class.getName());
//
// private Properties props = new Properties();
//
// private ConfigurationSingleton() {
// }
//
// public void readConfigFile(String config_path) {
// try {
// InputStream input = new FileInputStream(config_path);
// props.load(input);
// input.close();
// } catch (IOException e) {
// cease(logger, e.getMessage());
// }
// }
//
// public String getConfigItem(String val) {
// try {
// if (props.isEmpty()) {
// throw new Exception("Propery file object is empty. "
// + "This likely indicates that the config singleton "
// + "was not properly initialized via readConfigFile.");
// }
// if (props.getProperty(val) == null) {
// throw new Exception("The property " + val
// + " is missing from the configurtion file.");
// }
// return props.getProperty(val);
// } catch (Exception e) {
// cease(logger, e.getMessage());
// return null;
// }
// }
// }
| import java.io.IOException;
import org.apache.log4j.Logger;
import com.dogeops.cantilever.logreader.HTTPLogObject;
import com.dogeops.cantilever.utils.ConfigurationSingleton;
import com.ning.http.client.AsyncHandler;
import com.ning.http.client.AsyncHttpClient;
import com.ning.http.client.HttpResponseBodyPart;
import com.ning.http.client.HttpResponseHeaders;
import com.ning.http.client.HttpResponseStatus;
import com.ning.http.client.Request;
import com.ning.http.client.RequestBuilder;
import com.ning.http.client.Response; | package com.dogeops.cantilever.truss.client.ning;
public class HTTPAsyncGet {
private static final Logger logger = Logger.getLogger(HTTPAsyncGet.class
.getName());
private String url_request;
| // Path: src/main/java/com/dogeops/cantilever/logreader/HTTPLogObject.java
// public class HTTPLogObject {
// private String timestamp, method, request, bytes, useragent;
// private String requesting_resver, request_payload, url_request;
// private String[] headers;
//
// public HTTPLogObject(String timestamp, String method, String request,
// String bytes, String useragent) {
// this.timestamp = timestamp;
// this.method = method;
// this.request = request;
// this.bytes = bytes;
// this.useragent = useragent;
//
// buildRequestPayload();
// }
//
// private void buildHeaderArray() {
// String header_input = ConfigurationSingleton.instance
// .getConfigItem("replay.request.headers");
// String header_delimiter = ConfigurationSingleton.instance
// .getConfigItem("replay.request.headers.delimiter");
// this.headers = header_input.split(header_delimiter);
// }
//
// private void buildRequestPayload() {
// this.requesting_resver = ConfigurationSingleton.instance
// .getConfigItem("replay.request.servername");
// buildHeaderArray();
// buildURLRequest();
// Gson gson = new Gson();
// this.request_payload = gson.toJson(this);
// }
//
// private void buildURLRequest() {
// String http_port = ConfigurationSingleton.instance
// .getConfigItem("replay.request.port");
// String http_protocol = ConfigurationSingleton.instance.getConfigItem(
// "replay.request.protocol").toLowerCase();
//
// if (http_port.equals("80") || http_port.equals("443")) {
// http_port = "";
// } else {
// http_port = ":" + http_port;
// }
// this.url_request = http_protocol + "://" + this.requesting_resver
// + this.request + http_port;
// }
//
// public String getTimestamp() {
// return this.timestamp;
// }
//
// public String getPayload() {
// return this.request_payload;
// }
//
// public String getRequest() {
// return this.request;
// }
//
// public String[] getHeaders() {
// return this.headers;
// }
//
// public String getServerName() {
// return this.requesting_resver;
// }
//
// public String getMethod() {
// return this.method;
// }
//
// public String getUseragent() {
// return this.useragent;
// }
//
// public String getURLRequest() {
// return this.url_request;
// }
// }
//
// Path: src/main/java/com/dogeops/cantilever/utils/ConfigurationSingleton.java
// public enum ConfigurationSingleton {
// instance;
// private static final Logger logger = Logger
// .getLogger(ConfigurationSingleton.class.getName());
//
// private Properties props = new Properties();
//
// private ConfigurationSingleton() {
// }
//
// public void readConfigFile(String config_path) {
// try {
// InputStream input = new FileInputStream(config_path);
// props.load(input);
// input.close();
// } catch (IOException e) {
// cease(logger, e.getMessage());
// }
// }
//
// public String getConfigItem(String val) {
// try {
// if (props.isEmpty()) {
// throw new Exception("Propery file object is empty. "
// + "This likely indicates that the config singleton "
// + "was not properly initialized via readConfigFile.");
// }
// if (props.getProperty(val) == null) {
// throw new Exception("The property " + val
// + " is missing from the configurtion file.");
// }
// return props.getProperty(val);
// } catch (Exception e) {
// cease(logger, e.getMessage());
// return null;
// }
// }
// }
// Path: src/main/java/com/dogeops/cantilever/truss/client/ning/HTTPAsyncGet.java
import java.io.IOException;
import org.apache.log4j.Logger;
import com.dogeops.cantilever.logreader.HTTPLogObject;
import com.dogeops.cantilever.utils.ConfigurationSingleton;
import com.ning.http.client.AsyncHandler;
import com.ning.http.client.AsyncHttpClient;
import com.ning.http.client.HttpResponseBodyPart;
import com.ning.http.client.HttpResponseHeaders;
import com.ning.http.client.HttpResponseStatus;
import com.ning.http.client.Request;
import com.ning.http.client.RequestBuilder;
import com.ning.http.client.Response;
package com.dogeops.cantilever.truss.client.ning;
public class HTTPAsyncGet {
private static final Logger logger = Logger.getLogger(HTTPAsyncGet.class
.getName());
private String url_request;
| public HTTPAsyncGet(AsyncHttpClient client, HTTPLogObject http_log) { |
broamski/cantilever | src/main/java/com/dogeops/cantilever/messagequeue/ActiveMQ.java | // Path: src/main/java/com/dogeops/cantilever/truss/client/ning/HTTPAsyncLogMessageListener.java
// public class HTTPAsyncLogMessageListener implements MessageListener {
// private static final Logger logger = Logger.getLogger(HTTPAsyncLogMessageListener.class
// .getName());
//
// private Builder builder;
// private AsyncHttpClient client;
//
// public HTTPAsyncLogMessageListener() {
// builder = new AsyncHttpClientConfig.Builder();
// builder.setCompressionEnabled(true)
// .setMaximumConnectionsPerHost(100)
// .setRequestTimeoutInMs(15000)
// .build();
//
// client = new AsyncHttpClient(builder.build());
// }
//
// public enum AcceptableMethods {
// GET, POST, NAN;
// public static AcceptableMethods getValue(String str) {
// try {
// return valueOf(str);
// } catch (Exception e) {
// logger.error(e.getMessage());
// return NAN;
// }
// }
// }
//
// public void onMessage(Message message) {
// if (message instanceof TextMessage) {
// TextMessage textMessage = (TextMessage) message;
// String text;
// try {
// text = textMessage.getText();
// Gson gson = new Gson();
// HTTPLogObject http_log = gson.fromJson(text, HTTPLogObject.class);
//
// switch (AcceptableMethods.getValue(http_log.getMethod()))
// {
// case GET:
// new HTTPAsyncGet(client, http_log);
// break;
// case POST:
// new HTTPAsyncPost(client, http_log);
// break;
// default:
// logger.error("Unsupport HTTP Method: " + http_log.getMethod());
// }
//
// logger.trace("Received: " + text);
// } catch (JMSException e) {
// logger.error(e.getMessage());
// }
// } else {
// logger.error("Received an erroneous message: " + message);
// }
//
// }
//
// }
//
// Path: src/main/java/com/dogeops/cantilever/utils/Util.java
// public class Util {
// public static void cease(Logger logger, String message) {
// logger.error(message);
// System.exit(1);
// }
// }
| import javax.jms.Connection;
import javax.jms.DeliveryMode;
import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.MessageConsumer;
import javax.jms.MessageProducer;
import javax.jms.Session;
import javax.jms.TextMessage;
import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.log4j.Logger;
import com.dogeops.cantilever.truss.client.ning.HTTPAsyncLogMessageListener;
import com.dogeops.cantilever.utils.Util; | package com.dogeops.cantilever.messagequeue;
public class ActiveMQ implements MessageQueueInterface {
private static final Logger logger = Logger.getLogger(ActiveMQ.class
.getName());
public ActiveMQConnectionFactory connectionFactory;
public Connection connection;
public Session session;
public Destination destination;
public MessageProducer producer;
public void connect(String hostname, String queue_name) {
try {
logger.debug("Connecting to ActiveMQ Broker: " + hostname + " - Queue: " + queue_name);
connectionFactory = new ActiveMQConnectionFactory(hostname);
connection = connectionFactory.createConnection();
connection.start();
session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
destination = session.createQueue(queue_name);
} catch (JMSException e) { | // Path: src/main/java/com/dogeops/cantilever/truss/client/ning/HTTPAsyncLogMessageListener.java
// public class HTTPAsyncLogMessageListener implements MessageListener {
// private static final Logger logger = Logger.getLogger(HTTPAsyncLogMessageListener.class
// .getName());
//
// private Builder builder;
// private AsyncHttpClient client;
//
// public HTTPAsyncLogMessageListener() {
// builder = new AsyncHttpClientConfig.Builder();
// builder.setCompressionEnabled(true)
// .setMaximumConnectionsPerHost(100)
// .setRequestTimeoutInMs(15000)
// .build();
//
// client = new AsyncHttpClient(builder.build());
// }
//
// public enum AcceptableMethods {
// GET, POST, NAN;
// public static AcceptableMethods getValue(String str) {
// try {
// return valueOf(str);
// } catch (Exception e) {
// logger.error(e.getMessage());
// return NAN;
// }
// }
// }
//
// public void onMessage(Message message) {
// if (message instanceof TextMessage) {
// TextMessage textMessage = (TextMessage) message;
// String text;
// try {
// text = textMessage.getText();
// Gson gson = new Gson();
// HTTPLogObject http_log = gson.fromJson(text, HTTPLogObject.class);
//
// switch (AcceptableMethods.getValue(http_log.getMethod()))
// {
// case GET:
// new HTTPAsyncGet(client, http_log);
// break;
// case POST:
// new HTTPAsyncPost(client, http_log);
// break;
// default:
// logger.error("Unsupport HTTP Method: " + http_log.getMethod());
// }
//
// logger.trace("Received: " + text);
// } catch (JMSException e) {
// logger.error(e.getMessage());
// }
// } else {
// logger.error("Received an erroneous message: " + message);
// }
//
// }
//
// }
//
// Path: src/main/java/com/dogeops/cantilever/utils/Util.java
// public class Util {
// public static void cease(Logger logger, String message) {
// logger.error(message);
// System.exit(1);
// }
// }
// Path: src/main/java/com/dogeops/cantilever/messagequeue/ActiveMQ.java
import javax.jms.Connection;
import javax.jms.DeliveryMode;
import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.MessageConsumer;
import javax.jms.MessageProducer;
import javax.jms.Session;
import javax.jms.TextMessage;
import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.log4j.Logger;
import com.dogeops.cantilever.truss.client.ning.HTTPAsyncLogMessageListener;
import com.dogeops.cantilever.utils.Util;
package com.dogeops.cantilever.messagequeue;
public class ActiveMQ implements MessageQueueInterface {
private static final Logger logger = Logger.getLogger(ActiveMQ.class
.getName());
public ActiveMQConnectionFactory connectionFactory;
public Connection connection;
public Session session;
public Destination destination;
public MessageProducer producer;
public void connect(String hostname, String queue_name) {
try {
logger.debug("Connecting to ActiveMQ Broker: " + hostname + " - Queue: " + queue_name);
connectionFactory = new ActiveMQConnectionFactory(hostname);
connection = connectionFactory.createConnection();
connection.start();
session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
destination = session.createQueue(queue_name);
} catch (JMSException e) { | Util.cease(logger, e.getMessage()); |
broamski/cantilever | src/main/java/com/dogeops/cantilever/messagequeue/ActiveMQ.java | // Path: src/main/java/com/dogeops/cantilever/truss/client/ning/HTTPAsyncLogMessageListener.java
// public class HTTPAsyncLogMessageListener implements MessageListener {
// private static final Logger logger = Logger.getLogger(HTTPAsyncLogMessageListener.class
// .getName());
//
// private Builder builder;
// private AsyncHttpClient client;
//
// public HTTPAsyncLogMessageListener() {
// builder = new AsyncHttpClientConfig.Builder();
// builder.setCompressionEnabled(true)
// .setMaximumConnectionsPerHost(100)
// .setRequestTimeoutInMs(15000)
// .build();
//
// client = new AsyncHttpClient(builder.build());
// }
//
// public enum AcceptableMethods {
// GET, POST, NAN;
// public static AcceptableMethods getValue(String str) {
// try {
// return valueOf(str);
// } catch (Exception e) {
// logger.error(e.getMessage());
// return NAN;
// }
// }
// }
//
// public void onMessage(Message message) {
// if (message instanceof TextMessage) {
// TextMessage textMessage = (TextMessage) message;
// String text;
// try {
// text = textMessage.getText();
// Gson gson = new Gson();
// HTTPLogObject http_log = gson.fromJson(text, HTTPLogObject.class);
//
// switch (AcceptableMethods.getValue(http_log.getMethod()))
// {
// case GET:
// new HTTPAsyncGet(client, http_log);
// break;
// case POST:
// new HTTPAsyncPost(client, http_log);
// break;
// default:
// logger.error("Unsupport HTTP Method: " + http_log.getMethod());
// }
//
// logger.trace("Received: " + text);
// } catch (JMSException e) {
// logger.error(e.getMessage());
// }
// } else {
// logger.error("Received an erroneous message: " + message);
// }
//
// }
//
// }
//
// Path: src/main/java/com/dogeops/cantilever/utils/Util.java
// public class Util {
// public static void cease(Logger logger, String message) {
// logger.error(message);
// System.exit(1);
// }
// }
| import javax.jms.Connection;
import javax.jms.DeliveryMode;
import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.MessageConsumer;
import javax.jms.MessageProducer;
import javax.jms.Session;
import javax.jms.TextMessage;
import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.log4j.Logger;
import com.dogeops.cantilever.truss.client.ning.HTTPAsyncLogMessageListener;
import com.dogeops.cantilever.utils.Util; |
public void disconnect() {
try {
// We need to get some more details in this log message...
logger.debug("Disconnecting from ActiveMQ Broker");
connection.close();
} catch (JMSException e) {
Util.cease(logger, e.getMessage());
}
}
public void deliver(String payload) {
try {
// We need to get some more details in this log message...
logger.debug("Writing message to queue.");
// Create a MessageProducer from the Session to the Topic or Queue
MessageProducer producer = session.createProducer(destination);
producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
// Create a message
TextMessage message;
message = session.createTextMessage(payload);
// Tell the producer to send the message
producer.send(message);
} catch (JMSException e) {
Util.cease(logger, e.getMessage());
}
}
| // Path: src/main/java/com/dogeops/cantilever/truss/client/ning/HTTPAsyncLogMessageListener.java
// public class HTTPAsyncLogMessageListener implements MessageListener {
// private static final Logger logger = Logger.getLogger(HTTPAsyncLogMessageListener.class
// .getName());
//
// private Builder builder;
// private AsyncHttpClient client;
//
// public HTTPAsyncLogMessageListener() {
// builder = new AsyncHttpClientConfig.Builder();
// builder.setCompressionEnabled(true)
// .setMaximumConnectionsPerHost(100)
// .setRequestTimeoutInMs(15000)
// .build();
//
// client = new AsyncHttpClient(builder.build());
// }
//
// public enum AcceptableMethods {
// GET, POST, NAN;
// public static AcceptableMethods getValue(String str) {
// try {
// return valueOf(str);
// } catch (Exception e) {
// logger.error(e.getMessage());
// return NAN;
// }
// }
// }
//
// public void onMessage(Message message) {
// if (message instanceof TextMessage) {
// TextMessage textMessage = (TextMessage) message;
// String text;
// try {
// text = textMessage.getText();
// Gson gson = new Gson();
// HTTPLogObject http_log = gson.fromJson(text, HTTPLogObject.class);
//
// switch (AcceptableMethods.getValue(http_log.getMethod()))
// {
// case GET:
// new HTTPAsyncGet(client, http_log);
// break;
// case POST:
// new HTTPAsyncPost(client, http_log);
// break;
// default:
// logger.error("Unsupport HTTP Method: " + http_log.getMethod());
// }
//
// logger.trace("Received: " + text);
// } catch (JMSException e) {
// logger.error(e.getMessage());
// }
// } else {
// logger.error("Received an erroneous message: " + message);
// }
//
// }
//
// }
//
// Path: src/main/java/com/dogeops/cantilever/utils/Util.java
// public class Util {
// public static void cease(Logger logger, String message) {
// logger.error(message);
// System.exit(1);
// }
// }
// Path: src/main/java/com/dogeops/cantilever/messagequeue/ActiveMQ.java
import javax.jms.Connection;
import javax.jms.DeliveryMode;
import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.MessageConsumer;
import javax.jms.MessageProducer;
import javax.jms.Session;
import javax.jms.TextMessage;
import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.log4j.Logger;
import com.dogeops.cantilever.truss.client.ning.HTTPAsyncLogMessageListener;
import com.dogeops.cantilever.utils.Util;
public void disconnect() {
try {
// We need to get some more details in this log message...
logger.debug("Disconnecting from ActiveMQ Broker");
connection.close();
} catch (JMSException e) {
Util.cease(logger, e.getMessage());
}
}
public void deliver(String payload) {
try {
// We need to get some more details in this log message...
logger.debug("Writing message to queue.");
// Create a MessageProducer from the Session to the Topic or Queue
MessageProducer producer = session.createProducer(destination);
producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
// Create a message
TextMessage message;
message = session.createTextMessage(payload);
// Tell the producer to send the message
producer.send(message);
} catch (JMSException e) {
Util.cease(logger, e.getMessage());
}
}
| public void consume(HTTPAsyncLogMessageListener ml) { |
broamski/cantilever | src/main/java/com/dogeops/cantilever/truss/POSTHeaderCacheBuilder.java | // Path: src/main/java/com/dogeops/cantilever/utils/ConfigurationSingleton.java
// public enum ConfigurationSingleton {
// instance;
// private static final Logger logger = Logger
// .getLogger(ConfigurationSingleton.class.getName());
//
// private Properties props = new Properties();
//
// private ConfigurationSingleton() {
// }
//
// public void readConfigFile(String config_path) {
// try {
// InputStream input = new FileInputStream(config_path);
// props.load(input);
// input.close();
// } catch (IOException e) {
// cease(logger, e.getMessage());
// }
// }
//
// public String getConfigItem(String val) {
// try {
// if (props.isEmpty()) {
// throw new Exception("Propery file object is empty. "
// + "This likely indicates that the config singleton "
// + "was not properly initialized via readConfigFile.");
// }
// if (props.getProperty(val) == null) {
// throw new Exception("The property " + val
// + " is missing from the configurtion file.");
// }
// return props.getProperty(val);
// } catch (Exception e) {
// cease(logger, e.getMessage());
// return null;
// }
// }
// }
| import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import org.apache.log4j.Logger;
import com.dogeops.cantilever.utils.ConfigurationSingleton; | package com.dogeops.cantilever.truss;
public class POSTHeaderCacheBuilder {
private static final Logger logger = Logger.getLogger(POSTHeaderCacheBuilder.class
.getName());
private final String post_config_key = "truss.post.headers";
public POSTHeaderCacheBuilder() { | // Path: src/main/java/com/dogeops/cantilever/utils/ConfigurationSingleton.java
// public enum ConfigurationSingleton {
// instance;
// private static final Logger logger = Logger
// .getLogger(ConfigurationSingleton.class.getName());
//
// private Properties props = new Properties();
//
// private ConfigurationSingleton() {
// }
//
// public void readConfigFile(String config_path) {
// try {
// InputStream input = new FileInputStream(config_path);
// props.load(input);
// input.close();
// } catch (IOException e) {
// cease(logger, e.getMessage());
// }
// }
//
// public String getConfigItem(String val) {
// try {
// if (props.isEmpty()) {
// throw new Exception("Propery file object is empty. "
// + "This likely indicates that the config singleton "
// + "was not properly initialized via readConfigFile.");
// }
// if (props.getProperty(val) == null) {
// throw new Exception("The property " + val
// + " is missing from the configurtion file.");
// }
// return props.getProperty(val);
// } catch (Exception e) {
// cease(logger, e.getMessage());
// return null;
// }
// }
// }
// Path: src/main/java/com/dogeops/cantilever/truss/POSTHeaderCacheBuilder.java
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import org.apache.log4j.Logger;
import com.dogeops.cantilever.utils.ConfigurationSingleton;
package com.dogeops.cantilever.truss;
public class POSTHeaderCacheBuilder {
private static final Logger logger = Logger.getLogger(POSTHeaderCacheBuilder.class
.getName());
private final String post_config_key = "truss.post.headers";
public POSTHeaderCacheBuilder() { | File pattern_file = new File(ConfigurationSingleton.instance |
broamski/cantilever | src/main/java/com/dogeops/cantilever/messagequeue/MessageQueueFactory.java | // Path: src/main/java/com/dogeops/cantilever/utils/Util.java
// public class Util {
// public static void cease(Logger logger, String message) {
// logger.error(message);
// System.exit(1);
// }
// }
| import org.apache.log4j.Logger;
import com.dogeops.cantilever.utils.Util; | package com.dogeops.cantilever.messagequeue;
public class MessageQueueFactory {
private static final Logger logger = Logger.getLogger(MessageQueueFactory.class
.getName());
public enum QueueTypes {
AMQ, SQS, NAN;
public static QueueTypes toQueue(String str) {
try {
return valueOf(str);
} catch (Exception ex) {
return NAN;
}
}
}
public MessageQueueInterface getQueue(String type) {
switch (QueueTypes.toQueue(type))
{
case AMQ:
return new ActiveMQ();
case SQS:
return new AmazonSQS();
default: | // Path: src/main/java/com/dogeops/cantilever/utils/Util.java
// public class Util {
// public static void cease(Logger logger, String message) {
// logger.error(message);
// System.exit(1);
// }
// }
// Path: src/main/java/com/dogeops/cantilever/messagequeue/MessageQueueFactory.java
import org.apache.log4j.Logger;
import com.dogeops.cantilever.utils.Util;
package com.dogeops.cantilever.messagequeue;
public class MessageQueueFactory {
private static final Logger logger = Logger.getLogger(MessageQueueFactory.class
.getName());
public enum QueueTypes {
AMQ, SQS, NAN;
public static QueueTypes toQueue(String str) {
try {
return valueOf(str);
} catch (Exception ex) {
return NAN;
}
}
}
public MessageQueueInterface getQueue(String type) {
switch (QueueTypes.toQueue(type))
{
case AMQ:
return new ActiveMQ();
case SQS:
return new AmazonSQS();
default: | Util.cease(logger, "Invalid Message Queue. Quitting."); |
broamski/cantilever | src/main/java/com/dogeops/cantilever/utils/ConfigurationSingleton.java | // Path: src/main/java/com/dogeops/cantilever/utils/Util.java
// public static void cease(Logger logger, String message) {
// logger.error(message);
// System.exit(1);
// }
| import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import org.apache.log4j.Logger;
import static com.dogeops.cantilever.utils.Util.cease; | package com.dogeops.cantilever.utils;
public enum ConfigurationSingleton {
instance;
private static final Logger logger = Logger
.getLogger(ConfigurationSingleton.class.getName());
private Properties props = new Properties();
private ConfigurationSingleton() {
}
public void readConfigFile(String config_path) {
try {
InputStream input = new FileInputStream(config_path);
props.load(input);
input.close();
} catch (IOException e) { | // Path: src/main/java/com/dogeops/cantilever/utils/Util.java
// public static void cease(Logger logger, String message) {
// logger.error(message);
// System.exit(1);
// }
// Path: src/main/java/com/dogeops/cantilever/utils/ConfigurationSingleton.java
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import org.apache.log4j.Logger;
import static com.dogeops.cantilever.utils.Util.cease;
package com.dogeops.cantilever.utils;
public enum ConfigurationSingleton {
instance;
private static final Logger logger = Logger
.getLogger(ConfigurationSingleton.class.getName());
private Properties props = new Properties();
private ConfigurationSingleton() {
}
public void readConfigFile(String config_path) {
try {
InputStream input = new FileInputStream(config_path);
props.load(input);
input.close();
} catch (IOException e) { | cease(logger, e.getMessage()); |
broamski/cantilever | src/main/java/com/dogeops/cantilever/truss/client/apache/HTTPGetRequest.java | // Path: src/main/java/com/dogeops/cantilever/logreader/HTTPLogObject.java
// public class HTTPLogObject {
// private String timestamp, method, request, bytes, useragent;
// private String requesting_resver, request_payload, url_request;
// private String[] headers;
//
// public HTTPLogObject(String timestamp, String method, String request,
// String bytes, String useragent) {
// this.timestamp = timestamp;
// this.method = method;
// this.request = request;
// this.bytes = bytes;
// this.useragent = useragent;
//
// buildRequestPayload();
// }
//
// private void buildHeaderArray() {
// String header_input = ConfigurationSingleton.instance
// .getConfigItem("replay.request.headers");
// String header_delimiter = ConfigurationSingleton.instance
// .getConfigItem("replay.request.headers.delimiter");
// this.headers = header_input.split(header_delimiter);
// }
//
// private void buildRequestPayload() {
// this.requesting_resver = ConfigurationSingleton.instance
// .getConfigItem("replay.request.servername");
// buildHeaderArray();
// buildURLRequest();
// Gson gson = new Gson();
// this.request_payload = gson.toJson(this);
// }
//
// private void buildURLRequest() {
// String http_port = ConfigurationSingleton.instance
// .getConfigItem("replay.request.port");
// String http_protocol = ConfigurationSingleton.instance.getConfigItem(
// "replay.request.protocol").toLowerCase();
//
// if (http_port.equals("80") || http_port.equals("443")) {
// http_port = "";
// } else {
// http_port = ":" + http_port;
// }
// this.url_request = http_protocol + "://" + this.requesting_resver
// + this.request + http_port;
// }
//
// public String getTimestamp() {
// return this.timestamp;
// }
//
// public String getPayload() {
// return this.request_payload;
// }
//
// public String getRequest() {
// return this.request;
// }
//
// public String[] getHeaders() {
// return this.headers;
// }
//
// public String getServerName() {
// return this.requesting_resver;
// }
//
// public String getMethod() {
// return this.method;
// }
//
// public String getUseragent() {
// return this.useragent;
// }
//
// public String getURLRequest() {
// return this.url_request;
// }
// }
//
// Path: src/main/java/com/dogeops/cantilever/utils/ConfigurationSingleton.java
// public enum ConfigurationSingleton {
// instance;
// private static final Logger logger = Logger
// .getLogger(ConfigurationSingleton.class.getName());
//
// private Properties props = new Properties();
//
// private ConfigurationSingleton() {
// }
//
// public void readConfigFile(String config_path) {
// try {
// InputStream input = new FileInputStream(config_path);
// props.load(input);
// input.close();
// } catch (IOException e) {
// cease(logger, e.getMessage());
// }
// }
//
// public String getConfigItem(String val) {
// try {
// if (props.isEmpty()) {
// throw new Exception("Propery file object is empty. "
// + "This likely indicates that the config singleton "
// + "was not properly initialized via readConfigFile.");
// }
// if (props.getProperty(val) == null) {
// throw new Exception("The property " + val
// + " is missing from the configurtion file.");
// }
// return props.getProperty(val);
// } catch (Exception e) {
// cease(logger, e.getMessage());
// return null;
// }
// }
// }
| import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.protocol.BasicHttpContext;
import org.apache.http.protocol.HttpContext;
import org.apache.log4j.Logger;
import com.dogeops.cantilever.logreader.HTTPLogObject;
import com.dogeops.cantilever.utils.ConfigurationSingleton; | package com.dogeops.cantilever.truss.client.apache;
public class HTTPGetRequest extends Thread{
private static final Logger logger = Logger.getLogger(HTTPGetRequest.class
.getName());
private CloseableHttpClient httpClient;
private HttpContext context;
private HttpGet httpget; | // Path: src/main/java/com/dogeops/cantilever/logreader/HTTPLogObject.java
// public class HTTPLogObject {
// private String timestamp, method, request, bytes, useragent;
// private String requesting_resver, request_payload, url_request;
// private String[] headers;
//
// public HTTPLogObject(String timestamp, String method, String request,
// String bytes, String useragent) {
// this.timestamp = timestamp;
// this.method = method;
// this.request = request;
// this.bytes = bytes;
// this.useragent = useragent;
//
// buildRequestPayload();
// }
//
// private void buildHeaderArray() {
// String header_input = ConfigurationSingleton.instance
// .getConfigItem("replay.request.headers");
// String header_delimiter = ConfigurationSingleton.instance
// .getConfigItem("replay.request.headers.delimiter");
// this.headers = header_input.split(header_delimiter);
// }
//
// private void buildRequestPayload() {
// this.requesting_resver = ConfigurationSingleton.instance
// .getConfigItem("replay.request.servername");
// buildHeaderArray();
// buildURLRequest();
// Gson gson = new Gson();
// this.request_payload = gson.toJson(this);
// }
//
// private void buildURLRequest() {
// String http_port = ConfigurationSingleton.instance
// .getConfigItem("replay.request.port");
// String http_protocol = ConfigurationSingleton.instance.getConfigItem(
// "replay.request.protocol").toLowerCase();
//
// if (http_port.equals("80") || http_port.equals("443")) {
// http_port = "";
// } else {
// http_port = ":" + http_port;
// }
// this.url_request = http_protocol + "://" + this.requesting_resver
// + this.request + http_port;
// }
//
// public String getTimestamp() {
// return this.timestamp;
// }
//
// public String getPayload() {
// return this.request_payload;
// }
//
// public String getRequest() {
// return this.request;
// }
//
// public String[] getHeaders() {
// return this.headers;
// }
//
// public String getServerName() {
// return this.requesting_resver;
// }
//
// public String getMethod() {
// return this.method;
// }
//
// public String getUseragent() {
// return this.useragent;
// }
//
// public String getURLRequest() {
// return this.url_request;
// }
// }
//
// Path: src/main/java/com/dogeops/cantilever/utils/ConfigurationSingleton.java
// public enum ConfigurationSingleton {
// instance;
// private static final Logger logger = Logger
// .getLogger(ConfigurationSingleton.class.getName());
//
// private Properties props = new Properties();
//
// private ConfigurationSingleton() {
// }
//
// public void readConfigFile(String config_path) {
// try {
// InputStream input = new FileInputStream(config_path);
// props.load(input);
// input.close();
// } catch (IOException e) {
// cease(logger, e.getMessage());
// }
// }
//
// public String getConfigItem(String val) {
// try {
// if (props.isEmpty()) {
// throw new Exception("Propery file object is empty. "
// + "This likely indicates that the config singleton "
// + "was not properly initialized via readConfigFile.");
// }
// if (props.getProperty(val) == null) {
// throw new Exception("The property " + val
// + " is missing from the configurtion file.");
// }
// return props.getProperty(val);
// } catch (Exception e) {
// cease(logger, e.getMessage());
// return null;
// }
// }
// }
// Path: src/main/java/com/dogeops/cantilever/truss/client/apache/HTTPGetRequest.java
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.protocol.BasicHttpContext;
import org.apache.http.protocol.HttpContext;
import org.apache.log4j.Logger;
import com.dogeops.cantilever.logreader.HTTPLogObject;
import com.dogeops.cantilever.utils.ConfigurationSingleton;
package com.dogeops.cantilever.truss.client.apache;
public class HTTPGetRequest extends Thread{
private static final Logger logger = Logger.getLogger(HTTPGetRequest.class
.getName());
private CloseableHttpClient httpClient;
private HttpContext context;
private HttpGet httpget; | private HTTPLogObject http_log; |
broamski/cantilever | src/main/java/com/dogeops/cantilever/truss/client/apache/HTTPGetRequest.java | // Path: src/main/java/com/dogeops/cantilever/logreader/HTTPLogObject.java
// public class HTTPLogObject {
// private String timestamp, method, request, bytes, useragent;
// private String requesting_resver, request_payload, url_request;
// private String[] headers;
//
// public HTTPLogObject(String timestamp, String method, String request,
// String bytes, String useragent) {
// this.timestamp = timestamp;
// this.method = method;
// this.request = request;
// this.bytes = bytes;
// this.useragent = useragent;
//
// buildRequestPayload();
// }
//
// private void buildHeaderArray() {
// String header_input = ConfigurationSingleton.instance
// .getConfigItem("replay.request.headers");
// String header_delimiter = ConfigurationSingleton.instance
// .getConfigItem("replay.request.headers.delimiter");
// this.headers = header_input.split(header_delimiter);
// }
//
// private void buildRequestPayload() {
// this.requesting_resver = ConfigurationSingleton.instance
// .getConfigItem("replay.request.servername");
// buildHeaderArray();
// buildURLRequest();
// Gson gson = new Gson();
// this.request_payload = gson.toJson(this);
// }
//
// private void buildURLRequest() {
// String http_port = ConfigurationSingleton.instance
// .getConfigItem("replay.request.port");
// String http_protocol = ConfigurationSingleton.instance.getConfigItem(
// "replay.request.protocol").toLowerCase();
//
// if (http_port.equals("80") || http_port.equals("443")) {
// http_port = "";
// } else {
// http_port = ":" + http_port;
// }
// this.url_request = http_protocol + "://" + this.requesting_resver
// + this.request + http_port;
// }
//
// public String getTimestamp() {
// return this.timestamp;
// }
//
// public String getPayload() {
// return this.request_payload;
// }
//
// public String getRequest() {
// return this.request;
// }
//
// public String[] getHeaders() {
// return this.headers;
// }
//
// public String getServerName() {
// return this.requesting_resver;
// }
//
// public String getMethod() {
// return this.method;
// }
//
// public String getUseragent() {
// return this.useragent;
// }
//
// public String getURLRequest() {
// return this.url_request;
// }
// }
//
// Path: src/main/java/com/dogeops/cantilever/utils/ConfigurationSingleton.java
// public enum ConfigurationSingleton {
// instance;
// private static final Logger logger = Logger
// .getLogger(ConfigurationSingleton.class.getName());
//
// private Properties props = new Properties();
//
// private ConfigurationSingleton() {
// }
//
// public void readConfigFile(String config_path) {
// try {
// InputStream input = new FileInputStream(config_path);
// props.load(input);
// input.close();
// } catch (IOException e) {
// cease(logger, e.getMessage());
// }
// }
//
// public String getConfigItem(String val) {
// try {
// if (props.isEmpty()) {
// throw new Exception("Propery file object is empty. "
// + "This likely indicates that the config singleton "
// + "was not properly initialized via readConfigFile.");
// }
// if (props.getProperty(val) == null) {
// throw new Exception("The property " + val
// + " is missing from the configurtion file.");
// }
// return props.getProperty(val);
// } catch (Exception e) {
// cease(logger, e.getMessage());
// return null;
// }
// }
// }
| import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.protocol.BasicHttpContext;
import org.apache.http.protocol.HttpContext;
import org.apache.log4j.Logger;
import com.dogeops.cantilever.logreader.HTTPLogObject;
import com.dogeops.cantilever.utils.ConfigurationSingleton; | package com.dogeops.cantilever.truss.client.apache;
public class HTTPGetRequest extends Thread{
private static final Logger logger = Logger.getLogger(HTTPGetRequest.class
.getName());
private CloseableHttpClient httpClient;
private HttpContext context;
private HttpGet httpget;
private HTTPLogObject http_log;
public HTTPGetRequest(HTTPLogObject http_log, CloseableHttpClient httpClient) {
this.http_log = http_log;
this.httpClient = httpClient;
this.context = new BasicHttpContext();
}
public void run() {
// I'm unsure why we access these particular config items from the
// config singleton and not-prop them like we do in the HTTP Log Object
// Low priority, but should be reviewed at some point
| // Path: src/main/java/com/dogeops/cantilever/logreader/HTTPLogObject.java
// public class HTTPLogObject {
// private String timestamp, method, request, bytes, useragent;
// private String requesting_resver, request_payload, url_request;
// private String[] headers;
//
// public HTTPLogObject(String timestamp, String method, String request,
// String bytes, String useragent) {
// this.timestamp = timestamp;
// this.method = method;
// this.request = request;
// this.bytes = bytes;
// this.useragent = useragent;
//
// buildRequestPayload();
// }
//
// private void buildHeaderArray() {
// String header_input = ConfigurationSingleton.instance
// .getConfigItem("replay.request.headers");
// String header_delimiter = ConfigurationSingleton.instance
// .getConfigItem("replay.request.headers.delimiter");
// this.headers = header_input.split(header_delimiter);
// }
//
// private void buildRequestPayload() {
// this.requesting_resver = ConfigurationSingleton.instance
// .getConfigItem("replay.request.servername");
// buildHeaderArray();
// buildURLRequest();
// Gson gson = new Gson();
// this.request_payload = gson.toJson(this);
// }
//
// private void buildURLRequest() {
// String http_port = ConfigurationSingleton.instance
// .getConfigItem("replay.request.port");
// String http_protocol = ConfigurationSingleton.instance.getConfigItem(
// "replay.request.protocol").toLowerCase();
//
// if (http_port.equals("80") || http_port.equals("443")) {
// http_port = "";
// } else {
// http_port = ":" + http_port;
// }
// this.url_request = http_protocol + "://" + this.requesting_resver
// + this.request + http_port;
// }
//
// public String getTimestamp() {
// return this.timestamp;
// }
//
// public String getPayload() {
// return this.request_payload;
// }
//
// public String getRequest() {
// return this.request;
// }
//
// public String[] getHeaders() {
// return this.headers;
// }
//
// public String getServerName() {
// return this.requesting_resver;
// }
//
// public String getMethod() {
// return this.method;
// }
//
// public String getUseragent() {
// return this.useragent;
// }
//
// public String getURLRequest() {
// return this.url_request;
// }
// }
//
// Path: src/main/java/com/dogeops/cantilever/utils/ConfigurationSingleton.java
// public enum ConfigurationSingleton {
// instance;
// private static final Logger logger = Logger
// .getLogger(ConfigurationSingleton.class.getName());
//
// private Properties props = new Properties();
//
// private ConfigurationSingleton() {
// }
//
// public void readConfigFile(String config_path) {
// try {
// InputStream input = new FileInputStream(config_path);
// props.load(input);
// input.close();
// } catch (IOException e) {
// cease(logger, e.getMessage());
// }
// }
//
// public String getConfigItem(String val) {
// try {
// if (props.isEmpty()) {
// throw new Exception("Propery file object is empty. "
// + "This likely indicates that the config singleton "
// + "was not properly initialized via readConfigFile.");
// }
// if (props.getProperty(val) == null) {
// throw new Exception("The property " + val
// + " is missing from the configurtion file.");
// }
// return props.getProperty(val);
// } catch (Exception e) {
// cease(logger, e.getMessage());
// return null;
// }
// }
// }
// Path: src/main/java/com/dogeops/cantilever/truss/client/apache/HTTPGetRequest.java
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.protocol.BasicHttpContext;
import org.apache.http.protocol.HttpContext;
import org.apache.log4j.Logger;
import com.dogeops.cantilever.logreader.HTTPLogObject;
import com.dogeops.cantilever.utils.ConfigurationSingleton;
package com.dogeops.cantilever.truss.client.apache;
public class HTTPGetRequest extends Thread{
private static final Logger logger = Logger.getLogger(HTTPGetRequest.class
.getName());
private CloseableHttpClient httpClient;
private HttpContext context;
private HttpGet httpget;
private HTTPLogObject http_log;
public HTTPGetRequest(HTTPLogObject http_log, CloseableHttpClient httpClient) {
this.http_log = http_log;
this.httpClient = httpClient;
this.context = new BasicHttpContext();
}
public void run() {
// I'm unsure why we access these particular config items from the
// config singleton and not-prop them like we do in the HTTP Log Object
// Low priority, but should be reviewed at some point
| String http_port = ConfigurationSingleton.instance.getConfigItem("replay.request.port"); |
uPhyca/idobata4j | idobata4j-core/src/test/java/com/uphyca/idobata/TokenAuthenticatorTest.java | // Path: idobata4j-core/src/main/java/com/uphyca/idobata/http/Client.java
// public interface Client {
//
// /**
// * Synchronously execute an HTTP represented by {@code request} and encapsulate all response data
// * into a {@link Response} instance.
// */
// Response execute(Request request) throws IOException;
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/http/Header.java
// public class Header {
//
// private final String name;
// private final String value;
//
// public Header(String name, String value) {
// this.name = name;
// this.value = value;
// }
//
// public String getName() {
// return name;
// }
//
// public String getValue() {
// return value;
// }
//
// @Override
// public boolean equals(Object o) {
// if (this == o) {
// return true;
// }
// if (o == null || getClass() != o.getClass()) {
// return false;
// }
//
// Header header = (Header) o;
//
// if (name != null ? !name.equals(header.name) : header.name != null) {
// return false;
// }
// if (value != null ? !value.equals(header.value) : header.value != null) {
// return false;
// }
//
// return true;
// }
//
// @Override
// public int hashCode() {
// int result = name != null ? name.hashCode() : 0;
// result = 31 * result + (value != null ? value.hashCode() : 0);
// return result;
// }
//
// @Override
// public String toString() {
// return "Header{" + "name='" + name + '\'' + ", value='" + value + '\'' + '}';
// }
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/http/Request.java
// public class Request {
//
// private final String method;
// private final String url;
// private final List<Header> headers;
// private final TypedOutput body;
//
// public Request(String method, String url, List<Header> headers, TypedOutput body) {
// this.method = method;
// this.url = url;
// this.headers = headers;
// this.body = body;
// }
//
// /** HTTP method verb. */
// public String getMethod() {
// return method;
// }
//
// /** Target URL. */
// public String getUrl() {
// return url;
// }
//
// /** Returns an unmodifiable list of headers, never {@code null}. */
// public List<Header> getHeaders() {
// return headers;
// }
//
// /** Returns the request body or {@code null}. */
// public TypedOutput getBody() {
// return body;
// }
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/http/Response.java
// public class Response {
//
// private final String url;
// private final int status;
// private final String reason;
// private final List<Header> headers;
// private final TypedInput body;
//
// public Response(String url, int status, String reason, List<Header> headers, TypedInput body) {
// this.url = url;
// this.status = status;
// this.reason = reason;
// this.headers = headers;
// this.body = body;
// }
//
// /** Request URL. */
// public String getUrl() {
// return url;
// }
//
// /** Status line code. */
// public int getStatus() {
// return status;
// }
//
// /** Status line reason phrase. */
// public String getReason() {
// return reason;
// }
//
// /** An unmodifiable collection of headers. */
// public List<Header> getHeaders() {
// return headers;
// }
//
// /** Response body. May be {@code null}. */
// public TypedInput getBody() {
// return body;
// }
// }
| import com.uphyca.idobata.http.Client;
import com.uphyca.idobata.http.Header;
import com.uphyca.idobata.http.Request;
import com.uphyca.idobata.http.Response;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import java.util.Collections;
import static org.fest.assertions.api.Assertions.assertThat;
import static org.mockito.BDDMockito.given;
import static org.mockito.BDDMockito.mock; |
package com.uphyca.idobata;
@RunWith(MockitoJUnitRunner.class)
public class TokenAuthenticatorTest {
@Mock | // Path: idobata4j-core/src/main/java/com/uphyca/idobata/http/Client.java
// public interface Client {
//
// /**
// * Synchronously execute an HTTP represented by {@code request} and encapsulate all response data
// * into a {@link Response} instance.
// */
// Response execute(Request request) throws IOException;
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/http/Header.java
// public class Header {
//
// private final String name;
// private final String value;
//
// public Header(String name, String value) {
// this.name = name;
// this.value = value;
// }
//
// public String getName() {
// return name;
// }
//
// public String getValue() {
// return value;
// }
//
// @Override
// public boolean equals(Object o) {
// if (this == o) {
// return true;
// }
// if (o == null || getClass() != o.getClass()) {
// return false;
// }
//
// Header header = (Header) o;
//
// if (name != null ? !name.equals(header.name) : header.name != null) {
// return false;
// }
// if (value != null ? !value.equals(header.value) : header.value != null) {
// return false;
// }
//
// return true;
// }
//
// @Override
// public int hashCode() {
// int result = name != null ? name.hashCode() : 0;
// result = 31 * result + (value != null ? value.hashCode() : 0);
// return result;
// }
//
// @Override
// public String toString() {
// return "Header{" + "name='" + name + '\'' + ", value='" + value + '\'' + '}';
// }
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/http/Request.java
// public class Request {
//
// private final String method;
// private final String url;
// private final List<Header> headers;
// private final TypedOutput body;
//
// public Request(String method, String url, List<Header> headers, TypedOutput body) {
// this.method = method;
// this.url = url;
// this.headers = headers;
// this.body = body;
// }
//
// /** HTTP method verb. */
// public String getMethod() {
// return method;
// }
//
// /** Target URL. */
// public String getUrl() {
// return url;
// }
//
// /** Returns an unmodifiable list of headers, never {@code null}. */
// public List<Header> getHeaders() {
// return headers;
// }
//
// /** Returns the request body or {@code null}. */
// public TypedOutput getBody() {
// return body;
// }
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/http/Response.java
// public class Response {
//
// private final String url;
// private final int status;
// private final String reason;
// private final List<Header> headers;
// private final TypedInput body;
//
// public Response(String url, int status, String reason, List<Header> headers, TypedInput body) {
// this.url = url;
// this.status = status;
// this.reason = reason;
// this.headers = headers;
// this.body = body;
// }
//
// /** Request URL. */
// public String getUrl() {
// return url;
// }
//
// /** Status line code. */
// public int getStatus() {
// return status;
// }
//
// /** Status line reason phrase. */
// public String getReason() {
// return reason;
// }
//
// /** An unmodifiable collection of headers. */
// public List<Header> getHeaders() {
// return headers;
// }
//
// /** Response body. May be {@code null}. */
// public TypedInput getBody() {
// return body;
// }
// }
// Path: idobata4j-core/src/test/java/com/uphyca/idobata/TokenAuthenticatorTest.java
import com.uphyca.idobata.http.Client;
import com.uphyca.idobata.http.Header;
import com.uphyca.idobata.http.Request;
import com.uphyca.idobata.http.Response;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import java.util.Collections;
import static org.fest.assertions.api.Assertions.assertThat;
import static org.mockito.BDDMockito.given;
import static org.mockito.BDDMockito.mock;
package com.uphyca.idobata;
@RunWith(MockitoJUnitRunner.class)
public class TokenAuthenticatorTest {
@Mock | Client mClient; |
uPhyca/idobata4j | idobata4j-core/src/test/java/com/uphyca/idobata/TokenAuthenticatorTest.java | // Path: idobata4j-core/src/main/java/com/uphyca/idobata/http/Client.java
// public interface Client {
//
// /**
// * Synchronously execute an HTTP represented by {@code request} and encapsulate all response data
// * into a {@link Response} instance.
// */
// Response execute(Request request) throws IOException;
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/http/Header.java
// public class Header {
//
// private final String name;
// private final String value;
//
// public Header(String name, String value) {
// this.name = name;
// this.value = value;
// }
//
// public String getName() {
// return name;
// }
//
// public String getValue() {
// return value;
// }
//
// @Override
// public boolean equals(Object o) {
// if (this == o) {
// return true;
// }
// if (o == null || getClass() != o.getClass()) {
// return false;
// }
//
// Header header = (Header) o;
//
// if (name != null ? !name.equals(header.name) : header.name != null) {
// return false;
// }
// if (value != null ? !value.equals(header.value) : header.value != null) {
// return false;
// }
//
// return true;
// }
//
// @Override
// public int hashCode() {
// int result = name != null ? name.hashCode() : 0;
// result = 31 * result + (value != null ? value.hashCode() : 0);
// return result;
// }
//
// @Override
// public String toString() {
// return "Header{" + "name='" + name + '\'' + ", value='" + value + '\'' + '}';
// }
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/http/Request.java
// public class Request {
//
// private final String method;
// private final String url;
// private final List<Header> headers;
// private final TypedOutput body;
//
// public Request(String method, String url, List<Header> headers, TypedOutput body) {
// this.method = method;
// this.url = url;
// this.headers = headers;
// this.body = body;
// }
//
// /** HTTP method verb. */
// public String getMethod() {
// return method;
// }
//
// /** Target URL. */
// public String getUrl() {
// return url;
// }
//
// /** Returns an unmodifiable list of headers, never {@code null}. */
// public List<Header> getHeaders() {
// return headers;
// }
//
// /** Returns the request body or {@code null}. */
// public TypedOutput getBody() {
// return body;
// }
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/http/Response.java
// public class Response {
//
// private final String url;
// private final int status;
// private final String reason;
// private final List<Header> headers;
// private final TypedInput body;
//
// public Response(String url, int status, String reason, List<Header> headers, TypedInput body) {
// this.url = url;
// this.status = status;
// this.reason = reason;
// this.headers = headers;
// this.body = body;
// }
//
// /** Request URL. */
// public String getUrl() {
// return url;
// }
//
// /** Status line code. */
// public int getStatus() {
// return status;
// }
//
// /** Status line reason phrase. */
// public String getReason() {
// return reason;
// }
//
// /** An unmodifiable collection of headers. */
// public List<Header> getHeaders() {
// return headers;
// }
//
// /** Response body. May be {@code null}. */
// public TypedInput getBody() {
// return body;
// }
// }
| import com.uphyca.idobata.http.Client;
import com.uphyca.idobata.http.Header;
import com.uphyca.idobata.http.Request;
import com.uphyca.idobata.http.Response;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import java.util.Collections;
import static org.fest.assertions.api.Assertions.assertThat;
import static org.mockito.BDDMockito.given;
import static org.mockito.BDDMockito.mock; |
package com.uphyca.idobata;
@RunWith(MockitoJUnitRunner.class)
public class TokenAuthenticatorTest {
@Mock
Client mClient;
@Test
public void constantTokenString() throws Exception {
| // Path: idobata4j-core/src/main/java/com/uphyca/idobata/http/Client.java
// public interface Client {
//
// /**
// * Synchronously execute an HTTP represented by {@code request} and encapsulate all response data
// * into a {@link Response} instance.
// */
// Response execute(Request request) throws IOException;
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/http/Header.java
// public class Header {
//
// private final String name;
// private final String value;
//
// public Header(String name, String value) {
// this.name = name;
// this.value = value;
// }
//
// public String getName() {
// return name;
// }
//
// public String getValue() {
// return value;
// }
//
// @Override
// public boolean equals(Object o) {
// if (this == o) {
// return true;
// }
// if (o == null || getClass() != o.getClass()) {
// return false;
// }
//
// Header header = (Header) o;
//
// if (name != null ? !name.equals(header.name) : header.name != null) {
// return false;
// }
// if (value != null ? !value.equals(header.value) : header.value != null) {
// return false;
// }
//
// return true;
// }
//
// @Override
// public int hashCode() {
// int result = name != null ? name.hashCode() : 0;
// result = 31 * result + (value != null ? value.hashCode() : 0);
// return result;
// }
//
// @Override
// public String toString() {
// return "Header{" + "name='" + name + '\'' + ", value='" + value + '\'' + '}';
// }
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/http/Request.java
// public class Request {
//
// private final String method;
// private final String url;
// private final List<Header> headers;
// private final TypedOutput body;
//
// public Request(String method, String url, List<Header> headers, TypedOutput body) {
// this.method = method;
// this.url = url;
// this.headers = headers;
// this.body = body;
// }
//
// /** HTTP method verb. */
// public String getMethod() {
// return method;
// }
//
// /** Target URL. */
// public String getUrl() {
// return url;
// }
//
// /** Returns an unmodifiable list of headers, never {@code null}. */
// public List<Header> getHeaders() {
// return headers;
// }
//
// /** Returns the request body or {@code null}. */
// public TypedOutput getBody() {
// return body;
// }
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/http/Response.java
// public class Response {
//
// private final String url;
// private final int status;
// private final String reason;
// private final List<Header> headers;
// private final TypedInput body;
//
// public Response(String url, int status, String reason, List<Header> headers, TypedInput body) {
// this.url = url;
// this.status = status;
// this.reason = reason;
// this.headers = headers;
// this.body = body;
// }
//
// /** Request URL. */
// public String getUrl() {
// return url;
// }
//
// /** Status line code. */
// public int getStatus() {
// return status;
// }
//
// /** Status line reason phrase. */
// public String getReason() {
// return reason;
// }
//
// /** An unmodifiable collection of headers. */
// public List<Header> getHeaders() {
// return headers;
// }
//
// /** Response body. May be {@code null}. */
// public TypedInput getBody() {
// return body;
// }
// }
// Path: idobata4j-core/src/test/java/com/uphyca/idobata/TokenAuthenticatorTest.java
import com.uphyca.idobata.http.Client;
import com.uphyca.idobata.http.Header;
import com.uphyca.idobata.http.Request;
import com.uphyca.idobata.http.Response;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import java.util.Collections;
import static org.fest.assertions.api.Assertions.assertThat;
import static org.mockito.BDDMockito.given;
import static org.mockito.BDDMockito.mock;
package com.uphyca.idobata;
@RunWith(MockitoJUnitRunner.class)
public class TokenAuthenticatorTest {
@Mock
Client mClient;
@Test
public void constantTokenString() throws Exception {
| ArgumentCaptor<Request> requestCaptor = ArgumentCaptor.forClass(Request.class); |
uPhyca/idobata4j | idobata4j-core/src/test/java/com/uphyca/idobata/TokenAuthenticatorTest.java | // Path: idobata4j-core/src/main/java/com/uphyca/idobata/http/Client.java
// public interface Client {
//
// /**
// * Synchronously execute an HTTP represented by {@code request} and encapsulate all response data
// * into a {@link Response} instance.
// */
// Response execute(Request request) throws IOException;
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/http/Header.java
// public class Header {
//
// private final String name;
// private final String value;
//
// public Header(String name, String value) {
// this.name = name;
// this.value = value;
// }
//
// public String getName() {
// return name;
// }
//
// public String getValue() {
// return value;
// }
//
// @Override
// public boolean equals(Object o) {
// if (this == o) {
// return true;
// }
// if (o == null || getClass() != o.getClass()) {
// return false;
// }
//
// Header header = (Header) o;
//
// if (name != null ? !name.equals(header.name) : header.name != null) {
// return false;
// }
// if (value != null ? !value.equals(header.value) : header.value != null) {
// return false;
// }
//
// return true;
// }
//
// @Override
// public int hashCode() {
// int result = name != null ? name.hashCode() : 0;
// result = 31 * result + (value != null ? value.hashCode() : 0);
// return result;
// }
//
// @Override
// public String toString() {
// return "Header{" + "name='" + name + '\'' + ", value='" + value + '\'' + '}';
// }
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/http/Request.java
// public class Request {
//
// private final String method;
// private final String url;
// private final List<Header> headers;
// private final TypedOutput body;
//
// public Request(String method, String url, List<Header> headers, TypedOutput body) {
// this.method = method;
// this.url = url;
// this.headers = headers;
// this.body = body;
// }
//
// /** HTTP method verb. */
// public String getMethod() {
// return method;
// }
//
// /** Target URL. */
// public String getUrl() {
// return url;
// }
//
// /** Returns an unmodifiable list of headers, never {@code null}. */
// public List<Header> getHeaders() {
// return headers;
// }
//
// /** Returns the request body or {@code null}. */
// public TypedOutput getBody() {
// return body;
// }
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/http/Response.java
// public class Response {
//
// private final String url;
// private final int status;
// private final String reason;
// private final List<Header> headers;
// private final TypedInput body;
//
// public Response(String url, int status, String reason, List<Header> headers, TypedInput body) {
// this.url = url;
// this.status = status;
// this.reason = reason;
// this.headers = headers;
// this.body = body;
// }
//
// /** Request URL. */
// public String getUrl() {
// return url;
// }
//
// /** Status line code. */
// public int getStatus() {
// return status;
// }
//
// /** Status line reason phrase. */
// public String getReason() {
// return reason;
// }
//
// /** An unmodifiable collection of headers. */
// public List<Header> getHeaders() {
// return headers;
// }
//
// /** Response body. May be {@code null}. */
// public TypedInput getBody() {
// return body;
// }
// }
| import com.uphyca.idobata.http.Client;
import com.uphyca.idobata.http.Header;
import com.uphyca.idobata.http.Request;
import com.uphyca.idobata.http.Response;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import java.util.Collections;
import static org.fest.assertions.api.Assertions.assertThat;
import static org.mockito.BDDMockito.given;
import static org.mockito.BDDMockito.mock; |
package com.uphyca.idobata;
@RunWith(MockitoJUnitRunner.class)
public class TokenAuthenticatorTest {
@Mock
Client mClient;
@Test
public void constantTokenString() throws Exception {
ArgumentCaptor<Request> requestCaptor = ArgumentCaptor.forClass(Request.class); | // Path: idobata4j-core/src/main/java/com/uphyca/idobata/http/Client.java
// public interface Client {
//
// /**
// * Synchronously execute an HTTP represented by {@code request} and encapsulate all response data
// * into a {@link Response} instance.
// */
// Response execute(Request request) throws IOException;
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/http/Header.java
// public class Header {
//
// private final String name;
// private final String value;
//
// public Header(String name, String value) {
// this.name = name;
// this.value = value;
// }
//
// public String getName() {
// return name;
// }
//
// public String getValue() {
// return value;
// }
//
// @Override
// public boolean equals(Object o) {
// if (this == o) {
// return true;
// }
// if (o == null || getClass() != o.getClass()) {
// return false;
// }
//
// Header header = (Header) o;
//
// if (name != null ? !name.equals(header.name) : header.name != null) {
// return false;
// }
// if (value != null ? !value.equals(header.value) : header.value != null) {
// return false;
// }
//
// return true;
// }
//
// @Override
// public int hashCode() {
// int result = name != null ? name.hashCode() : 0;
// result = 31 * result + (value != null ? value.hashCode() : 0);
// return result;
// }
//
// @Override
// public String toString() {
// return "Header{" + "name='" + name + '\'' + ", value='" + value + '\'' + '}';
// }
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/http/Request.java
// public class Request {
//
// private final String method;
// private final String url;
// private final List<Header> headers;
// private final TypedOutput body;
//
// public Request(String method, String url, List<Header> headers, TypedOutput body) {
// this.method = method;
// this.url = url;
// this.headers = headers;
// this.body = body;
// }
//
// /** HTTP method verb. */
// public String getMethod() {
// return method;
// }
//
// /** Target URL. */
// public String getUrl() {
// return url;
// }
//
// /** Returns an unmodifiable list of headers, never {@code null}. */
// public List<Header> getHeaders() {
// return headers;
// }
//
// /** Returns the request body or {@code null}. */
// public TypedOutput getBody() {
// return body;
// }
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/http/Response.java
// public class Response {
//
// private final String url;
// private final int status;
// private final String reason;
// private final List<Header> headers;
// private final TypedInput body;
//
// public Response(String url, int status, String reason, List<Header> headers, TypedInput body) {
// this.url = url;
// this.status = status;
// this.reason = reason;
// this.headers = headers;
// this.body = body;
// }
//
// /** Request URL. */
// public String getUrl() {
// return url;
// }
//
// /** Status line code. */
// public int getStatus() {
// return status;
// }
//
// /** Status line reason phrase. */
// public String getReason() {
// return reason;
// }
//
// /** An unmodifiable collection of headers. */
// public List<Header> getHeaders() {
// return headers;
// }
//
// /** Response body. May be {@code null}. */
// public TypedInput getBody() {
// return body;
// }
// }
// Path: idobata4j-core/src/test/java/com/uphyca/idobata/TokenAuthenticatorTest.java
import com.uphyca.idobata.http.Client;
import com.uphyca.idobata.http.Header;
import com.uphyca.idobata.http.Request;
import com.uphyca.idobata.http.Response;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import java.util.Collections;
import static org.fest.assertions.api.Assertions.assertThat;
import static org.mockito.BDDMockito.given;
import static org.mockito.BDDMockito.mock;
package com.uphyca.idobata;
@RunWith(MockitoJUnitRunner.class)
public class TokenAuthenticatorTest {
@Mock
Client mClient;
@Test
public void constantTokenString() throws Exception {
ArgumentCaptor<Request> requestCaptor = ArgumentCaptor.forClass(Request.class); | given(mClient.execute(requestCaptor.capture())).willReturn(mock(Response.class)); |
uPhyca/idobata4j | idobata4j-core/src/test/java/com/uphyca/idobata/TokenAuthenticatorTest.java | // Path: idobata4j-core/src/main/java/com/uphyca/idobata/http/Client.java
// public interface Client {
//
// /**
// * Synchronously execute an HTTP represented by {@code request} and encapsulate all response data
// * into a {@link Response} instance.
// */
// Response execute(Request request) throws IOException;
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/http/Header.java
// public class Header {
//
// private final String name;
// private final String value;
//
// public Header(String name, String value) {
// this.name = name;
// this.value = value;
// }
//
// public String getName() {
// return name;
// }
//
// public String getValue() {
// return value;
// }
//
// @Override
// public boolean equals(Object o) {
// if (this == o) {
// return true;
// }
// if (o == null || getClass() != o.getClass()) {
// return false;
// }
//
// Header header = (Header) o;
//
// if (name != null ? !name.equals(header.name) : header.name != null) {
// return false;
// }
// if (value != null ? !value.equals(header.value) : header.value != null) {
// return false;
// }
//
// return true;
// }
//
// @Override
// public int hashCode() {
// int result = name != null ? name.hashCode() : 0;
// result = 31 * result + (value != null ? value.hashCode() : 0);
// return result;
// }
//
// @Override
// public String toString() {
// return "Header{" + "name='" + name + '\'' + ", value='" + value + '\'' + '}';
// }
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/http/Request.java
// public class Request {
//
// private final String method;
// private final String url;
// private final List<Header> headers;
// private final TypedOutput body;
//
// public Request(String method, String url, List<Header> headers, TypedOutput body) {
// this.method = method;
// this.url = url;
// this.headers = headers;
// this.body = body;
// }
//
// /** HTTP method verb. */
// public String getMethod() {
// return method;
// }
//
// /** Target URL. */
// public String getUrl() {
// return url;
// }
//
// /** Returns an unmodifiable list of headers, never {@code null}. */
// public List<Header> getHeaders() {
// return headers;
// }
//
// /** Returns the request body or {@code null}. */
// public TypedOutput getBody() {
// return body;
// }
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/http/Response.java
// public class Response {
//
// private final String url;
// private final int status;
// private final String reason;
// private final List<Header> headers;
// private final TypedInput body;
//
// public Response(String url, int status, String reason, List<Header> headers, TypedInput body) {
// this.url = url;
// this.status = status;
// this.reason = reason;
// this.headers = headers;
// this.body = body;
// }
//
// /** Request URL. */
// public String getUrl() {
// return url;
// }
//
// /** Status line code. */
// public int getStatus() {
// return status;
// }
//
// /** Status line reason phrase. */
// public String getReason() {
// return reason;
// }
//
// /** An unmodifiable collection of headers. */
// public List<Header> getHeaders() {
// return headers;
// }
//
// /** Response body. May be {@code null}. */
// public TypedInput getBody() {
// return body;
// }
// }
| import com.uphyca.idobata.http.Client;
import com.uphyca.idobata.http.Header;
import com.uphyca.idobata.http.Request;
import com.uphyca.idobata.http.Response;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import java.util.Collections;
import static org.fest.assertions.api.Assertions.assertThat;
import static org.mockito.BDDMockito.given;
import static org.mockito.BDDMockito.mock; |
package com.uphyca.idobata;
@RunWith(MockitoJUnitRunner.class)
public class TokenAuthenticatorTest {
@Mock
Client mClient;
@Test
public void constantTokenString() throws Exception {
ArgumentCaptor<Request> requestCaptor = ArgumentCaptor.forClass(Request.class);
given(mClient.execute(requestCaptor.capture())).willReturn(mock(Response.class));
TokenAuthenticator underTest = new TokenAuthenticator("abc"); | // Path: idobata4j-core/src/main/java/com/uphyca/idobata/http/Client.java
// public interface Client {
//
// /**
// * Synchronously execute an HTTP represented by {@code request} and encapsulate all response data
// * into a {@link Response} instance.
// */
// Response execute(Request request) throws IOException;
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/http/Header.java
// public class Header {
//
// private final String name;
// private final String value;
//
// public Header(String name, String value) {
// this.name = name;
// this.value = value;
// }
//
// public String getName() {
// return name;
// }
//
// public String getValue() {
// return value;
// }
//
// @Override
// public boolean equals(Object o) {
// if (this == o) {
// return true;
// }
// if (o == null || getClass() != o.getClass()) {
// return false;
// }
//
// Header header = (Header) o;
//
// if (name != null ? !name.equals(header.name) : header.name != null) {
// return false;
// }
// if (value != null ? !value.equals(header.value) : header.value != null) {
// return false;
// }
//
// return true;
// }
//
// @Override
// public int hashCode() {
// int result = name != null ? name.hashCode() : 0;
// result = 31 * result + (value != null ? value.hashCode() : 0);
// return result;
// }
//
// @Override
// public String toString() {
// return "Header{" + "name='" + name + '\'' + ", value='" + value + '\'' + '}';
// }
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/http/Request.java
// public class Request {
//
// private final String method;
// private final String url;
// private final List<Header> headers;
// private final TypedOutput body;
//
// public Request(String method, String url, List<Header> headers, TypedOutput body) {
// this.method = method;
// this.url = url;
// this.headers = headers;
// this.body = body;
// }
//
// /** HTTP method verb. */
// public String getMethod() {
// return method;
// }
//
// /** Target URL. */
// public String getUrl() {
// return url;
// }
//
// /** Returns an unmodifiable list of headers, never {@code null}. */
// public List<Header> getHeaders() {
// return headers;
// }
//
// /** Returns the request body or {@code null}. */
// public TypedOutput getBody() {
// return body;
// }
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/http/Response.java
// public class Response {
//
// private final String url;
// private final int status;
// private final String reason;
// private final List<Header> headers;
// private final TypedInput body;
//
// public Response(String url, int status, String reason, List<Header> headers, TypedInput body) {
// this.url = url;
// this.status = status;
// this.reason = reason;
// this.headers = headers;
// this.body = body;
// }
//
// /** Request URL. */
// public String getUrl() {
// return url;
// }
//
// /** Status line code. */
// public int getStatus() {
// return status;
// }
//
// /** Status line reason phrase. */
// public String getReason() {
// return reason;
// }
//
// /** An unmodifiable collection of headers. */
// public List<Header> getHeaders() {
// return headers;
// }
//
// /** Response body. May be {@code null}. */
// public TypedInput getBody() {
// return body;
// }
// }
// Path: idobata4j-core/src/test/java/com/uphyca/idobata/TokenAuthenticatorTest.java
import com.uphyca.idobata.http.Client;
import com.uphyca.idobata.http.Header;
import com.uphyca.idobata.http.Request;
import com.uphyca.idobata.http.Response;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import java.util.Collections;
import static org.fest.assertions.api.Assertions.assertThat;
import static org.mockito.BDDMockito.given;
import static org.mockito.BDDMockito.mock;
package com.uphyca.idobata;
@RunWith(MockitoJUnitRunner.class)
public class TokenAuthenticatorTest {
@Mock
Client mClient;
@Test
public void constantTokenString() throws Exception {
ArgumentCaptor<Request> requestCaptor = ArgumentCaptor.forClass(Request.class);
given(mClient.execute(requestCaptor.capture())).willReturn(mock(Response.class));
TokenAuthenticator underTest = new TokenAuthenticator("abc"); | Request request = new Request(null, null, Collections.<Header> emptyList(), null); |
uPhyca/idobata4j | idobata4j-core/src/main/java/com/uphyca/idobata/IdobataImpl.java | // Path: idobata4j-core/src/main/java/com/uphyca/idobata/pusher/PusherBuilder.java
// public class PusherBuilder {
//
// private static final String API_KEY = "44ffe67af1c7035be764";
//
// private PusherOptions options;
//
// /** Options for the Pusher client library to use. */
// public PusherBuilder setOptions(PusherOptions options) {
// this.options = options;
// return this;
// }
//
// public PusherBuilder buildUpon() {
// return new PusherBuilder().setOptions(options);
// }
//
// /**
// * Create the {@link com.pusher.client.Pusher} instances.
// */
// public Pusher build() {
// if (options == null) {
// return new Pusher(API_KEY);
// }
// return new Pusher(API_KEY, options);
// }
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/transform/Converter.java
// public interface Converter {
//
// /**
// * Convert an HTTP response body to a concrete object of the specified type.
// *
// * @param body HTTP response body.
// * @param type Target object type.
// * @return Instance of {@code type} which will be cast by the caller.
// * @throws Exception
// */
// <T> T convert(TypedInput body, Type type) throws ConversionException, IOException;
// }
| import java.util.List;
import com.pusher.client.AuthorizationFailureException;
import com.pusher.client.Authorizer;
import com.pusher.client.Pusher;
import com.pusher.client.PusherOptions;
import com.uphyca.idobata.http.*;
import com.uphyca.idobata.model.*;
import com.uphyca.idobata.pusher.PusherBuilder;
import com.uphyca.idobata.transform.Converter;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.Collections; | /*
* Copyright (C) 2014 uPhyca Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.uphyca.idobata;
/**
* Default implementation of {@link com.uphyca.idobata.Idobata}
*
* @see com.uphyca.idobata.IdobataBuilder
* @author Sosuke Masui (masui@uphyca.com)
*/
class IdobataImpl implements Idobata {
private final Client client;
private final RequestInterceptor requestInterceptor; | // Path: idobata4j-core/src/main/java/com/uphyca/idobata/pusher/PusherBuilder.java
// public class PusherBuilder {
//
// private static final String API_KEY = "44ffe67af1c7035be764";
//
// private PusherOptions options;
//
// /** Options for the Pusher client library to use. */
// public PusherBuilder setOptions(PusherOptions options) {
// this.options = options;
// return this;
// }
//
// public PusherBuilder buildUpon() {
// return new PusherBuilder().setOptions(options);
// }
//
// /**
// * Create the {@link com.pusher.client.Pusher} instances.
// */
// public Pusher build() {
// if (options == null) {
// return new Pusher(API_KEY);
// }
// return new Pusher(API_KEY, options);
// }
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/transform/Converter.java
// public interface Converter {
//
// /**
// * Convert an HTTP response body to a concrete object of the specified type.
// *
// * @param body HTTP response body.
// * @param type Target object type.
// * @return Instance of {@code type} which will be cast by the caller.
// * @throws Exception
// */
// <T> T convert(TypedInput body, Type type) throws ConversionException, IOException;
// }
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/IdobataImpl.java
import java.util.List;
import com.pusher.client.AuthorizationFailureException;
import com.pusher.client.Authorizer;
import com.pusher.client.Pusher;
import com.pusher.client.PusherOptions;
import com.uphyca.idobata.http.*;
import com.uphyca.idobata.model.*;
import com.uphyca.idobata.pusher.PusherBuilder;
import com.uphyca.idobata.transform.Converter;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.Collections;
/*
* Copyright (C) 2014 uPhyca Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.uphyca.idobata;
/**
* Default implementation of {@link com.uphyca.idobata.Idobata}
*
* @see com.uphyca.idobata.IdobataBuilder
* @author Sosuke Masui (masui@uphyca.com)
*/
class IdobataImpl implements Idobata {
private final Client client;
private final RequestInterceptor requestInterceptor; | private final Converter converter; |
uPhyca/idobata4j | idobata4j-core/src/main/java/com/uphyca/idobata/IdobataImpl.java | // Path: idobata4j-core/src/main/java/com/uphyca/idobata/pusher/PusherBuilder.java
// public class PusherBuilder {
//
// private static final String API_KEY = "44ffe67af1c7035be764";
//
// private PusherOptions options;
//
// /** Options for the Pusher client library to use. */
// public PusherBuilder setOptions(PusherOptions options) {
// this.options = options;
// return this;
// }
//
// public PusherBuilder buildUpon() {
// return new PusherBuilder().setOptions(options);
// }
//
// /**
// * Create the {@link com.pusher.client.Pusher} instances.
// */
// public Pusher build() {
// if (options == null) {
// return new Pusher(API_KEY);
// }
// return new Pusher(API_KEY, options);
// }
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/transform/Converter.java
// public interface Converter {
//
// /**
// * Convert an HTTP response body to a concrete object of the specified type.
// *
// * @param body HTTP response body.
// * @param type Target object type.
// * @return Instance of {@code type} which will be cast by the caller.
// * @throws Exception
// */
// <T> T convert(TypedInput body, Type type) throws ConversionException, IOException;
// }
| import java.util.List;
import com.pusher.client.AuthorizationFailureException;
import com.pusher.client.Authorizer;
import com.pusher.client.Pusher;
import com.pusher.client.PusherOptions;
import com.uphyca.idobata.http.*;
import com.uphyca.idobata.model.*;
import com.uphyca.idobata.pusher.PusherBuilder;
import com.uphyca.idobata.transform.Converter;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.Collections; | /*
* Copyright (C) 2014 uPhyca Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.uphyca.idobata;
/**
* Default implementation of {@link com.uphyca.idobata.Idobata}
*
* @see com.uphyca.idobata.IdobataBuilder
* @author Sosuke Masui (masui@uphyca.com)
*/
class IdobataImpl implements Idobata {
private final Client client;
private final RequestInterceptor requestInterceptor;
private final Converter converter; | // Path: idobata4j-core/src/main/java/com/uphyca/idobata/pusher/PusherBuilder.java
// public class PusherBuilder {
//
// private static final String API_KEY = "44ffe67af1c7035be764";
//
// private PusherOptions options;
//
// /** Options for the Pusher client library to use. */
// public PusherBuilder setOptions(PusherOptions options) {
// this.options = options;
// return this;
// }
//
// public PusherBuilder buildUpon() {
// return new PusherBuilder().setOptions(options);
// }
//
// /**
// * Create the {@link com.pusher.client.Pusher} instances.
// */
// public Pusher build() {
// if (options == null) {
// return new Pusher(API_KEY);
// }
// return new Pusher(API_KEY, options);
// }
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/transform/Converter.java
// public interface Converter {
//
// /**
// * Convert an HTTP response body to a concrete object of the specified type.
// *
// * @param body HTTP response body.
// * @param type Target object type.
// * @return Instance of {@code type} which will be cast by the caller.
// * @throws Exception
// */
// <T> T convert(TypedInput body, Type type) throws ConversionException, IOException;
// }
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/IdobataImpl.java
import java.util.List;
import com.pusher.client.AuthorizationFailureException;
import com.pusher.client.Authorizer;
import com.pusher.client.Pusher;
import com.pusher.client.PusherOptions;
import com.uphyca.idobata.http.*;
import com.uphyca.idobata.model.*;
import com.uphyca.idobata.pusher.PusherBuilder;
import com.uphyca.idobata.transform.Converter;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.Collections;
/*
* Copyright (C) 2014 uPhyca Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.uphyca.idobata;
/**
* Default implementation of {@link com.uphyca.idobata.Idobata}
*
* @see com.uphyca.idobata.IdobataBuilder
* @author Sosuke Masui (masui@uphyca.com)
*/
class IdobataImpl implements Idobata {
private final Client client;
private final RequestInterceptor requestInterceptor;
private final Converter converter; | private final PusherBuilder pusherBuilder; |
uPhyca/idobata4j | idobata4j-core/src/main/java/com/uphyca/idobata/IdobataStreamImpl.java | // Path: idobata4j-core/src/main/java/com/uphyca/idobata/http/TypedInput.java
// public interface TypedInput {
//
// /** Returns the mime type. */
// String mimeType();
//
// /** Length in bytes. Returns {@code -1} if length is unknown. */
// long length();
//
// /**
// * Read bytes as stream. Unless otherwise specified, this method may only be called once. It is
// * the responsibility of the caller to close the stream.
// */
// InputStream in() throws IOException;
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/pusher/PresenceChannelEventListenerAdapter.java
// public class PresenceChannelEventListenerAdapter implements PresenceChannelEventListener {
//
// @Override
// public void onUsersInformationReceived(String channelName, Set<User> users) {
// //no-op
// }
//
// @Override
// public void userSubscribed(String channelName, User user) {
// //no-op
// }
//
// @Override
// public void userUnsubscribed(String channelName, User user) {
// //no-op
// }
//
// @Override
// public void onAuthenticationFailure(String message, Exception e) {
// //no-op
// }
//
// @Override
// public void onSubscriptionSucceeded(String channelName) {
// //no-op
// }
//
// @Override
// public void onEvent(String channelName, String eventName, String data) {
// //no-op
// }
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/transform/ConversionException.java
// public class ConversionException extends Exception {
//
// public ConversionException() {
// }
//
// public ConversionException(String message) {
// super(message);
// }
//
// public ConversionException(String message, Throwable cause) {
// super(message, cause);
// }
//
// public ConversionException(Throwable cause) {
// super(cause);
// }
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/transform/Converter.java
// public interface Converter {
//
// /**
// * Convert an HTTP response body to a concrete object of the specified type.
// *
// * @param body HTTP response body.
// * @param type Target object type.
// * @return Instance of {@code type} which will be cast by the caller.
// * @throws Exception
// */
// <T> T convert(TypedInput body, Type type) throws ConversionException, IOException;
// }
| import com.pusher.client.Pusher;
import com.pusher.client.channel.PresenceChannel;
import com.pusher.client.connection.ConnectionEventListener;
import com.pusher.client.connection.ConnectionState;
import com.pusher.client.connection.ConnectionStateChange;
import com.uphyca.idobata.event.*;
import com.uphyca.idobata.http.TypedInput;
import com.uphyca.idobata.pusher.PresenceChannelEventListenerAdapter;
import com.uphyca.idobata.transform.ConversionException;
import com.uphyca.idobata.transform.Converter;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.Type;
import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap; | /*
* Copyright (C) 2014 uPhyca Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.uphyca.idobata;
/**
* @author Sosuke Masui (masui@uphyca.com)
*/
class IdobataStreamImpl extends PresenceChannelEventListenerAdapter implements IdobataStream, ConnectionEventListener {
private static final String MESSAGE_CREATED = "message_created";
private static final String MEMBER_STATUS_CHANGED = "member_status_changed";
private static final String ROOM_TOUCHED = "room_touched";
private static final Map<String, Type> TYPE_MAP;
static {
TYPE_MAP = new HashMap<String, Type>();
TYPE_MAP.put(MESSAGE_CREATED, MessageCreatedEvent.class);
TYPE_MAP.put(MEMBER_STATUS_CHANGED, MemberStatusChangedEvent.class);
TYPE_MAP.put(ROOM_TOUCHED, RoomTouchedEvent.class);
}
private final Idobata idobata;
private final String channelName; | // Path: idobata4j-core/src/main/java/com/uphyca/idobata/http/TypedInput.java
// public interface TypedInput {
//
// /** Returns the mime type. */
// String mimeType();
//
// /** Length in bytes. Returns {@code -1} if length is unknown. */
// long length();
//
// /**
// * Read bytes as stream. Unless otherwise specified, this method may only be called once. It is
// * the responsibility of the caller to close the stream.
// */
// InputStream in() throws IOException;
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/pusher/PresenceChannelEventListenerAdapter.java
// public class PresenceChannelEventListenerAdapter implements PresenceChannelEventListener {
//
// @Override
// public void onUsersInformationReceived(String channelName, Set<User> users) {
// //no-op
// }
//
// @Override
// public void userSubscribed(String channelName, User user) {
// //no-op
// }
//
// @Override
// public void userUnsubscribed(String channelName, User user) {
// //no-op
// }
//
// @Override
// public void onAuthenticationFailure(String message, Exception e) {
// //no-op
// }
//
// @Override
// public void onSubscriptionSucceeded(String channelName) {
// //no-op
// }
//
// @Override
// public void onEvent(String channelName, String eventName, String data) {
// //no-op
// }
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/transform/ConversionException.java
// public class ConversionException extends Exception {
//
// public ConversionException() {
// }
//
// public ConversionException(String message) {
// super(message);
// }
//
// public ConversionException(String message, Throwable cause) {
// super(message, cause);
// }
//
// public ConversionException(Throwable cause) {
// super(cause);
// }
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/transform/Converter.java
// public interface Converter {
//
// /**
// * Convert an HTTP response body to a concrete object of the specified type.
// *
// * @param body HTTP response body.
// * @param type Target object type.
// * @return Instance of {@code type} which will be cast by the caller.
// * @throws Exception
// */
// <T> T convert(TypedInput body, Type type) throws ConversionException, IOException;
// }
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/IdobataStreamImpl.java
import com.pusher.client.Pusher;
import com.pusher.client.channel.PresenceChannel;
import com.pusher.client.connection.ConnectionEventListener;
import com.pusher.client.connection.ConnectionState;
import com.pusher.client.connection.ConnectionStateChange;
import com.uphyca.idobata.event.*;
import com.uphyca.idobata.http.TypedInput;
import com.uphyca.idobata.pusher.PresenceChannelEventListenerAdapter;
import com.uphyca.idobata.transform.ConversionException;
import com.uphyca.idobata.transform.Converter;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.Type;
import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
/*
* Copyright (C) 2014 uPhyca Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.uphyca.idobata;
/**
* @author Sosuke Masui (masui@uphyca.com)
*/
class IdobataStreamImpl extends PresenceChannelEventListenerAdapter implements IdobataStream, ConnectionEventListener {
private static final String MESSAGE_CREATED = "message_created";
private static final String MEMBER_STATUS_CHANGED = "member_status_changed";
private static final String ROOM_TOUCHED = "room_touched";
private static final Map<String, Type> TYPE_MAP;
static {
TYPE_MAP = new HashMap<String, Type>();
TYPE_MAP.put(MESSAGE_CREATED, MessageCreatedEvent.class);
TYPE_MAP.put(MEMBER_STATUS_CHANGED, MemberStatusChangedEvent.class);
TYPE_MAP.put(ROOM_TOUCHED, RoomTouchedEvent.class);
}
private final Idobata idobata;
private final String channelName; | private final Converter converter; |
uPhyca/idobata4j | idobata4j-core/src/main/java/com/uphyca/idobata/IdobataStreamImpl.java | // Path: idobata4j-core/src/main/java/com/uphyca/idobata/http/TypedInput.java
// public interface TypedInput {
//
// /** Returns the mime type. */
// String mimeType();
//
// /** Length in bytes. Returns {@code -1} if length is unknown. */
// long length();
//
// /**
// * Read bytes as stream. Unless otherwise specified, this method may only be called once. It is
// * the responsibility of the caller to close the stream.
// */
// InputStream in() throws IOException;
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/pusher/PresenceChannelEventListenerAdapter.java
// public class PresenceChannelEventListenerAdapter implements PresenceChannelEventListener {
//
// @Override
// public void onUsersInformationReceived(String channelName, Set<User> users) {
// //no-op
// }
//
// @Override
// public void userSubscribed(String channelName, User user) {
// //no-op
// }
//
// @Override
// public void userUnsubscribed(String channelName, User user) {
// //no-op
// }
//
// @Override
// public void onAuthenticationFailure(String message, Exception e) {
// //no-op
// }
//
// @Override
// public void onSubscriptionSucceeded(String channelName) {
// //no-op
// }
//
// @Override
// public void onEvent(String channelName, String eventName, String data) {
// //no-op
// }
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/transform/ConversionException.java
// public class ConversionException extends Exception {
//
// public ConversionException() {
// }
//
// public ConversionException(String message) {
// super(message);
// }
//
// public ConversionException(String message, Throwable cause) {
// super(message, cause);
// }
//
// public ConversionException(Throwable cause) {
// super(cause);
// }
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/transform/Converter.java
// public interface Converter {
//
// /**
// * Convert an HTTP response body to a concrete object of the specified type.
// *
// * @param body HTTP response body.
// * @param type Target object type.
// * @return Instance of {@code type} which will be cast by the caller.
// * @throws Exception
// */
// <T> T convert(TypedInput body, Type type) throws ConversionException, IOException;
// }
| import com.pusher.client.Pusher;
import com.pusher.client.channel.PresenceChannel;
import com.pusher.client.connection.ConnectionEventListener;
import com.pusher.client.connection.ConnectionState;
import com.pusher.client.connection.ConnectionStateChange;
import com.uphyca.idobata.event.*;
import com.uphyca.idobata.http.TypedInput;
import com.uphyca.idobata.pusher.PresenceChannelEventListenerAdapter;
import com.uphyca.idobata.transform.ConversionException;
import com.uphyca.idobata.transform.Converter;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.Type;
import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap; | if (listeners == null) {
listenerMap.put(event, listeners = new LinkedHashSet<Listener<?>>());
}
listeners.add(listener);
}
private void publishError(Exception e) {
IdobataError idobataError = new IdobataError(e);
idobataError.fillInStackTrace();
errorListener.onError(idobataError);
}
private void publishEvent(String eventName, Object event) {
Set<Listener<?>> listeners = listenerMap.get(eventName);
if (listeners == null) {
return;
}
for (Listener each : listeners) {
each.onEvent(event);
}
}
@Override
public void onEvent(String channelName, String eventName, String data) {
try {
Type type = TYPE_MAP.get(eventName);
if (type == null) {
throw new IllegalStateException();
}
publishEvent(eventName, converter.convert(new JsonTypedInput(data), type)); | // Path: idobata4j-core/src/main/java/com/uphyca/idobata/http/TypedInput.java
// public interface TypedInput {
//
// /** Returns the mime type. */
// String mimeType();
//
// /** Length in bytes. Returns {@code -1} if length is unknown. */
// long length();
//
// /**
// * Read bytes as stream. Unless otherwise specified, this method may only be called once. It is
// * the responsibility of the caller to close the stream.
// */
// InputStream in() throws IOException;
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/pusher/PresenceChannelEventListenerAdapter.java
// public class PresenceChannelEventListenerAdapter implements PresenceChannelEventListener {
//
// @Override
// public void onUsersInformationReceived(String channelName, Set<User> users) {
// //no-op
// }
//
// @Override
// public void userSubscribed(String channelName, User user) {
// //no-op
// }
//
// @Override
// public void userUnsubscribed(String channelName, User user) {
// //no-op
// }
//
// @Override
// public void onAuthenticationFailure(String message, Exception e) {
// //no-op
// }
//
// @Override
// public void onSubscriptionSucceeded(String channelName) {
// //no-op
// }
//
// @Override
// public void onEvent(String channelName, String eventName, String data) {
// //no-op
// }
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/transform/ConversionException.java
// public class ConversionException extends Exception {
//
// public ConversionException() {
// }
//
// public ConversionException(String message) {
// super(message);
// }
//
// public ConversionException(String message, Throwable cause) {
// super(message, cause);
// }
//
// public ConversionException(Throwable cause) {
// super(cause);
// }
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/transform/Converter.java
// public interface Converter {
//
// /**
// * Convert an HTTP response body to a concrete object of the specified type.
// *
// * @param body HTTP response body.
// * @param type Target object type.
// * @return Instance of {@code type} which will be cast by the caller.
// * @throws Exception
// */
// <T> T convert(TypedInput body, Type type) throws ConversionException, IOException;
// }
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/IdobataStreamImpl.java
import com.pusher.client.Pusher;
import com.pusher.client.channel.PresenceChannel;
import com.pusher.client.connection.ConnectionEventListener;
import com.pusher.client.connection.ConnectionState;
import com.pusher.client.connection.ConnectionStateChange;
import com.uphyca.idobata.event.*;
import com.uphyca.idobata.http.TypedInput;
import com.uphyca.idobata.pusher.PresenceChannelEventListenerAdapter;
import com.uphyca.idobata.transform.ConversionException;
import com.uphyca.idobata.transform.Converter;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.Type;
import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
if (listeners == null) {
listenerMap.put(event, listeners = new LinkedHashSet<Listener<?>>());
}
listeners.add(listener);
}
private void publishError(Exception e) {
IdobataError idobataError = new IdobataError(e);
idobataError.fillInStackTrace();
errorListener.onError(idobataError);
}
private void publishEvent(String eventName, Object event) {
Set<Listener<?>> listeners = listenerMap.get(eventName);
if (listeners == null) {
return;
}
for (Listener each : listeners) {
each.onEvent(event);
}
}
@Override
public void onEvent(String channelName, String eventName, String data) {
try {
Type type = TYPE_MAP.get(eventName);
if (type == null) {
throw new IllegalStateException();
}
publishEvent(eventName, converter.convert(new JsonTypedInput(data), type)); | } catch (ConversionException e) { |
uPhyca/idobata4j | idobata4j-core/src/main/java/com/uphyca/idobata/IdobataStreamImpl.java | // Path: idobata4j-core/src/main/java/com/uphyca/idobata/http/TypedInput.java
// public interface TypedInput {
//
// /** Returns the mime type. */
// String mimeType();
//
// /** Length in bytes. Returns {@code -1} if length is unknown. */
// long length();
//
// /**
// * Read bytes as stream. Unless otherwise specified, this method may only be called once. It is
// * the responsibility of the caller to close the stream.
// */
// InputStream in() throws IOException;
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/pusher/PresenceChannelEventListenerAdapter.java
// public class PresenceChannelEventListenerAdapter implements PresenceChannelEventListener {
//
// @Override
// public void onUsersInformationReceived(String channelName, Set<User> users) {
// //no-op
// }
//
// @Override
// public void userSubscribed(String channelName, User user) {
// //no-op
// }
//
// @Override
// public void userUnsubscribed(String channelName, User user) {
// //no-op
// }
//
// @Override
// public void onAuthenticationFailure(String message, Exception e) {
// //no-op
// }
//
// @Override
// public void onSubscriptionSucceeded(String channelName) {
// //no-op
// }
//
// @Override
// public void onEvent(String channelName, String eventName, String data) {
// //no-op
// }
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/transform/ConversionException.java
// public class ConversionException extends Exception {
//
// public ConversionException() {
// }
//
// public ConversionException(String message) {
// super(message);
// }
//
// public ConversionException(String message, Throwable cause) {
// super(message, cause);
// }
//
// public ConversionException(Throwable cause) {
// super(cause);
// }
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/transform/Converter.java
// public interface Converter {
//
// /**
// * Convert an HTTP response body to a concrete object of the specified type.
// *
// * @param body HTTP response body.
// * @param type Target object type.
// * @return Instance of {@code type} which will be cast by the caller.
// * @throws Exception
// */
// <T> T convert(TypedInput body, Type type) throws ConversionException, IOException;
// }
| import com.pusher.client.Pusher;
import com.pusher.client.channel.PresenceChannel;
import com.pusher.client.connection.ConnectionEventListener;
import com.pusher.client.connection.ConnectionState;
import com.pusher.client.connection.ConnectionStateChange;
import com.uphyca.idobata.event.*;
import com.uphyca.idobata.http.TypedInput;
import com.uphyca.idobata.pusher.PresenceChannelEventListenerAdapter;
import com.uphyca.idobata.transform.ConversionException;
import com.uphyca.idobata.transform.Converter;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.Type;
import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap; | case DISCONNECTED:
connectionListener.closed(new ConnectionEventValue(ConnectionEvent.CLOSED));
break;
}
}
@Override
public void onError(String message, String code, Exception e) {
publishError(e);
}
private static final ErrorListener EMPTY_ERROR_LISTENER = new ErrorListener() {
@Override
public void onError(IdobataError error) {
//no-op
}
};
private static final ConnectionListener EMPTY_CONNECTION_LISTENER = new ConnectionListener() {
@Override
public void closed(ConnectionEvent event) {
//no-op
}
@Override
public void opened(ConnectionEvent event) {
//no-op
}
};
| // Path: idobata4j-core/src/main/java/com/uphyca/idobata/http/TypedInput.java
// public interface TypedInput {
//
// /** Returns the mime type. */
// String mimeType();
//
// /** Length in bytes. Returns {@code -1} if length is unknown. */
// long length();
//
// /**
// * Read bytes as stream. Unless otherwise specified, this method may only be called once. It is
// * the responsibility of the caller to close the stream.
// */
// InputStream in() throws IOException;
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/pusher/PresenceChannelEventListenerAdapter.java
// public class PresenceChannelEventListenerAdapter implements PresenceChannelEventListener {
//
// @Override
// public void onUsersInformationReceived(String channelName, Set<User> users) {
// //no-op
// }
//
// @Override
// public void userSubscribed(String channelName, User user) {
// //no-op
// }
//
// @Override
// public void userUnsubscribed(String channelName, User user) {
// //no-op
// }
//
// @Override
// public void onAuthenticationFailure(String message, Exception e) {
// //no-op
// }
//
// @Override
// public void onSubscriptionSucceeded(String channelName) {
// //no-op
// }
//
// @Override
// public void onEvent(String channelName, String eventName, String data) {
// //no-op
// }
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/transform/ConversionException.java
// public class ConversionException extends Exception {
//
// public ConversionException() {
// }
//
// public ConversionException(String message) {
// super(message);
// }
//
// public ConversionException(String message, Throwable cause) {
// super(message, cause);
// }
//
// public ConversionException(Throwable cause) {
// super(cause);
// }
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/transform/Converter.java
// public interface Converter {
//
// /**
// * Convert an HTTP response body to a concrete object of the specified type.
// *
// * @param body HTTP response body.
// * @param type Target object type.
// * @return Instance of {@code type} which will be cast by the caller.
// * @throws Exception
// */
// <T> T convert(TypedInput body, Type type) throws ConversionException, IOException;
// }
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/IdobataStreamImpl.java
import com.pusher.client.Pusher;
import com.pusher.client.channel.PresenceChannel;
import com.pusher.client.connection.ConnectionEventListener;
import com.pusher.client.connection.ConnectionState;
import com.pusher.client.connection.ConnectionStateChange;
import com.uphyca.idobata.event.*;
import com.uphyca.idobata.http.TypedInput;
import com.uphyca.idobata.pusher.PresenceChannelEventListenerAdapter;
import com.uphyca.idobata.transform.ConversionException;
import com.uphyca.idobata.transform.Converter;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.Type;
import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
case DISCONNECTED:
connectionListener.closed(new ConnectionEventValue(ConnectionEvent.CLOSED));
break;
}
}
@Override
public void onError(String message, String code, Exception e) {
publishError(e);
}
private static final ErrorListener EMPTY_ERROR_LISTENER = new ErrorListener() {
@Override
public void onError(IdobataError error) {
//no-op
}
};
private static final ConnectionListener EMPTY_CONNECTION_LISTENER = new ConnectionListener() {
@Override
public void closed(ConnectionEvent event) {
//no-op
}
@Override
public void opened(ConnectionEvent event) {
//no-op
}
};
| private static final class JsonTypedInput implements TypedInput { |
uPhyca/idobata4j | idobata4j-core/src/main/java/com/uphyca/idobata/IdobataStream.java | // Path: idobata4j-core/src/main/java/com/uphyca/idobata/event/ConnectionEvent.java
// public interface ConnectionEvent extends Serializable {
//
// public static final int CLOSED = 0;
// public static final int OPENED = 1;
//
// int getType();
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/event/MemberStatusChangedEvent.java
// public interface MemberStatusChangedEvent extends Serializable {
// long getId();
//
// String getStatus();
//
// String getType();
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/event/MessageCreatedEvent.java
// public interface MessageCreatedEvent extends Serializable {
// long getId();
//
// String getBody();
//
// String getBodyPlain();
//
// List<String> getImageUrls();
//
// boolean isMultiline();
//
// List<Long> getMentions();
//
// String getCreatedAt();
//
// long getRoomId();
//
// String getRoomName();
//
// String getOrganizationSlug();
//
// String getSenderType();
//
// long getSenderId();
//
// String getSenderName();
//
// String getSenderIconUrl();
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/event/RoomTouchedEvent.java
// public interface RoomTouchedEvent extends Serializable {
//
// long getRoomId();
// }
| import com.uphyca.idobata.event.ConnectionEvent;
import com.uphyca.idobata.event.MemberStatusChangedEvent;
import com.uphyca.idobata.event.MessageCreatedEvent;
import com.uphyca.idobata.event.RoomTouchedEvent;
import java.io.Closeable; | /*
* Copyright (C) 2014 uPhyca Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.uphyca.idobata;
/**
* Represents <a href="https://idobata.io/">Idobata</a> WebSocket API.
*
* @author Sosuke Masui (masui@uphyca.com)
*/
public interface IdobataStream extends Closeable {
public interface Listener<T> {
void onEvent(T event);
}
public interface ConnectionListener { | // Path: idobata4j-core/src/main/java/com/uphyca/idobata/event/ConnectionEvent.java
// public interface ConnectionEvent extends Serializable {
//
// public static final int CLOSED = 0;
// public static final int OPENED = 1;
//
// int getType();
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/event/MemberStatusChangedEvent.java
// public interface MemberStatusChangedEvent extends Serializable {
// long getId();
//
// String getStatus();
//
// String getType();
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/event/MessageCreatedEvent.java
// public interface MessageCreatedEvent extends Serializable {
// long getId();
//
// String getBody();
//
// String getBodyPlain();
//
// List<String> getImageUrls();
//
// boolean isMultiline();
//
// List<Long> getMentions();
//
// String getCreatedAt();
//
// long getRoomId();
//
// String getRoomName();
//
// String getOrganizationSlug();
//
// String getSenderType();
//
// long getSenderId();
//
// String getSenderName();
//
// String getSenderIconUrl();
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/event/RoomTouchedEvent.java
// public interface RoomTouchedEvent extends Serializable {
//
// long getRoomId();
// }
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/IdobataStream.java
import com.uphyca.idobata.event.ConnectionEvent;
import com.uphyca.idobata.event.MemberStatusChangedEvent;
import com.uphyca.idobata.event.MessageCreatedEvent;
import com.uphyca.idobata.event.RoomTouchedEvent;
import java.io.Closeable;
/*
* Copyright (C) 2014 uPhyca Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.uphyca.idobata;
/**
* Represents <a href="https://idobata.io/">Idobata</a> WebSocket API.
*
* @author Sosuke Masui (masui@uphyca.com)
*/
public interface IdobataStream extends Closeable {
public interface Listener<T> {
void onEvent(T event);
}
public interface ConnectionListener { | void closed(ConnectionEvent event); |
uPhyca/idobata4j | idobata4j-core/src/main/java/com/uphyca/idobata/IdobataStream.java | // Path: idobata4j-core/src/main/java/com/uphyca/idobata/event/ConnectionEvent.java
// public interface ConnectionEvent extends Serializable {
//
// public static final int CLOSED = 0;
// public static final int OPENED = 1;
//
// int getType();
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/event/MemberStatusChangedEvent.java
// public interface MemberStatusChangedEvent extends Serializable {
// long getId();
//
// String getStatus();
//
// String getType();
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/event/MessageCreatedEvent.java
// public interface MessageCreatedEvent extends Serializable {
// long getId();
//
// String getBody();
//
// String getBodyPlain();
//
// List<String> getImageUrls();
//
// boolean isMultiline();
//
// List<Long> getMentions();
//
// String getCreatedAt();
//
// long getRoomId();
//
// String getRoomName();
//
// String getOrganizationSlug();
//
// String getSenderType();
//
// long getSenderId();
//
// String getSenderName();
//
// String getSenderIconUrl();
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/event/RoomTouchedEvent.java
// public interface RoomTouchedEvent extends Serializable {
//
// long getRoomId();
// }
| import com.uphyca.idobata.event.ConnectionEvent;
import com.uphyca.idobata.event.MemberStatusChangedEvent;
import com.uphyca.idobata.event.MessageCreatedEvent;
import com.uphyca.idobata.event.RoomTouchedEvent;
import java.io.Closeable; | /*
* Copyright (C) 2014 uPhyca Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.uphyca.idobata;
/**
* Represents <a href="https://idobata.io/">Idobata</a> WebSocket API.
*
* @author Sosuke Masui (masui@uphyca.com)
*/
public interface IdobataStream extends Closeable {
public interface Listener<T> {
void onEvent(T event);
}
public interface ConnectionListener {
void closed(ConnectionEvent event);
void opened(ConnectionEvent event);
}
void open();
/**
* event: message_created
*/ | // Path: idobata4j-core/src/main/java/com/uphyca/idobata/event/ConnectionEvent.java
// public interface ConnectionEvent extends Serializable {
//
// public static final int CLOSED = 0;
// public static final int OPENED = 1;
//
// int getType();
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/event/MemberStatusChangedEvent.java
// public interface MemberStatusChangedEvent extends Serializable {
// long getId();
//
// String getStatus();
//
// String getType();
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/event/MessageCreatedEvent.java
// public interface MessageCreatedEvent extends Serializable {
// long getId();
//
// String getBody();
//
// String getBodyPlain();
//
// List<String> getImageUrls();
//
// boolean isMultiline();
//
// List<Long> getMentions();
//
// String getCreatedAt();
//
// long getRoomId();
//
// String getRoomName();
//
// String getOrganizationSlug();
//
// String getSenderType();
//
// long getSenderId();
//
// String getSenderName();
//
// String getSenderIconUrl();
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/event/RoomTouchedEvent.java
// public interface RoomTouchedEvent extends Serializable {
//
// long getRoomId();
// }
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/IdobataStream.java
import com.uphyca.idobata.event.ConnectionEvent;
import com.uphyca.idobata.event.MemberStatusChangedEvent;
import com.uphyca.idobata.event.MessageCreatedEvent;
import com.uphyca.idobata.event.RoomTouchedEvent;
import java.io.Closeable;
/*
* Copyright (C) 2014 uPhyca Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.uphyca.idobata;
/**
* Represents <a href="https://idobata.io/">Idobata</a> WebSocket API.
*
* @author Sosuke Masui (masui@uphyca.com)
*/
public interface IdobataStream extends Closeable {
public interface Listener<T> {
void onEvent(T event);
}
public interface ConnectionListener {
void closed(ConnectionEvent event);
void opened(ConnectionEvent event);
}
void open();
/**
* event: message_created
*/ | IdobataStream subscribeMessageCreated(Listener<MessageCreatedEvent> listener); |
uPhyca/idobata4j | idobata4j-core/src/main/java/com/uphyca/idobata/IdobataStream.java | // Path: idobata4j-core/src/main/java/com/uphyca/idobata/event/ConnectionEvent.java
// public interface ConnectionEvent extends Serializable {
//
// public static final int CLOSED = 0;
// public static final int OPENED = 1;
//
// int getType();
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/event/MemberStatusChangedEvent.java
// public interface MemberStatusChangedEvent extends Serializable {
// long getId();
//
// String getStatus();
//
// String getType();
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/event/MessageCreatedEvent.java
// public interface MessageCreatedEvent extends Serializable {
// long getId();
//
// String getBody();
//
// String getBodyPlain();
//
// List<String> getImageUrls();
//
// boolean isMultiline();
//
// List<Long> getMentions();
//
// String getCreatedAt();
//
// long getRoomId();
//
// String getRoomName();
//
// String getOrganizationSlug();
//
// String getSenderType();
//
// long getSenderId();
//
// String getSenderName();
//
// String getSenderIconUrl();
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/event/RoomTouchedEvent.java
// public interface RoomTouchedEvent extends Serializable {
//
// long getRoomId();
// }
| import com.uphyca.idobata.event.ConnectionEvent;
import com.uphyca.idobata.event.MemberStatusChangedEvent;
import com.uphyca.idobata.event.MessageCreatedEvent;
import com.uphyca.idobata.event.RoomTouchedEvent;
import java.io.Closeable; | /*
* Copyright (C) 2014 uPhyca Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.uphyca.idobata;
/**
* Represents <a href="https://idobata.io/">Idobata</a> WebSocket API.
*
* @author Sosuke Masui (masui@uphyca.com)
*/
public interface IdobataStream extends Closeable {
public interface Listener<T> {
void onEvent(T event);
}
public interface ConnectionListener {
void closed(ConnectionEvent event);
void opened(ConnectionEvent event);
}
void open();
/**
* event: message_created
*/
IdobataStream subscribeMessageCreated(Listener<MessageCreatedEvent> listener);
/**
* event: member_status_changed
*/ | // Path: idobata4j-core/src/main/java/com/uphyca/idobata/event/ConnectionEvent.java
// public interface ConnectionEvent extends Serializable {
//
// public static final int CLOSED = 0;
// public static final int OPENED = 1;
//
// int getType();
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/event/MemberStatusChangedEvent.java
// public interface MemberStatusChangedEvent extends Serializable {
// long getId();
//
// String getStatus();
//
// String getType();
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/event/MessageCreatedEvent.java
// public interface MessageCreatedEvent extends Serializable {
// long getId();
//
// String getBody();
//
// String getBodyPlain();
//
// List<String> getImageUrls();
//
// boolean isMultiline();
//
// List<Long> getMentions();
//
// String getCreatedAt();
//
// long getRoomId();
//
// String getRoomName();
//
// String getOrganizationSlug();
//
// String getSenderType();
//
// long getSenderId();
//
// String getSenderName();
//
// String getSenderIconUrl();
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/event/RoomTouchedEvent.java
// public interface RoomTouchedEvent extends Serializable {
//
// long getRoomId();
// }
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/IdobataStream.java
import com.uphyca.idobata.event.ConnectionEvent;
import com.uphyca.idobata.event.MemberStatusChangedEvent;
import com.uphyca.idobata.event.MessageCreatedEvent;
import com.uphyca.idobata.event.RoomTouchedEvent;
import java.io.Closeable;
/*
* Copyright (C) 2014 uPhyca Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.uphyca.idobata;
/**
* Represents <a href="https://idobata.io/">Idobata</a> WebSocket API.
*
* @author Sosuke Masui (masui@uphyca.com)
*/
public interface IdobataStream extends Closeable {
public interface Listener<T> {
void onEvent(T event);
}
public interface ConnectionListener {
void closed(ConnectionEvent event);
void opened(ConnectionEvent event);
}
void open();
/**
* event: message_created
*/
IdobataStream subscribeMessageCreated(Listener<MessageCreatedEvent> listener);
/**
* event: member_status_changed
*/ | IdobataStream subscribeMemberStatusChanged(Listener<MemberStatusChangedEvent> listener); |
uPhyca/idobata4j | idobata4j-core/src/main/java/com/uphyca/idobata/IdobataStream.java | // Path: idobata4j-core/src/main/java/com/uphyca/idobata/event/ConnectionEvent.java
// public interface ConnectionEvent extends Serializable {
//
// public static final int CLOSED = 0;
// public static final int OPENED = 1;
//
// int getType();
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/event/MemberStatusChangedEvent.java
// public interface MemberStatusChangedEvent extends Serializable {
// long getId();
//
// String getStatus();
//
// String getType();
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/event/MessageCreatedEvent.java
// public interface MessageCreatedEvent extends Serializable {
// long getId();
//
// String getBody();
//
// String getBodyPlain();
//
// List<String> getImageUrls();
//
// boolean isMultiline();
//
// List<Long> getMentions();
//
// String getCreatedAt();
//
// long getRoomId();
//
// String getRoomName();
//
// String getOrganizationSlug();
//
// String getSenderType();
//
// long getSenderId();
//
// String getSenderName();
//
// String getSenderIconUrl();
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/event/RoomTouchedEvent.java
// public interface RoomTouchedEvent extends Serializable {
//
// long getRoomId();
// }
| import com.uphyca.idobata.event.ConnectionEvent;
import com.uphyca.idobata.event.MemberStatusChangedEvent;
import com.uphyca.idobata.event.MessageCreatedEvent;
import com.uphyca.idobata.event.RoomTouchedEvent;
import java.io.Closeable; | /*
* Copyright (C) 2014 uPhyca Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.uphyca.idobata;
/**
* Represents <a href="https://idobata.io/">Idobata</a> WebSocket API.
*
* @author Sosuke Masui (masui@uphyca.com)
*/
public interface IdobataStream extends Closeable {
public interface Listener<T> {
void onEvent(T event);
}
public interface ConnectionListener {
void closed(ConnectionEvent event);
void opened(ConnectionEvent event);
}
void open();
/**
* event: message_created
*/
IdobataStream subscribeMessageCreated(Listener<MessageCreatedEvent> listener);
/**
* event: member_status_changed
*/
IdobataStream subscribeMemberStatusChanged(Listener<MemberStatusChangedEvent> listener);
/**
* event: room_touched
*/ | // Path: idobata4j-core/src/main/java/com/uphyca/idobata/event/ConnectionEvent.java
// public interface ConnectionEvent extends Serializable {
//
// public static final int CLOSED = 0;
// public static final int OPENED = 1;
//
// int getType();
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/event/MemberStatusChangedEvent.java
// public interface MemberStatusChangedEvent extends Serializable {
// long getId();
//
// String getStatus();
//
// String getType();
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/event/MessageCreatedEvent.java
// public interface MessageCreatedEvent extends Serializable {
// long getId();
//
// String getBody();
//
// String getBodyPlain();
//
// List<String> getImageUrls();
//
// boolean isMultiline();
//
// List<Long> getMentions();
//
// String getCreatedAt();
//
// long getRoomId();
//
// String getRoomName();
//
// String getOrganizationSlug();
//
// String getSenderType();
//
// long getSenderId();
//
// String getSenderName();
//
// String getSenderIconUrl();
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/event/RoomTouchedEvent.java
// public interface RoomTouchedEvent extends Serializable {
//
// long getRoomId();
// }
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/IdobataStream.java
import com.uphyca.idobata.event.ConnectionEvent;
import com.uphyca.idobata.event.MemberStatusChangedEvent;
import com.uphyca.idobata.event.MessageCreatedEvent;
import com.uphyca.idobata.event.RoomTouchedEvent;
import java.io.Closeable;
/*
* Copyright (C) 2014 uPhyca Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.uphyca.idobata;
/**
* Represents <a href="https://idobata.io/">Idobata</a> WebSocket API.
*
* @author Sosuke Masui (masui@uphyca.com)
*/
public interface IdobataStream extends Closeable {
public interface Listener<T> {
void onEvent(T event);
}
public interface ConnectionListener {
void closed(ConnectionEvent event);
void opened(ConnectionEvent event);
}
void open();
/**
* event: message_created
*/
IdobataStream subscribeMessageCreated(Listener<MessageCreatedEvent> listener);
/**
* event: member_status_changed
*/
IdobataStream subscribeMemberStatusChanged(Listener<MemberStatusChangedEvent> listener);
/**
* event: room_touched
*/ | IdobataStream subscribeRoomTouched(Listener<RoomTouchedEvent> listener); |
uPhyca/idobata4j | idobata4j-core/src/test/java/com/uphyca/idobata/IdobataTest.java | // Path: idobata4j-core/src/main/java/com/uphyca/idobata/http/Client.java
// public interface Client {
//
// /**
// * Synchronously execute an HTTP represented by {@code request} and encapsulate all response data
// * into a {@link Response} instance.
// */
// Response execute(Request request) throws IOException;
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/http/Request.java
// public class Request {
//
// private final String method;
// private final String url;
// private final List<Header> headers;
// private final TypedOutput body;
//
// public Request(String method, String url, List<Header> headers, TypedOutput body) {
// this.method = method;
// this.url = url;
// this.headers = headers;
// this.body = body;
// }
//
// /** HTTP method verb. */
// public String getMethod() {
// return method;
// }
//
// /** Target URL. */
// public String getUrl() {
// return url;
// }
//
// /** Returns an unmodifiable list of headers, never {@code null}. */
// public List<Header> getHeaders() {
// return headers;
// }
//
// /** Returns the request body or {@code null}. */
// public TypedOutput getBody() {
// return body;
// }
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/http/Response.java
// public class Response {
//
// private final String url;
// private final int status;
// private final String reason;
// private final List<Header> headers;
// private final TypedInput body;
//
// public Response(String url, int status, String reason, List<Header> headers, TypedInput body) {
// this.url = url;
// this.status = status;
// this.reason = reason;
// this.headers = headers;
// this.body = body;
// }
//
// /** Request URL. */
// public String getUrl() {
// return url;
// }
//
// /** Status line code. */
// public int getStatus() {
// return status;
// }
//
// /** Status line reason phrase. */
// public String getReason() {
// return reason;
// }
//
// /** An unmodifiable collection of headers. */
// public List<Header> getHeaders() {
// return headers;
// }
//
// /** Response body. May be {@code null}. */
// public TypedInput getBody() {
// return body;
// }
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/http/TypedInput.java
// public interface TypedInput {
//
// /** Returns the mime type. */
// String mimeType();
//
// /** Length in bytes. Returns {@code -1} if length is unknown. */
// long length();
//
// /**
// * Read bytes as stream. Unless otherwise specified, this method may only be called once. It is
// * the responsibility of the caller to close the stream.
// */
// InputStream in() throws IOException;
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/pusher/PusherBuilder.java
// public class PusherBuilder {
//
// private static final String API_KEY = "44ffe67af1c7035be764";
//
// private PusherOptions options;
//
// /** Options for the Pusher client library to use. */
// public PusherBuilder setOptions(PusherOptions options) {
// this.options = options;
// return this;
// }
//
// public PusherBuilder buildUpon() {
// return new PusherBuilder().setOptions(options);
// }
//
// /**
// * Create the {@link com.pusher.client.Pusher} instances.
// */
// public Pusher build() {
// if (options == null) {
// return new Pusher(API_KEY);
// }
// return new Pusher(API_KEY, options);
// }
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/transform/Converter.java
// public interface Converter {
//
// /**
// * Convert an HTTP response body to a concrete object of the specified type.
// *
// * @param body HTTP response body.
// * @param type Target object type.
// * @return Instance of {@code type} which will be cast by the caller.
// * @throws Exception
// */
// <T> T convert(TypedInput body, Type type) throws ConversionException, IOException;
// }
| import com.pusher.client.Pusher;
import com.uphyca.idobata.http.Client;
import com.uphyca.idobata.http.Request;
import com.uphyca.idobata.http.Response;
import com.uphyca.idobata.http.TypedInput;
import com.uphyca.idobata.model.*;
import com.uphyca.idobata.pusher.PusherBuilder;
import com.uphyca.idobata.transform.Converter;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import static org.fest.assertions.api.Assertions.assertThat;
import static org.mockito.BDDMockito.given;
import static org.mockito.Matchers.same;
import static org.mockito.Mockito.*; | /*
* Copyright (C) 2014 uPhyca Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.uphyca.idobata;
/**
* @author Sosuke Masui (masui@uphyca.com)
*/
@RunWith(MockitoJUnitRunner.class)
public class IdobataTest {
Idobata underTest;
@Mock | // Path: idobata4j-core/src/main/java/com/uphyca/idobata/http/Client.java
// public interface Client {
//
// /**
// * Synchronously execute an HTTP represented by {@code request} and encapsulate all response data
// * into a {@link Response} instance.
// */
// Response execute(Request request) throws IOException;
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/http/Request.java
// public class Request {
//
// private final String method;
// private final String url;
// private final List<Header> headers;
// private final TypedOutput body;
//
// public Request(String method, String url, List<Header> headers, TypedOutput body) {
// this.method = method;
// this.url = url;
// this.headers = headers;
// this.body = body;
// }
//
// /** HTTP method verb. */
// public String getMethod() {
// return method;
// }
//
// /** Target URL. */
// public String getUrl() {
// return url;
// }
//
// /** Returns an unmodifiable list of headers, never {@code null}. */
// public List<Header> getHeaders() {
// return headers;
// }
//
// /** Returns the request body or {@code null}. */
// public TypedOutput getBody() {
// return body;
// }
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/http/Response.java
// public class Response {
//
// private final String url;
// private final int status;
// private final String reason;
// private final List<Header> headers;
// private final TypedInput body;
//
// public Response(String url, int status, String reason, List<Header> headers, TypedInput body) {
// this.url = url;
// this.status = status;
// this.reason = reason;
// this.headers = headers;
// this.body = body;
// }
//
// /** Request URL. */
// public String getUrl() {
// return url;
// }
//
// /** Status line code. */
// public int getStatus() {
// return status;
// }
//
// /** Status line reason phrase. */
// public String getReason() {
// return reason;
// }
//
// /** An unmodifiable collection of headers. */
// public List<Header> getHeaders() {
// return headers;
// }
//
// /** Response body. May be {@code null}. */
// public TypedInput getBody() {
// return body;
// }
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/http/TypedInput.java
// public interface TypedInput {
//
// /** Returns the mime type. */
// String mimeType();
//
// /** Length in bytes. Returns {@code -1} if length is unknown. */
// long length();
//
// /**
// * Read bytes as stream. Unless otherwise specified, this method may only be called once. It is
// * the responsibility of the caller to close the stream.
// */
// InputStream in() throws IOException;
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/pusher/PusherBuilder.java
// public class PusherBuilder {
//
// private static final String API_KEY = "44ffe67af1c7035be764";
//
// private PusherOptions options;
//
// /** Options for the Pusher client library to use. */
// public PusherBuilder setOptions(PusherOptions options) {
// this.options = options;
// return this;
// }
//
// public PusherBuilder buildUpon() {
// return new PusherBuilder().setOptions(options);
// }
//
// /**
// * Create the {@link com.pusher.client.Pusher} instances.
// */
// public Pusher build() {
// if (options == null) {
// return new Pusher(API_KEY);
// }
// return new Pusher(API_KEY, options);
// }
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/transform/Converter.java
// public interface Converter {
//
// /**
// * Convert an HTTP response body to a concrete object of the specified type.
// *
// * @param body HTTP response body.
// * @param type Target object type.
// * @return Instance of {@code type} which will be cast by the caller.
// * @throws Exception
// */
// <T> T convert(TypedInput body, Type type) throws ConversionException, IOException;
// }
// Path: idobata4j-core/src/test/java/com/uphyca/idobata/IdobataTest.java
import com.pusher.client.Pusher;
import com.uphyca.idobata.http.Client;
import com.uphyca.idobata.http.Request;
import com.uphyca.idobata.http.Response;
import com.uphyca.idobata.http.TypedInput;
import com.uphyca.idobata.model.*;
import com.uphyca.idobata.pusher.PusherBuilder;
import com.uphyca.idobata.transform.Converter;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import static org.fest.assertions.api.Assertions.assertThat;
import static org.mockito.BDDMockito.given;
import static org.mockito.Matchers.same;
import static org.mockito.Mockito.*;
/*
* Copyright (C) 2014 uPhyca Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.uphyca.idobata;
/**
* @author Sosuke Masui (masui@uphyca.com)
*/
@RunWith(MockitoJUnitRunner.class)
public class IdobataTest {
Idobata underTest;
@Mock | Client client; |
uPhyca/idobata4j | idobata4j-core/src/test/java/com/uphyca/idobata/IdobataTest.java | // Path: idobata4j-core/src/main/java/com/uphyca/idobata/http/Client.java
// public interface Client {
//
// /**
// * Synchronously execute an HTTP represented by {@code request} and encapsulate all response data
// * into a {@link Response} instance.
// */
// Response execute(Request request) throws IOException;
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/http/Request.java
// public class Request {
//
// private final String method;
// private final String url;
// private final List<Header> headers;
// private final TypedOutput body;
//
// public Request(String method, String url, List<Header> headers, TypedOutput body) {
// this.method = method;
// this.url = url;
// this.headers = headers;
// this.body = body;
// }
//
// /** HTTP method verb. */
// public String getMethod() {
// return method;
// }
//
// /** Target URL. */
// public String getUrl() {
// return url;
// }
//
// /** Returns an unmodifiable list of headers, never {@code null}. */
// public List<Header> getHeaders() {
// return headers;
// }
//
// /** Returns the request body or {@code null}. */
// public TypedOutput getBody() {
// return body;
// }
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/http/Response.java
// public class Response {
//
// private final String url;
// private final int status;
// private final String reason;
// private final List<Header> headers;
// private final TypedInput body;
//
// public Response(String url, int status, String reason, List<Header> headers, TypedInput body) {
// this.url = url;
// this.status = status;
// this.reason = reason;
// this.headers = headers;
// this.body = body;
// }
//
// /** Request URL. */
// public String getUrl() {
// return url;
// }
//
// /** Status line code. */
// public int getStatus() {
// return status;
// }
//
// /** Status line reason phrase. */
// public String getReason() {
// return reason;
// }
//
// /** An unmodifiable collection of headers. */
// public List<Header> getHeaders() {
// return headers;
// }
//
// /** Response body. May be {@code null}. */
// public TypedInput getBody() {
// return body;
// }
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/http/TypedInput.java
// public interface TypedInput {
//
// /** Returns the mime type. */
// String mimeType();
//
// /** Length in bytes. Returns {@code -1} if length is unknown. */
// long length();
//
// /**
// * Read bytes as stream. Unless otherwise specified, this method may only be called once. It is
// * the responsibility of the caller to close the stream.
// */
// InputStream in() throws IOException;
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/pusher/PusherBuilder.java
// public class PusherBuilder {
//
// private static final String API_KEY = "44ffe67af1c7035be764";
//
// private PusherOptions options;
//
// /** Options for the Pusher client library to use. */
// public PusherBuilder setOptions(PusherOptions options) {
// this.options = options;
// return this;
// }
//
// public PusherBuilder buildUpon() {
// return new PusherBuilder().setOptions(options);
// }
//
// /**
// * Create the {@link com.pusher.client.Pusher} instances.
// */
// public Pusher build() {
// if (options == null) {
// return new Pusher(API_KEY);
// }
// return new Pusher(API_KEY, options);
// }
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/transform/Converter.java
// public interface Converter {
//
// /**
// * Convert an HTTP response body to a concrete object of the specified type.
// *
// * @param body HTTP response body.
// * @param type Target object type.
// * @return Instance of {@code type} which will be cast by the caller.
// * @throws Exception
// */
// <T> T convert(TypedInput body, Type type) throws ConversionException, IOException;
// }
| import com.pusher.client.Pusher;
import com.uphyca.idobata.http.Client;
import com.uphyca.idobata.http.Request;
import com.uphyca.idobata.http.Response;
import com.uphyca.idobata.http.TypedInput;
import com.uphyca.idobata.model.*;
import com.uphyca.idobata.pusher.PusherBuilder;
import com.uphyca.idobata.transform.Converter;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import static org.fest.assertions.api.Assertions.assertThat;
import static org.mockito.BDDMockito.given;
import static org.mockito.Matchers.same;
import static org.mockito.Mockito.*; | @Override
public PusherBuilder buildUpon() {
return this;
}
@Override
public Pusher build() {
return pusher;
}
};
@Before
public void setUp() throws Exception {
underTest = new IdobataBuilder().setClient(client)
.setRequestInterceptor(requestInterceptor)
.setConverter(converter)
.setPusherBuilder(pusherBuilder)
.build();
}
@Test
public void assertPreconditions() throws Exception {
assertThat(client).isNotNull();
assertThat(requestInterceptor).isNotNull();
assertThat(converter).isNotNull();
assertThat(underTest).isNotNull();
}
@Test
public void getSeed() throws Exception { | // Path: idobata4j-core/src/main/java/com/uphyca/idobata/http/Client.java
// public interface Client {
//
// /**
// * Synchronously execute an HTTP represented by {@code request} and encapsulate all response data
// * into a {@link Response} instance.
// */
// Response execute(Request request) throws IOException;
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/http/Request.java
// public class Request {
//
// private final String method;
// private final String url;
// private final List<Header> headers;
// private final TypedOutput body;
//
// public Request(String method, String url, List<Header> headers, TypedOutput body) {
// this.method = method;
// this.url = url;
// this.headers = headers;
// this.body = body;
// }
//
// /** HTTP method verb. */
// public String getMethod() {
// return method;
// }
//
// /** Target URL. */
// public String getUrl() {
// return url;
// }
//
// /** Returns an unmodifiable list of headers, never {@code null}. */
// public List<Header> getHeaders() {
// return headers;
// }
//
// /** Returns the request body or {@code null}. */
// public TypedOutput getBody() {
// return body;
// }
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/http/Response.java
// public class Response {
//
// private final String url;
// private final int status;
// private final String reason;
// private final List<Header> headers;
// private final TypedInput body;
//
// public Response(String url, int status, String reason, List<Header> headers, TypedInput body) {
// this.url = url;
// this.status = status;
// this.reason = reason;
// this.headers = headers;
// this.body = body;
// }
//
// /** Request URL. */
// public String getUrl() {
// return url;
// }
//
// /** Status line code. */
// public int getStatus() {
// return status;
// }
//
// /** Status line reason phrase. */
// public String getReason() {
// return reason;
// }
//
// /** An unmodifiable collection of headers. */
// public List<Header> getHeaders() {
// return headers;
// }
//
// /** Response body. May be {@code null}. */
// public TypedInput getBody() {
// return body;
// }
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/http/TypedInput.java
// public interface TypedInput {
//
// /** Returns the mime type. */
// String mimeType();
//
// /** Length in bytes. Returns {@code -1} if length is unknown. */
// long length();
//
// /**
// * Read bytes as stream. Unless otherwise specified, this method may only be called once. It is
// * the responsibility of the caller to close the stream.
// */
// InputStream in() throws IOException;
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/pusher/PusherBuilder.java
// public class PusherBuilder {
//
// private static final String API_KEY = "44ffe67af1c7035be764";
//
// private PusherOptions options;
//
// /** Options for the Pusher client library to use. */
// public PusherBuilder setOptions(PusherOptions options) {
// this.options = options;
// return this;
// }
//
// public PusherBuilder buildUpon() {
// return new PusherBuilder().setOptions(options);
// }
//
// /**
// * Create the {@link com.pusher.client.Pusher} instances.
// */
// public Pusher build() {
// if (options == null) {
// return new Pusher(API_KEY);
// }
// return new Pusher(API_KEY, options);
// }
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/transform/Converter.java
// public interface Converter {
//
// /**
// * Convert an HTTP response body to a concrete object of the specified type.
// *
// * @param body HTTP response body.
// * @param type Target object type.
// * @return Instance of {@code type} which will be cast by the caller.
// * @throws Exception
// */
// <T> T convert(TypedInput body, Type type) throws ConversionException, IOException;
// }
// Path: idobata4j-core/src/test/java/com/uphyca/idobata/IdobataTest.java
import com.pusher.client.Pusher;
import com.uphyca.idobata.http.Client;
import com.uphyca.idobata.http.Request;
import com.uphyca.idobata.http.Response;
import com.uphyca.idobata.http.TypedInput;
import com.uphyca.idobata.model.*;
import com.uphyca.idobata.pusher.PusherBuilder;
import com.uphyca.idobata.transform.Converter;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import static org.fest.assertions.api.Assertions.assertThat;
import static org.mockito.BDDMockito.given;
import static org.mockito.Matchers.same;
import static org.mockito.Mockito.*;
@Override
public PusherBuilder buildUpon() {
return this;
}
@Override
public Pusher build() {
return pusher;
}
};
@Before
public void setUp() throws Exception {
underTest = new IdobataBuilder().setClient(client)
.setRequestInterceptor(requestInterceptor)
.setConverter(converter)
.setPusherBuilder(pusherBuilder)
.build();
}
@Test
public void assertPreconditions() throws Exception {
assertThat(client).isNotNull();
assertThat(requestInterceptor).isNotNull();
assertThat(converter).isNotNull();
assertThat(underTest).isNotNull();
}
@Test
public void getSeed() throws Exception { | Response response = mock(Response.class); |
uPhyca/idobata4j | idobata4j-core/src/test/java/com/uphyca/idobata/IdobataTest.java | // Path: idobata4j-core/src/main/java/com/uphyca/idobata/http/Client.java
// public interface Client {
//
// /**
// * Synchronously execute an HTTP represented by {@code request} and encapsulate all response data
// * into a {@link Response} instance.
// */
// Response execute(Request request) throws IOException;
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/http/Request.java
// public class Request {
//
// private final String method;
// private final String url;
// private final List<Header> headers;
// private final TypedOutput body;
//
// public Request(String method, String url, List<Header> headers, TypedOutput body) {
// this.method = method;
// this.url = url;
// this.headers = headers;
// this.body = body;
// }
//
// /** HTTP method verb. */
// public String getMethod() {
// return method;
// }
//
// /** Target URL. */
// public String getUrl() {
// return url;
// }
//
// /** Returns an unmodifiable list of headers, never {@code null}. */
// public List<Header> getHeaders() {
// return headers;
// }
//
// /** Returns the request body or {@code null}. */
// public TypedOutput getBody() {
// return body;
// }
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/http/Response.java
// public class Response {
//
// private final String url;
// private final int status;
// private final String reason;
// private final List<Header> headers;
// private final TypedInput body;
//
// public Response(String url, int status, String reason, List<Header> headers, TypedInput body) {
// this.url = url;
// this.status = status;
// this.reason = reason;
// this.headers = headers;
// this.body = body;
// }
//
// /** Request URL. */
// public String getUrl() {
// return url;
// }
//
// /** Status line code. */
// public int getStatus() {
// return status;
// }
//
// /** Status line reason phrase. */
// public String getReason() {
// return reason;
// }
//
// /** An unmodifiable collection of headers. */
// public List<Header> getHeaders() {
// return headers;
// }
//
// /** Response body. May be {@code null}. */
// public TypedInput getBody() {
// return body;
// }
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/http/TypedInput.java
// public interface TypedInput {
//
// /** Returns the mime type. */
// String mimeType();
//
// /** Length in bytes. Returns {@code -1} if length is unknown. */
// long length();
//
// /**
// * Read bytes as stream. Unless otherwise specified, this method may only be called once. It is
// * the responsibility of the caller to close the stream.
// */
// InputStream in() throws IOException;
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/pusher/PusherBuilder.java
// public class PusherBuilder {
//
// private static final String API_KEY = "44ffe67af1c7035be764";
//
// private PusherOptions options;
//
// /** Options for the Pusher client library to use. */
// public PusherBuilder setOptions(PusherOptions options) {
// this.options = options;
// return this;
// }
//
// public PusherBuilder buildUpon() {
// return new PusherBuilder().setOptions(options);
// }
//
// /**
// * Create the {@link com.pusher.client.Pusher} instances.
// */
// public Pusher build() {
// if (options == null) {
// return new Pusher(API_KEY);
// }
// return new Pusher(API_KEY, options);
// }
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/transform/Converter.java
// public interface Converter {
//
// /**
// * Convert an HTTP response body to a concrete object of the specified type.
// *
// * @param body HTTP response body.
// * @param type Target object type.
// * @return Instance of {@code type} which will be cast by the caller.
// * @throws Exception
// */
// <T> T convert(TypedInput body, Type type) throws ConversionException, IOException;
// }
| import com.pusher.client.Pusher;
import com.uphyca.idobata.http.Client;
import com.uphyca.idobata.http.Request;
import com.uphyca.idobata.http.Response;
import com.uphyca.idobata.http.TypedInput;
import com.uphyca.idobata.model.*;
import com.uphyca.idobata.pusher.PusherBuilder;
import com.uphyca.idobata.transform.Converter;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import static org.fest.assertions.api.Assertions.assertThat;
import static org.mockito.BDDMockito.given;
import static org.mockito.Matchers.same;
import static org.mockito.Mockito.*; | return this;
}
@Override
public Pusher build() {
return pusher;
}
};
@Before
public void setUp() throws Exception {
underTest = new IdobataBuilder().setClient(client)
.setRequestInterceptor(requestInterceptor)
.setConverter(converter)
.setPusherBuilder(pusherBuilder)
.build();
}
@Test
public void assertPreconditions() throws Exception {
assertThat(client).isNotNull();
assertThat(requestInterceptor).isNotNull();
assertThat(converter).isNotNull();
assertThat(underTest).isNotNull();
}
@Test
public void getSeed() throws Exception {
Response response = mock(Response.class);
Seed expectedSeed = new SeedBean(); | // Path: idobata4j-core/src/main/java/com/uphyca/idobata/http/Client.java
// public interface Client {
//
// /**
// * Synchronously execute an HTTP represented by {@code request} and encapsulate all response data
// * into a {@link Response} instance.
// */
// Response execute(Request request) throws IOException;
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/http/Request.java
// public class Request {
//
// private final String method;
// private final String url;
// private final List<Header> headers;
// private final TypedOutput body;
//
// public Request(String method, String url, List<Header> headers, TypedOutput body) {
// this.method = method;
// this.url = url;
// this.headers = headers;
// this.body = body;
// }
//
// /** HTTP method verb. */
// public String getMethod() {
// return method;
// }
//
// /** Target URL. */
// public String getUrl() {
// return url;
// }
//
// /** Returns an unmodifiable list of headers, never {@code null}. */
// public List<Header> getHeaders() {
// return headers;
// }
//
// /** Returns the request body or {@code null}. */
// public TypedOutput getBody() {
// return body;
// }
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/http/Response.java
// public class Response {
//
// private final String url;
// private final int status;
// private final String reason;
// private final List<Header> headers;
// private final TypedInput body;
//
// public Response(String url, int status, String reason, List<Header> headers, TypedInput body) {
// this.url = url;
// this.status = status;
// this.reason = reason;
// this.headers = headers;
// this.body = body;
// }
//
// /** Request URL. */
// public String getUrl() {
// return url;
// }
//
// /** Status line code. */
// public int getStatus() {
// return status;
// }
//
// /** Status line reason phrase. */
// public String getReason() {
// return reason;
// }
//
// /** An unmodifiable collection of headers. */
// public List<Header> getHeaders() {
// return headers;
// }
//
// /** Response body. May be {@code null}. */
// public TypedInput getBody() {
// return body;
// }
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/http/TypedInput.java
// public interface TypedInput {
//
// /** Returns the mime type. */
// String mimeType();
//
// /** Length in bytes. Returns {@code -1} if length is unknown. */
// long length();
//
// /**
// * Read bytes as stream. Unless otherwise specified, this method may only be called once. It is
// * the responsibility of the caller to close the stream.
// */
// InputStream in() throws IOException;
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/pusher/PusherBuilder.java
// public class PusherBuilder {
//
// private static final String API_KEY = "44ffe67af1c7035be764";
//
// private PusherOptions options;
//
// /** Options for the Pusher client library to use. */
// public PusherBuilder setOptions(PusherOptions options) {
// this.options = options;
// return this;
// }
//
// public PusherBuilder buildUpon() {
// return new PusherBuilder().setOptions(options);
// }
//
// /**
// * Create the {@link com.pusher.client.Pusher} instances.
// */
// public Pusher build() {
// if (options == null) {
// return new Pusher(API_KEY);
// }
// return new Pusher(API_KEY, options);
// }
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/transform/Converter.java
// public interface Converter {
//
// /**
// * Convert an HTTP response body to a concrete object of the specified type.
// *
// * @param body HTTP response body.
// * @param type Target object type.
// * @return Instance of {@code type} which will be cast by the caller.
// * @throws Exception
// */
// <T> T convert(TypedInput body, Type type) throws ConversionException, IOException;
// }
// Path: idobata4j-core/src/test/java/com/uphyca/idobata/IdobataTest.java
import com.pusher.client.Pusher;
import com.uphyca.idobata.http.Client;
import com.uphyca.idobata.http.Request;
import com.uphyca.idobata.http.Response;
import com.uphyca.idobata.http.TypedInput;
import com.uphyca.idobata.model.*;
import com.uphyca.idobata.pusher.PusherBuilder;
import com.uphyca.idobata.transform.Converter;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import static org.fest.assertions.api.Assertions.assertThat;
import static org.mockito.BDDMockito.given;
import static org.mockito.Matchers.same;
import static org.mockito.Mockito.*;
return this;
}
@Override
public Pusher build() {
return pusher;
}
};
@Before
public void setUp() throws Exception {
underTest = new IdobataBuilder().setClient(client)
.setRequestInterceptor(requestInterceptor)
.setConverter(converter)
.setPusherBuilder(pusherBuilder)
.build();
}
@Test
public void assertPreconditions() throws Exception {
assertThat(client).isNotNull();
assertThat(requestInterceptor).isNotNull();
assertThat(converter).isNotNull();
assertThat(underTest).isNotNull();
}
@Test
public void getSeed() throws Exception {
Response response = mock(Response.class);
Seed expectedSeed = new SeedBean(); | ArgumentCaptor<Request> requestCaptor = ArgumentCaptor.forClass(Request.class); |
uPhyca/idobata4j | idobata4j-core/src/test/java/com/uphyca/idobata/IdobataTest.java | // Path: idobata4j-core/src/main/java/com/uphyca/idobata/http/Client.java
// public interface Client {
//
// /**
// * Synchronously execute an HTTP represented by {@code request} and encapsulate all response data
// * into a {@link Response} instance.
// */
// Response execute(Request request) throws IOException;
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/http/Request.java
// public class Request {
//
// private final String method;
// private final String url;
// private final List<Header> headers;
// private final TypedOutput body;
//
// public Request(String method, String url, List<Header> headers, TypedOutput body) {
// this.method = method;
// this.url = url;
// this.headers = headers;
// this.body = body;
// }
//
// /** HTTP method verb. */
// public String getMethod() {
// return method;
// }
//
// /** Target URL. */
// public String getUrl() {
// return url;
// }
//
// /** Returns an unmodifiable list of headers, never {@code null}. */
// public List<Header> getHeaders() {
// return headers;
// }
//
// /** Returns the request body or {@code null}. */
// public TypedOutput getBody() {
// return body;
// }
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/http/Response.java
// public class Response {
//
// private final String url;
// private final int status;
// private final String reason;
// private final List<Header> headers;
// private final TypedInput body;
//
// public Response(String url, int status, String reason, List<Header> headers, TypedInput body) {
// this.url = url;
// this.status = status;
// this.reason = reason;
// this.headers = headers;
// this.body = body;
// }
//
// /** Request URL. */
// public String getUrl() {
// return url;
// }
//
// /** Status line code. */
// public int getStatus() {
// return status;
// }
//
// /** Status line reason phrase. */
// public String getReason() {
// return reason;
// }
//
// /** An unmodifiable collection of headers. */
// public List<Header> getHeaders() {
// return headers;
// }
//
// /** Response body. May be {@code null}. */
// public TypedInput getBody() {
// return body;
// }
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/http/TypedInput.java
// public interface TypedInput {
//
// /** Returns the mime type. */
// String mimeType();
//
// /** Length in bytes. Returns {@code -1} if length is unknown. */
// long length();
//
// /**
// * Read bytes as stream. Unless otherwise specified, this method may only be called once. It is
// * the responsibility of the caller to close the stream.
// */
// InputStream in() throws IOException;
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/pusher/PusherBuilder.java
// public class PusherBuilder {
//
// private static final String API_KEY = "44ffe67af1c7035be764";
//
// private PusherOptions options;
//
// /** Options for the Pusher client library to use. */
// public PusherBuilder setOptions(PusherOptions options) {
// this.options = options;
// return this;
// }
//
// public PusherBuilder buildUpon() {
// return new PusherBuilder().setOptions(options);
// }
//
// /**
// * Create the {@link com.pusher.client.Pusher} instances.
// */
// public Pusher build() {
// if (options == null) {
// return new Pusher(API_KEY);
// }
// return new Pusher(API_KEY, options);
// }
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/transform/Converter.java
// public interface Converter {
//
// /**
// * Convert an HTTP response body to a concrete object of the specified type.
// *
// * @param body HTTP response body.
// * @param type Target object type.
// * @return Instance of {@code type} which will be cast by the caller.
// * @throws Exception
// */
// <T> T convert(TypedInput body, Type type) throws ConversionException, IOException;
// }
| import com.pusher.client.Pusher;
import com.uphyca.idobata.http.Client;
import com.uphyca.idobata.http.Request;
import com.uphyca.idobata.http.Response;
import com.uphyca.idobata.http.TypedInput;
import com.uphyca.idobata.model.*;
import com.uphyca.idobata.pusher.PusherBuilder;
import com.uphyca.idobata.transform.Converter;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import static org.fest.assertions.api.Assertions.assertThat;
import static org.mockito.BDDMockito.given;
import static org.mockito.Matchers.same;
import static org.mockito.Mockito.*; |
@Override
public Pusher build() {
return pusher;
}
};
@Before
public void setUp() throws Exception {
underTest = new IdobataBuilder().setClient(client)
.setRequestInterceptor(requestInterceptor)
.setConverter(converter)
.setPusherBuilder(pusherBuilder)
.build();
}
@Test
public void assertPreconditions() throws Exception {
assertThat(client).isNotNull();
assertThat(requestInterceptor).isNotNull();
assertThat(converter).isNotNull();
assertThat(underTest).isNotNull();
}
@Test
public void getSeed() throws Exception {
Response response = mock(Response.class);
Seed expectedSeed = new SeedBean();
ArgumentCaptor<Request> requestCaptor = ArgumentCaptor.forClass(Request.class);
| // Path: idobata4j-core/src/main/java/com/uphyca/idobata/http/Client.java
// public interface Client {
//
// /**
// * Synchronously execute an HTTP represented by {@code request} and encapsulate all response data
// * into a {@link Response} instance.
// */
// Response execute(Request request) throws IOException;
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/http/Request.java
// public class Request {
//
// private final String method;
// private final String url;
// private final List<Header> headers;
// private final TypedOutput body;
//
// public Request(String method, String url, List<Header> headers, TypedOutput body) {
// this.method = method;
// this.url = url;
// this.headers = headers;
// this.body = body;
// }
//
// /** HTTP method verb. */
// public String getMethod() {
// return method;
// }
//
// /** Target URL. */
// public String getUrl() {
// return url;
// }
//
// /** Returns an unmodifiable list of headers, never {@code null}. */
// public List<Header> getHeaders() {
// return headers;
// }
//
// /** Returns the request body or {@code null}. */
// public TypedOutput getBody() {
// return body;
// }
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/http/Response.java
// public class Response {
//
// private final String url;
// private final int status;
// private final String reason;
// private final List<Header> headers;
// private final TypedInput body;
//
// public Response(String url, int status, String reason, List<Header> headers, TypedInput body) {
// this.url = url;
// this.status = status;
// this.reason = reason;
// this.headers = headers;
// this.body = body;
// }
//
// /** Request URL. */
// public String getUrl() {
// return url;
// }
//
// /** Status line code. */
// public int getStatus() {
// return status;
// }
//
// /** Status line reason phrase. */
// public String getReason() {
// return reason;
// }
//
// /** An unmodifiable collection of headers. */
// public List<Header> getHeaders() {
// return headers;
// }
//
// /** Response body. May be {@code null}. */
// public TypedInput getBody() {
// return body;
// }
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/http/TypedInput.java
// public interface TypedInput {
//
// /** Returns the mime type. */
// String mimeType();
//
// /** Length in bytes. Returns {@code -1} if length is unknown. */
// long length();
//
// /**
// * Read bytes as stream. Unless otherwise specified, this method may only be called once. It is
// * the responsibility of the caller to close the stream.
// */
// InputStream in() throws IOException;
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/pusher/PusherBuilder.java
// public class PusherBuilder {
//
// private static final String API_KEY = "44ffe67af1c7035be764";
//
// private PusherOptions options;
//
// /** Options for the Pusher client library to use. */
// public PusherBuilder setOptions(PusherOptions options) {
// this.options = options;
// return this;
// }
//
// public PusherBuilder buildUpon() {
// return new PusherBuilder().setOptions(options);
// }
//
// /**
// * Create the {@link com.pusher.client.Pusher} instances.
// */
// public Pusher build() {
// if (options == null) {
// return new Pusher(API_KEY);
// }
// return new Pusher(API_KEY, options);
// }
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/transform/Converter.java
// public interface Converter {
//
// /**
// * Convert an HTTP response body to a concrete object of the specified type.
// *
// * @param body HTTP response body.
// * @param type Target object type.
// * @return Instance of {@code type} which will be cast by the caller.
// * @throws Exception
// */
// <T> T convert(TypedInput body, Type type) throws ConversionException, IOException;
// }
// Path: idobata4j-core/src/test/java/com/uphyca/idobata/IdobataTest.java
import com.pusher.client.Pusher;
import com.uphyca.idobata.http.Client;
import com.uphyca.idobata.http.Request;
import com.uphyca.idobata.http.Response;
import com.uphyca.idobata.http.TypedInput;
import com.uphyca.idobata.model.*;
import com.uphyca.idobata.pusher.PusherBuilder;
import com.uphyca.idobata.transform.Converter;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import static org.fest.assertions.api.Assertions.assertThat;
import static org.mockito.BDDMockito.given;
import static org.mockito.Matchers.same;
import static org.mockito.Mockito.*;
@Override
public Pusher build() {
return pusher;
}
};
@Before
public void setUp() throws Exception {
underTest = new IdobataBuilder().setClient(client)
.setRequestInterceptor(requestInterceptor)
.setConverter(converter)
.setPusherBuilder(pusherBuilder)
.build();
}
@Test
public void assertPreconditions() throws Exception {
assertThat(client).isNotNull();
assertThat(requestInterceptor).isNotNull();
assertThat(converter).isNotNull();
assertThat(underTest).isNotNull();
}
@Test
public void getSeed() throws Exception {
Response response = mock(Response.class);
Seed expectedSeed = new SeedBean();
ArgumentCaptor<Request> requestCaptor = ArgumentCaptor.forClass(Request.class);
| given(response.getBody()).willReturn(mock(TypedInput.class)); |
uPhyca/idobata4j | idobata4j-core/src/main/java/com/uphyca/idobata/TokenAuthenticator.java | // Path: idobata4j-core/src/main/java/com/uphyca/idobata/http/Client.java
// public interface Client {
//
// /**
// * Synchronously execute an HTTP represented by {@code request} and encapsulate all response data
// * into a {@link Response} instance.
// */
// Response execute(Request request) throws IOException;
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/http/Header.java
// public class Header {
//
// private final String name;
// private final String value;
//
// public Header(String name, String value) {
// this.name = name;
// this.value = value;
// }
//
// public String getName() {
// return name;
// }
//
// public String getValue() {
// return value;
// }
//
// @Override
// public boolean equals(Object o) {
// if (this == o) {
// return true;
// }
// if (o == null || getClass() != o.getClass()) {
// return false;
// }
//
// Header header = (Header) o;
//
// if (name != null ? !name.equals(header.name) : header.name != null) {
// return false;
// }
// if (value != null ? !value.equals(header.value) : header.value != null) {
// return false;
// }
//
// return true;
// }
//
// @Override
// public int hashCode() {
// int result = name != null ? name.hashCode() : 0;
// result = 31 * result + (value != null ? value.hashCode() : 0);
// return result;
// }
//
// @Override
// public String toString() {
// return "Header{" + "name='" + name + '\'' + ", value='" + value + '\'' + '}';
// }
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/http/Request.java
// public class Request {
//
// private final String method;
// private final String url;
// private final List<Header> headers;
// private final TypedOutput body;
//
// public Request(String method, String url, List<Header> headers, TypedOutput body) {
// this.method = method;
// this.url = url;
// this.headers = headers;
// this.body = body;
// }
//
// /** HTTP method verb. */
// public String getMethod() {
// return method;
// }
//
// /** Target URL. */
// public String getUrl() {
// return url;
// }
//
// /** Returns an unmodifiable list of headers, never {@code null}. */
// public List<Header> getHeaders() {
// return headers;
// }
//
// /** Returns the request body or {@code null}. */
// public TypedOutput getBody() {
// return body;
// }
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/http/Response.java
// public class Response {
//
// private final String url;
// private final int status;
// private final String reason;
// private final List<Header> headers;
// private final TypedInput body;
//
// public Response(String url, int status, String reason, List<Header> headers, TypedInput body) {
// this.url = url;
// this.status = status;
// this.reason = reason;
// this.headers = headers;
// this.body = body;
// }
//
// /** Request URL. */
// public String getUrl() {
// return url;
// }
//
// /** Status line code. */
// public int getStatus() {
// return status;
// }
//
// /** Status line reason phrase. */
// public String getReason() {
// return reason;
// }
//
// /** An unmodifiable collection of headers. */
// public List<Header> getHeaders() {
// return headers;
// }
//
// /** Response body. May be {@code null}. */
// public TypedInput getBody() {
// return body;
// }
// }
| import com.uphyca.idobata.http.Client;
import com.uphyca.idobata.http.Header;
import com.uphyca.idobata.http.Request;
import com.uphyca.idobata.http.Response;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List; | /*
* Copyright (C) 2014 uPhyca Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.uphyca.idobata;
/**
* Represents token authentication.
*
* @author Sosuke Masui (masui@uphyca.com)
*/
public class TokenAuthenticator implements RequestInterceptor {
/**
* The provider to rovides token to authenticate.
*/
public interface TokenProvider {
String get();
}
private final TokenProvider mTokenProvider;
/**
* @param tokenProvider The tokenProvider to obtain the token for authentication.
*/
public TokenAuthenticator(TokenProvider tokenProvider) {
mTokenProvider = tokenProvider;
}
/**
* @param token The token for authentication.
*/
public TokenAuthenticator(String token) {
this.mTokenProvider = new SimpleTokenProvider(token);
}
@Override | // Path: idobata4j-core/src/main/java/com/uphyca/idobata/http/Client.java
// public interface Client {
//
// /**
// * Synchronously execute an HTTP represented by {@code request} and encapsulate all response data
// * into a {@link Response} instance.
// */
// Response execute(Request request) throws IOException;
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/http/Header.java
// public class Header {
//
// private final String name;
// private final String value;
//
// public Header(String name, String value) {
// this.name = name;
// this.value = value;
// }
//
// public String getName() {
// return name;
// }
//
// public String getValue() {
// return value;
// }
//
// @Override
// public boolean equals(Object o) {
// if (this == o) {
// return true;
// }
// if (o == null || getClass() != o.getClass()) {
// return false;
// }
//
// Header header = (Header) o;
//
// if (name != null ? !name.equals(header.name) : header.name != null) {
// return false;
// }
// if (value != null ? !value.equals(header.value) : header.value != null) {
// return false;
// }
//
// return true;
// }
//
// @Override
// public int hashCode() {
// int result = name != null ? name.hashCode() : 0;
// result = 31 * result + (value != null ? value.hashCode() : 0);
// return result;
// }
//
// @Override
// public String toString() {
// return "Header{" + "name='" + name + '\'' + ", value='" + value + '\'' + '}';
// }
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/http/Request.java
// public class Request {
//
// private final String method;
// private final String url;
// private final List<Header> headers;
// private final TypedOutput body;
//
// public Request(String method, String url, List<Header> headers, TypedOutput body) {
// this.method = method;
// this.url = url;
// this.headers = headers;
// this.body = body;
// }
//
// /** HTTP method verb. */
// public String getMethod() {
// return method;
// }
//
// /** Target URL. */
// public String getUrl() {
// return url;
// }
//
// /** Returns an unmodifiable list of headers, never {@code null}. */
// public List<Header> getHeaders() {
// return headers;
// }
//
// /** Returns the request body or {@code null}. */
// public TypedOutput getBody() {
// return body;
// }
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/http/Response.java
// public class Response {
//
// private final String url;
// private final int status;
// private final String reason;
// private final List<Header> headers;
// private final TypedInput body;
//
// public Response(String url, int status, String reason, List<Header> headers, TypedInput body) {
// this.url = url;
// this.status = status;
// this.reason = reason;
// this.headers = headers;
// this.body = body;
// }
//
// /** Request URL. */
// public String getUrl() {
// return url;
// }
//
// /** Status line code. */
// public int getStatus() {
// return status;
// }
//
// /** Status line reason phrase. */
// public String getReason() {
// return reason;
// }
//
// /** An unmodifiable collection of headers. */
// public List<Header> getHeaders() {
// return headers;
// }
//
// /** Response body. May be {@code null}. */
// public TypedInput getBody() {
// return body;
// }
// }
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/TokenAuthenticator.java
import com.uphyca.idobata.http.Client;
import com.uphyca.idobata.http.Header;
import com.uphyca.idobata.http.Request;
import com.uphyca.idobata.http.Response;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
/*
* Copyright (C) 2014 uPhyca Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.uphyca.idobata;
/**
* Represents token authentication.
*
* @author Sosuke Masui (masui@uphyca.com)
*/
public class TokenAuthenticator implements RequestInterceptor {
/**
* The provider to rovides token to authenticate.
*/
public interface TokenProvider {
String get();
}
private final TokenProvider mTokenProvider;
/**
* @param tokenProvider The tokenProvider to obtain the token for authentication.
*/
public TokenAuthenticator(TokenProvider tokenProvider) {
mTokenProvider = tokenProvider;
}
/**
* @param token The token for authentication.
*/
public TokenAuthenticator(String token) {
this.mTokenProvider = new SimpleTokenProvider(token);
}
@Override | public Response execute(Client client, Request request) throws IdobataError { |
uPhyca/idobata4j | idobata4j-core/src/main/java/com/uphyca/idobata/TokenAuthenticator.java | // Path: idobata4j-core/src/main/java/com/uphyca/idobata/http/Client.java
// public interface Client {
//
// /**
// * Synchronously execute an HTTP represented by {@code request} and encapsulate all response data
// * into a {@link Response} instance.
// */
// Response execute(Request request) throws IOException;
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/http/Header.java
// public class Header {
//
// private final String name;
// private final String value;
//
// public Header(String name, String value) {
// this.name = name;
// this.value = value;
// }
//
// public String getName() {
// return name;
// }
//
// public String getValue() {
// return value;
// }
//
// @Override
// public boolean equals(Object o) {
// if (this == o) {
// return true;
// }
// if (o == null || getClass() != o.getClass()) {
// return false;
// }
//
// Header header = (Header) o;
//
// if (name != null ? !name.equals(header.name) : header.name != null) {
// return false;
// }
// if (value != null ? !value.equals(header.value) : header.value != null) {
// return false;
// }
//
// return true;
// }
//
// @Override
// public int hashCode() {
// int result = name != null ? name.hashCode() : 0;
// result = 31 * result + (value != null ? value.hashCode() : 0);
// return result;
// }
//
// @Override
// public String toString() {
// return "Header{" + "name='" + name + '\'' + ", value='" + value + '\'' + '}';
// }
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/http/Request.java
// public class Request {
//
// private final String method;
// private final String url;
// private final List<Header> headers;
// private final TypedOutput body;
//
// public Request(String method, String url, List<Header> headers, TypedOutput body) {
// this.method = method;
// this.url = url;
// this.headers = headers;
// this.body = body;
// }
//
// /** HTTP method verb. */
// public String getMethod() {
// return method;
// }
//
// /** Target URL. */
// public String getUrl() {
// return url;
// }
//
// /** Returns an unmodifiable list of headers, never {@code null}. */
// public List<Header> getHeaders() {
// return headers;
// }
//
// /** Returns the request body or {@code null}. */
// public TypedOutput getBody() {
// return body;
// }
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/http/Response.java
// public class Response {
//
// private final String url;
// private final int status;
// private final String reason;
// private final List<Header> headers;
// private final TypedInput body;
//
// public Response(String url, int status, String reason, List<Header> headers, TypedInput body) {
// this.url = url;
// this.status = status;
// this.reason = reason;
// this.headers = headers;
// this.body = body;
// }
//
// /** Request URL. */
// public String getUrl() {
// return url;
// }
//
// /** Status line code. */
// public int getStatus() {
// return status;
// }
//
// /** Status line reason phrase. */
// public String getReason() {
// return reason;
// }
//
// /** An unmodifiable collection of headers. */
// public List<Header> getHeaders() {
// return headers;
// }
//
// /** Response body. May be {@code null}. */
// public TypedInput getBody() {
// return body;
// }
// }
| import com.uphyca.idobata.http.Client;
import com.uphyca.idobata.http.Header;
import com.uphyca.idobata.http.Request;
import com.uphyca.idobata.http.Response;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List; | /*
* Copyright (C) 2014 uPhyca Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.uphyca.idobata;
/**
* Represents token authentication.
*
* @author Sosuke Masui (masui@uphyca.com)
*/
public class TokenAuthenticator implements RequestInterceptor {
/**
* The provider to rovides token to authenticate.
*/
public interface TokenProvider {
String get();
}
private final TokenProvider mTokenProvider;
/**
* @param tokenProvider The tokenProvider to obtain the token for authentication.
*/
public TokenAuthenticator(TokenProvider tokenProvider) {
mTokenProvider = tokenProvider;
}
/**
* @param token The token for authentication.
*/
public TokenAuthenticator(String token) {
this.mTokenProvider = new SimpleTokenProvider(token);
}
@Override | // Path: idobata4j-core/src/main/java/com/uphyca/idobata/http/Client.java
// public interface Client {
//
// /**
// * Synchronously execute an HTTP represented by {@code request} and encapsulate all response data
// * into a {@link Response} instance.
// */
// Response execute(Request request) throws IOException;
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/http/Header.java
// public class Header {
//
// private final String name;
// private final String value;
//
// public Header(String name, String value) {
// this.name = name;
// this.value = value;
// }
//
// public String getName() {
// return name;
// }
//
// public String getValue() {
// return value;
// }
//
// @Override
// public boolean equals(Object o) {
// if (this == o) {
// return true;
// }
// if (o == null || getClass() != o.getClass()) {
// return false;
// }
//
// Header header = (Header) o;
//
// if (name != null ? !name.equals(header.name) : header.name != null) {
// return false;
// }
// if (value != null ? !value.equals(header.value) : header.value != null) {
// return false;
// }
//
// return true;
// }
//
// @Override
// public int hashCode() {
// int result = name != null ? name.hashCode() : 0;
// result = 31 * result + (value != null ? value.hashCode() : 0);
// return result;
// }
//
// @Override
// public String toString() {
// return "Header{" + "name='" + name + '\'' + ", value='" + value + '\'' + '}';
// }
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/http/Request.java
// public class Request {
//
// private final String method;
// private final String url;
// private final List<Header> headers;
// private final TypedOutput body;
//
// public Request(String method, String url, List<Header> headers, TypedOutput body) {
// this.method = method;
// this.url = url;
// this.headers = headers;
// this.body = body;
// }
//
// /** HTTP method verb. */
// public String getMethod() {
// return method;
// }
//
// /** Target URL. */
// public String getUrl() {
// return url;
// }
//
// /** Returns an unmodifiable list of headers, never {@code null}. */
// public List<Header> getHeaders() {
// return headers;
// }
//
// /** Returns the request body or {@code null}. */
// public TypedOutput getBody() {
// return body;
// }
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/http/Response.java
// public class Response {
//
// private final String url;
// private final int status;
// private final String reason;
// private final List<Header> headers;
// private final TypedInput body;
//
// public Response(String url, int status, String reason, List<Header> headers, TypedInput body) {
// this.url = url;
// this.status = status;
// this.reason = reason;
// this.headers = headers;
// this.body = body;
// }
//
// /** Request URL. */
// public String getUrl() {
// return url;
// }
//
// /** Status line code. */
// public int getStatus() {
// return status;
// }
//
// /** Status line reason phrase. */
// public String getReason() {
// return reason;
// }
//
// /** An unmodifiable collection of headers. */
// public List<Header> getHeaders() {
// return headers;
// }
//
// /** Response body. May be {@code null}. */
// public TypedInput getBody() {
// return body;
// }
// }
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/TokenAuthenticator.java
import com.uphyca.idobata.http.Client;
import com.uphyca.idobata.http.Header;
import com.uphyca.idobata.http.Request;
import com.uphyca.idobata.http.Response;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
/*
* Copyright (C) 2014 uPhyca Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.uphyca.idobata;
/**
* Represents token authentication.
*
* @author Sosuke Masui (masui@uphyca.com)
*/
public class TokenAuthenticator implements RequestInterceptor {
/**
* The provider to rovides token to authenticate.
*/
public interface TokenProvider {
String get();
}
private final TokenProvider mTokenProvider;
/**
* @param tokenProvider The tokenProvider to obtain the token for authentication.
*/
public TokenAuthenticator(TokenProvider tokenProvider) {
mTokenProvider = tokenProvider;
}
/**
* @param token The token for authentication.
*/
public TokenAuthenticator(String token) {
this.mTokenProvider = new SimpleTokenProvider(token);
}
@Override | public Response execute(Client client, Request request) throws IdobataError { |
uPhyca/idobata4j | idobata4j-core/src/main/java/com/uphyca/idobata/TokenAuthenticator.java | // Path: idobata4j-core/src/main/java/com/uphyca/idobata/http/Client.java
// public interface Client {
//
// /**
// * Synchronously execute an HTTP represented by {@code request} and encapsulate all response data
// * into a {@link Response} instance.
// */
// Response execute(Request request) throws IOException;
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/http/Header.java
// public class Header {
//
// private final String name;
// private final String value;
//
// public Header(String name, String value) {
// this.name = name;
// this.value = value;
// }
//
// public String getName() {
// return name;
// }
//
// public String getValue() {
// return value;
// }
//
// @Override
// public boolean equals(Object o) {
// if (this == o) {
// return true;
// }
// if (o == null || getClass() != o.getClass()) {
// return false;
// }
//
// Header header = (Header) o;
//
// if (name != null ? !name.equals(header.name) : header.name != null) {
// return false;
// }
// if (value != null ? !value.equals(header.value) : header.value != null) {
// return false;
// }
//
// return true;
// }
//
// @Override
// public int hashCode() {
// int result = name != null ? name.hashCode() : 0;
// result = 31 * result + (value != null ? value.hashCode() : 0);
// return result;
// }
//
// @Override
// public String toString() {
// return "Header{" + "name='" + name + '\'' + ", value='" + value + '\'' + '}';
// }
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/http/Request.java
// public class Request {
//
// private final String method;
// private final String url;
// private final List<Header> headers;
// private final TypedOutput body;
//
// public Request(String method, String url, List<Header> headers, TypedOutput body) {
// this.method = method;
// this.url = url;
// this.headers = headers;
// this.body = body;
// }
//
// /** HTTP method verb. */
// public String getMethod() {
// return method;
// }
//
// /** Target URL. */
// public String getUrl() {
// return url;
// }
//
// /** Returns an unmodifiable list of headers, never {@code null}. */
// public List<Header> getHeaders() {
// return headers;
// }
//
// /** Returns the request body or {@code null}. */
// public TypedOutput getBody() {
// return body;
// }
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/http/Response.java
// public class Response {
//
// private final String url;
// private final int status;
// private final String reason;
// private final List<Header> headers;
// private final TypedInput body;
//
// public Response(String url, int status, String reason, List<Header> headers, TypedInput body) {
// this.url = url;
// this.status = status;
// this.reason = reason;
// this.headers = headers;
// this.body = body;
// }
//
// /** Request URL. */
// public String getUrl() {
// return url;
// }
//
// /** Status line code. */
// public int getStatus() {
// return status;
// }
//
// /** Status line reason phrase. */
// public String getReason() {
// return reason;
// }
//
// /** An unmodifiable collection of headers. */
// public List<Header> getHeaders() {
// return headers;
// }
//
// /** Response body. May be {@code null}. */
// public TypedInput getBody() {
// return body;
// }
// }
| import com.uphyca.idobata.http.Client;
import com.uphyca.idobata.http.Header;
import com.uphyca.idobata.http.Request;
import com.uphyca.idobata.http.Response;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List; | /*
* Copyright (C) 2014 uPhyca Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.uphyca.idobata;
/**
* Represents token authentication.
*
* @author Sosuke Masui (masui@uphyca.com)
*/
public class TokenAuthenticator implements RequestInterceptor {
/**
* The provider to rovides token to authenticate.
*/
public interface TokenProvider {
String get();
}
private final TokenProvider mTokenProvider;
/**
* @param tokenProvider The tokenProvider to obtain the token for authentication.
*/
public TokenAuthenticator(TokenProvider tokenProvider) {
mTokenProvider = tokenProvider;
}
/**
* @param token The token for authentication.
*/
public TokenAuthenticator(String token) {
this.mTokenProvider = new SimpleTokenProvider(token);
}
@Override | // Path: idobata4j-core/src/main/java/com/uphyca/idobata/http/Client.java
// public interface Client {
//
// /**
// * Synchronously execute an HTTP represented by {@code request} and encapsulate all response data
// * into a {@link Response} instance.
// */
// Response execute(Request request) throws IOException;
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/http/Header.java
// public class Header {
//
// private final String name;
// private final String value;
//
// public Header(String name, String value) {
// this.name = name;
// this.value = value;
// }
//
// public String getName() {
// return name;
// }
//
// public String getValue() {
// return value;
// }
//
// @Override
// public boolean equals(Object o) {
// if (this == o) {
// return true;
// }
// if (o == null || getClass() != o.getClass()) {
// return false;
// }
//
// Header header = (Header) o;
//
// if (name != null ? !name.equals(header.name) : header.name != null) {
// return false;
// }
// if (value != null ? !value.equals(header.value) : header.value != null) {
// return false;
// }
//
// return true;
// }
//
// @Override
// public int hashCode() {
// int result = name != null ? name.hashCode() : 0;
// result = 31 * result + (value != null ? value.hashCode() : 0);
// return result;
// }
//
// @Override
// public String toString() {
// return "Header{" + "name='" + name + '\'' + ", value='" + value + '\'' + '}';
// }
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/http/Request.java
// public class Request {
//
// private final String method;
// private final String url;
// private final List<Header> headers;
// private final TypedOutput body;
//
// public Request(String method, String url, List<Header> headers, TypedOutput body) {
// this.method = method;
// this.url = url;
// this.headers = headers;
// this.body = body;
// }
//
// /** HTTP method verb. */
// public String getMethod() {
// return method;
// }
//
// /** Target URL. */
// public String getUrl() {
// return url;
// }
//
// /** Returns an unmodifiable list of headers, never {@code null}. */
// public List<Header> getHeaders() {
// return headers;
// }
//
// /** Returns the request body or {@code null}. */
// public TypedOutput getBody() {
// return body;
// }
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/http/Response.java
// public class Response {
//
// private final String url;
// private final int status;
// private final String reason;
// private final List<Header> headers;
// private final TypedInput body;
//
// public Response(String url, int status, String reason, List<Header> headers, TypedInput body) {
// this.url = url;
// this.status = status;
// this.reason = reason;
// this.headers = headers;
// this.body = body;
// }
//
// /** Request URL. */
// public String getUrl() {
// return url;
// }
//
// /** Status line code. */
// public int getStatus() {
// return status;
// }
//
// /** Status line reason phrase. */
// public String getReason() {
// return reason;
// }
//
// /** An unmodifiable collection of headers. */
// public List<Header> getHeaders() {
// return headers;
// }
//
// /** Response body. May be {@code null}. */
// public TypedInput getBody() {
// return body;
// }
// }
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/TokenAuthenticator.java
import com.uphyca.idobata.http.Client;
import com.uphyca.idobata.http.Header;
import com.uphyca.idobata.http.Request;
import com.uphyca.idobata.http.Response;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
/*
* Copyright (C) 2014 uPhyca Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.uphyca.idobata;
/**
* Represents token authentication.
*
* @author Sosuke Masui (masui@uphyca.com)
*/
public class TokenAuthenticator implements RequestInterceptor {
/**
* The provider to rovides token to authenticate.
*/
public interface TokenProvider {
String get();
}
private final TokenProvider mTokenProvider;
/**
* @param tokenProvider The tokenProvider to obtain the token for authentication.
*/
public TokenAuthenticator(TokenProvider tokenProvider) {
mTokenProvider = tokenProvider;
}
/**
* @param token The token for authentication.
*/
public TokenAuthenticator(String token) {
this.mTokenProvider = new SimpleTokenProvider(token);
}
@Override | public Response execute(Client client, Request request) throws IdobataError { |
uPhyca/idobata4j | idobata4j-core/src/main/java/com/uphyca/idobata/TokenAuthenticator.java | // Path: idobata4j-core/src/main/java/com/uphyca/idobata/http/Client.java
// public interface Client {
//
// /**
// * Synchronously execute an HTTP represented by {@code request} and encapsulate all response data
// * into a {@link Response} instance.
// */
// Response execute(Request request) throws IOException;
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/http/Header.java
// public class Header {
//
// private final String name;
// private final String value;
//
// public Header(String name, String value) {
// this.name = name;
// this.value = value;
// }
//
// public String getName() {
// return name;
// }
//
// public String getValue() {
// return value;
// }
//
// @Override
// public boolean equals(Object o) {
// if (this == o) {
// return true;
// }
// if (o == null || getClass() != o.getClass()) {
// return false;
// }
//
// Header header = (Header) o;
//
// if (name != null ? !name.equals(header.name) : header.name != null) {
// return false;
// }
// if (value != null ? !value.equals(header.value) : header.value != null) {
// return false;
// }
//
// return true;
// }
//
// @Override
// public int hashCode() {
// int result = name != null ? name.hashCode() : 0;
// result = 31 * result + (value != null ? value.hashCode() : 0);
// return result;
// }
//
// @Override
// public String toString() {
// return "Header{" + "name='" + name + '\'' + ", value='" + value + '\'' + '}';
// }
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/http/Request.java
// public class Request {
//
// private final String method;
// private final String url;
// private final List<Header> headers;
// private final TypedOutput body;
//
// public Request(String method, String url, List<Header> headers, TypedOutput body) {
// this.method = method;
// this.url = url;
// this.headers = headers;
// this.body = body;
// }
//
// /** HTTP method verb. */
// public String getMethod() {
// return method;
// }
//
// /** Target URL. */
// public String getUrl() {
// return url;
// }
//
// /** Returns an unmodifiable list of headers, never {@code null}. */
// public List<Header> getHeaders() {
// return headers;
// }
//
// /** Returns the request body or {@code null}. */
// public TypedOutput getBody() {
// return body;
// }
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/http/Response.java
// public class Response {
//
// private final String url;
// private final int status;
// private final String reason;
// private final List<Header> headers;
// private final TypedInput body;
//
// public Response(String url, int status, String reason, List<Header> headers, TypedInput body) {
// this.url = url;
// this.status = status;
// this.reason = reason;
// this.headers = headers;
// this.body = body;
// }
//
// /** Request URL. */
// public String getUrl() {
// return url;
// }
//
// /** Status line code. */
// public int getStatus() {
// return status;
// }
//
// /** Status line reason phrase. */
// public String getReason() {
// return reason;
// }
//
// /** An unmodifiable collection of headers. */
// public List<Header> getHeaders() {
// return headers;
// }
//
// /** Response body. May be {@code null}. */
// public TypedInput getBody() {
// return body;
// }
// }
| import com.uphyca.idobata.http.Client;
import com.uphyca.idobata.http.Header;
import com.uphyca.idobata.http.Request;
import com.uphyca.idobata.http.Response;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List; | /*
* Copyright (C) 2014 uPhyca Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.uphyca.idobata;
/**
* Represents token authentication.
*
* @author Sosuke Masui (masui@uphyca.com)
*/
public class TokenAuthenticator implements RequestInterceptor {
/**
* The provider to rovides token to authenticate.
*/
public interface TokenProvider {
String get();
}
private final TokenProvider mTokenProvider;
/**
* @param tokenProvider The tokenProvider to obtain the token for authentication.
*/
public TokenAuthenticator(TokenProvider tokenProvider) {
mTokenProvider = tokenProvider;
}
/**
* @param token The token for authentication.
*/
public TokenAuthenticator(String token) {
this.mTokenProvider = new SimpleTokenProvider(token);
}
@Override
public Response execute(Client client, Request request) throws IdobataError { | // Path: idobata4j-core/src/main/java/com/uphyca/idobata/http/Client.java
// public interface Client {
//
// /**
// * Synchronously execute an HTTP represented by {@code request} and encapsulate all response data
// * into a {@link Response} instance.
// */
// Response execute(Request request) throws IOException;
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/http/Header.java
// public class Header {
//
// private final String name;
// private final String value;
//
// public Header(String name, String value) {
// this.name = name;
// this.value = value;
// }
//
// public String getName() {
// return name;
// }
//
// public String getValue() {
// return value;
// }
//
// @Override
// public boolean equals(Object o) {
// if (this == o) {
// return true;
// }
// if (o == null || getClass() != o.getClass()) {
// return false;
// }
//
// Header header = (Header) o;
//
// if (name != null ? !name.equals(header.name) : header.name != null) {
// return false;
// }
// if (value != null ? !value.equals(header.value) : header.value != null) {
// return false;
// }
//
// return true;
// }
//
// @Override
// public int hashCode() {
// int result = name != null ? name.hashCode() : 0;
// result = 31 * result + (value != null ? value.hashCode() : 0);
// return result;
// }
//
// @Override
// public String toString() {
// return "Header{" + "name='" + name + '\'' + ", value='" + value + '\'' + '}';
// }
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/http/Request.java
// public class Request {
//
// private final String method;
// private final String url;
// private final List<Header> headers;
// private final TypedOutput body;
//
// public Request(String method, String url, List<Header> headers, TypedOutput body) {
// this.method = method;
// this.url = url;
// this.headers = headers;
// this.body = body;
// }
//
// /** HTTP method verb. */
// public String getMethod() {
// return method;
// }
//
// /** Target URL. */
// public String getUrl() {
// return url;
// }
//
// /** Returns an unmodifiable list of headers, never {@code null}. */
// public List<Header> getHeaders() {
// return headers;
// }
//
// /** Returns the request body or {@code null}. */
// public TypedOutput getBody() {
// return body;
// }
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/http/Response.java
// public class Response {
//
// private final String url;
// private final int status;
// private final String reason;
// private final List<Header> headers;
// private final TypedInput body;
//
// public Response(String url, int status, String reason, List<Header> headers, TypedInput body) {
// this.url = url;
// this.status = status;
// this.reason = reason;
// this.headers = headers;
// this.body = body;
// }
//
// /** Request URL. */
// public String getUrl() {
// return url;
// }
//
// /** Status line code. */
// public int getStatus() {
// return status;
// }
//
// /** Status line reason phrase. */
// public String getReason() {
// return reason;
// }
//
// /** An unmodifiable collection of headers. */
// public List<Header> getHeaders() {
// return headers;
// }
//
// /** Response body. May be {@code null}. */
// public TypedInput getBody() {
// return body;
// }
// }
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/TokenAuthenticator.java
import com.uphyca.idobata.http.Client;
import com.uphyca.idobata.http.Header;
import com.uphyca.idobata.http.Request;
import com.uphyca.idobata.http.Response;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
/*
* Copyright (C) 2014 uPhyca Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.uphyca.idobata;
/**
* Represents token authentication.
*
* @author Sosuke Masui (masui@uphyca.com)
*/
public class TokenAuthenticator implements RequestInterceptor {
/**
* The provider to rovides token to authenticate.
*/
public interface TokenProvider {
String get();
}
private final TokenProvider mTokenProvider;
/**
* @param tokenProvider The tokenProvider to obtain the token for authentication.
*/
public TokenAuthenticator(TokenProvider tokenProvider) {
mTokenProvider = tokenProvider;
}
/**
* @param token The token for authentication.
*/
public TokenAuthenticator(String token) {
this.mTokenProvider = new SimpleTokenProvider(token);
}
@Override
public Response execute(Client client, Request request) throws IdobataError { | List<Header> requestHeaders = new ArrayList<Header>(request.getHeaders()); |
uPhyca/idobata4j | idobata4j-core/src/main/java/com/uphyca/idobata/CookieAuthenticator.java | // Path: idobata4j-core/src/main/java/com/uphyca/idobata/http/Client.java
// public interface Client {
//
// /**
// * Synchronously execute an HTTP represented by {@code request} and encapsulate all response data
// * into a {@link Response} instance.
// */
// Response execute(Request request) throws IOException;
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/http/Request.java
// public class Request {
//
// private final String method;
// private final String url;
// private final List<Header> headers;
// private final TypedOutput body;
//
// public Request(String method, String url, List<Header> headers, TypedOutput body) {
// this.method = method;
// this.url = url;
// this.headers = headers;
// this.body = body;
// }
//
// /** HTTP method verb. */
// public String getMethod() {
// return method;
// }
//
// /** Target URL. */
// public String getUrl() {
// return url;
// }
//
// /** Returns an unmodifiable list of headers, never {@code null}. */
// public List<Header> getHeaders() {
// return headers;
// }
//
// /** Returns the request body or {@code null}. */
// public TypedOutput getBody() {
// return body;
// }
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/http/Response.java
// public class Response {
//
// private final String url;
// private final int status;
// private final String reason;
// private final List<Header> headers;
// private final TypedInput body;
//
// public Response(String url, int status, String reason, List<Header> headers, TypedInput body) {
// this.url = url;
// this.status = status;
// this.reason = reason;
// this.headers = headers;
// this.body = body;
// }
//
// /** Request URL. */
// public String getUrl() {
// return url;
// }
//
// /** Status line code. */
// public int getStatus() {
// return status;
// }
//
// /** Status line reason phrase. */
// public String getReason() {
// return reason;
// }
//
// /** An unmodifiable collection of headers. */
// public List<Header> getHeaders() {
// return headers;
// }
//
// /** Response body. May be {@code null}. */
// public TypedInput getBody() {
// return body;
// }
// }
| import com.uphyca.idobata.http.Client;
import com.uphyca.idobata.http.Request;
import com.uphyca.idobata.http.Response;
import java.io.IOException; | /*
* Copyright (C) 2014 uPhyca Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.uphyca.idobata;
/**
* Represents cookie authentication.
*
* @author Sosuke Masui (masui@uphyca.com)
*/
public class CookieAuthenticator implements RequestInterceptor {
@Override | // Path: idobata4j-core/src/main/java/com/uphyca/idobata/http/Client.java
// public interface Client {
//
// /**
// * Synchronously execute an HTTP represented by {@code request} and encapsulate all response data
// * into a {@link Response} instance.
// */
// Response execute(Request request) throws IOException;
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/http/Request.java
// public class Request {
//
// private final String method;
// private final String url;
// private final List<Header> headers;
// private final TypedOutput body;
//
// public Request(String method, String url, List<Header> headers, TypedOutput body) {
// this.method = method;
// this.url = url;
// this.headers = headers;
// this.body = body;
// }
//
// /** HTTP method verb. */
// public String getMethod() {
// return method;
// }
//
// /** Target URL. */
// public String getUrl() {
// return url;
// }
//
// /** Returns an unmodifiable list of headers, never {@code null}. */
// public List<Header> getHeaders() {
// return headers;
// }
//
// /** Returns the request body or {@code null}. */
// public TypedOutput getBody() {
// return body;
// }
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/http/Response.java
// public class Response {
//
// private final String url;
// private final int status;
// private final String reason;
// private final List<Header> headers;
// private final TypedInput body;
//
// public Response(String url, int status, String reason, List<Header> headers, TypedInput body) {
// this.url = url;
// this.status = status;
// this.reason = reason;
// this.headers = headers;
// this.body = body;
// }
//
// /** Request URL. */
// public String getUrl() {
// return url;
// }
//
// /** Status line code. */
// public int getStatus() {
// return status;
// }
//
// /** Status line reason phrase. */
// public String getReason() {
// return reason;
// }
//
// /** An unmodifiable collection of headers. */
// public List<Header> getHeaders() {
// return headers;
// }
//
// /** Response body. May be {@code null}. */
// public TypedInput getBody() {
// return body;
// }
// }
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/CookieAuthenticator.java
import com.uphyca.idobata.http.Client;
import com.uphyca.idobata.http.Request;
import com.uphyca.idobata.http.Response;
import java.io.IOException;
/*
* Copyright (C) 2014 uPhyca Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.uphyca.idobata;
/**
* Represents cookie authentication.
*
* @author Sosuke Masui (masui@uphyca.com)
*/
public class CookieAuthenticator implements RequestInterceptor {
@Override | public Response execute(Client client, Request request) throws IdobataError { |
uPhyca/idobata4j | idobata4j-core/src/main/java/com/uphyca/idobata/CookieAuthenticator.java | // Path: idobata4j-core/src/main/java/com/uphyca/idobata/http/Client.java
// public interface Client {
//
// /**
// * Synchronously execute an HTTP represented by {@code request} and encapsulate all response data
// * into a {@link Response} instance.
// */
// Response execute(Request request) throws IOException;
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/http/Request.java
// public class Request {
//
// private final String method;
// private final String url;
// private final List<Header> headers;
// private final TypedOutput body;
//
// public Request(String method, String url, List<Header> headers, TypedOutput body) {
// this.method = method;
// this.url = url;
// this.headers = headers;
// this.body = body;
// }
//
// /** HTTP method verb. */
// public String getMethod() {
// return method;
// }
//
// /** Target URL. */
// public String getUrl() {
// return url;
// }
//
// /** Returns an unmodifiable list of headers, never {@code null}. */
// public List<Header> getHeaders() {
// return headers;
// }
//
// /** Returns the request body or {@code null}. */
// public TypedOutput getBody() {
// return body;
// }
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/http/Response.java
// public class Response {
//
// private final String url;
// private final int status;
// private final String reason;
// private final List<Header> headers;
// private final TypedInput body;
//
// public Response(String url, int status, String reason, List<Header> headers, TypedInput body) {
// this.url = url;
// this.status = status;
// this.reason = reason;
// this.headers = headers;
// this.body = body;
// }
//
// /** Request URL. */
// public String getUrl() {
// return url;
// }
//
// /** Status line code. */
// public int getStatus() {
// return status;
// }
//
// /** Status line reason phrase. */
// public String getReason() {
// return reason;
// }
//
// /** An unmodifiable collection of headers. */
// public List<Header> getHeaders() {
// return headers;
// }
//
// /** Response body. May be {@code null}. */
// public TypedInput getBody() {
// return body;
// }
// }
| import com.uphyca.idobata.http.Client;
import com.uphyca.idobata.http.Request;
import com.uphyca.idobata.http.Response;
import java.io.IOException; | /*
* Copyright (C) 2014 uPhyca Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.uphyca.idobata;
/**
* Represents cookie authentication.
*
* @author Sosuke Masui (masui@uphyca.com)
*/
public class CookieAuthenticator implements RequestInterceptor {
@Override | // Path: idobata4j-core/src/main/java/com/uphyca/idobata/http/Client.java
// public interface Client {
//
// /**
// * Synchronously execute an HTTP represented by {@code request} and encapsulate all response data
// * into a {@link Response} instance.
// */
// Response execute(Request request) throws IOException;
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/http/Request.java
// public class Request {
//
// private final String method;
// private final String url;
// private final List<Header> headers;
// private final TypedOutput body;
//
// public Request(String method, String url, List<Header> headers, TypedOutput body) {
// this.method = method;
// this.url = url;
// this.headers = headers;
// this.body = body;
// }
//
// /** HTTP method verb. */
// public String getMethod() {
// return method;
// }
//
// /** Target URL. */
// public String getUrl() {
// return url;
// }
//
// /** Returns an unmodifiable list of headers, never {@code null}. */
// public List<Header> getHeaders() {
// return headers;
// }
//
// /** Returns the request body or {@code null}. */
// public TypedOutput getBody() {
// return body;
// }
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/http/Response.java
// public class Response {
//
// private final String url;
// private final int status;
// private final String reason;
// private final List<Header> headers;
// private final TypedInput body;
//
// public Response(String url, int status, String reason, List<Header> headers, TypedInput body) {
// this.url = url;
// this.status = status;
// this.reason = reason;
// this.headers = headers;
// this.body = body;
// }
//
// /** Request URL. */
// public String getUrl() {
// return url;
// }
//
// /** Status line code. */
// public int getStatus() {
// return status;
// }
//
// /** Status line reason phrase. */
// public String getReason() {
// return reason;
// }
//
// /** An unmodifiable collection of headers. */
// public List<Header> getHeaders() {
// return headers;
// }
//
// /** Response body. May be {@code null}. */
// public TypedInput getBody() {
// return body;
// }
// }
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/CookieAuthenticator.java
import com.uphyca.idobata.http.Client;
import com.uphyca.idobata.http.Request;
import com.uphyca.idobata.http.Response;
import java.io.IOException;
/*
* Copyright (C) 2014 uPhyca Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.uphyca.idobata;
/**
* Represents cookie authentication.
*
* @author Sosuke Masui (masui@uphyca.com)
*/
public class CookieAuthenticator implements RequestInterceptor {
@Override | public Response execute(Client client, Request request) throws IdobataError { |
uPhyca/idobata4j | idobata4j-core/src/main/java/com/uphyca/idobata/CookieAuthenticator.java | // Path: idobata4j-core/src/main/java/com/uphyca/idobata/http/Client.java
// public interface Client {
//
// /**
// * Synchronously execute an HTTP represented by {@code request} and encapsulate all response data
// * into a {@link Response} instance.
// */
// Response execute(Request request) throws IOException;
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/http/Request.java
// public class Request {
//
// private final String method;
// private final String url;
// private final List<Header> headers;
// private final TypedOutput body;
//
// public Request(String method, String url, List<Header> headers, TypedOutput body) {
// this.method = method;
// this.url = url;
// this.headers = headers;
// this.body = body;
// }
//
// /** HTTP method verb. */
// public String getMethod() {
// return method;
// }
//
// /** Target URL. */
// public String getUrl() {
// return url;
// }
//
// /** Returns an unmodifiable list of headers, never {@code null}. */
// public List<Header> getHeaders() {
// return headers;
// }
//
// /** Returns the request body or {@code null}. */
// public TypedOutput getBody() {
// return body;
// }
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/http/Response.java
// public class Response {
//
// private final String url;
// private final int status;
// private final String reason;
// private final List<Header> headers;
// private final TypedInput body;
//
// public Response(String url, int status, String reason, List<Header> headers, TypedInput body) {
// this.url = url;
// this.status = status;
// this.reason = reason;
// this.headers = headers;
// this.body = body;
// }
//
// /** Request URL. */
// public String getUrl() {
// return url;
// }
//
// /** Status line code. */
// public int getStatus() {
// return status;
// }
//
// /** Status line reason phrase. */
// public String getReason() {
// return reason;
// }
//
// /** An unmodifiable collection of headers. */
// public List<Header> getHeaders() {
// return headers;
// }
//
// /** Response body. May be {@code null}. */
// public TypedInput getBody() {
// return body;
// }
// }
| import com.uphyca.idobata.http.Client;
import com.uphyca.idobata.http.Request;
import com.uphyca.idobata.http.Response;
import java.io.IOException; | /*
* Copyright (C) 2014 uPhyca Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.uphyca.idobata;
/**
* Represents cookie authentication.
*
* @author Sosuke Masui (masui@uphyca.com)
*/
public class CookieAuthenticator implements RequestInterceptor {
@Override | // Path: idobata4j-core/src/main/java/com/uphyca/idobata/http/Client.java
// public interface Client {
//
// /**
// * Synchronously execute an HTTP represented by {@code request} and encapsulate all response data
// * into a {@link Response} instance.
// */
// Response execute(Request request) throws IOException;
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/http/Request.java
// public class Request {
//
// private final String method;
// private final String url;
// private final List<Header> headers;
// private final TypedOutput body;
//
// public Request(String method, String url, List<Header> headers, TypedOutput body) {
// this.method = method;
// this.url = url;
// this.headers = headers;
// this.body = body;
// }
//
// /** HTTP method verb. */
// public String getMethod() {
// return method;
// }
//
// /** Target URL. */
// public String getUrl() {
// return url;
// }
//
// /** Returns an unmodifiable list of headers, never {@code null}. */
// public List<Header> getHeaders() {
// return headers;
// }
//
// /** Returns the request body or {@code null}. */
// public TypedOutput getBody() {
// return body;
// }
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/http/Response.java
// public class Response {
//
// private final String url;
// private final int status;
// private final String reason;
// private final List<Header> headers;
// private final TypedInput body;
//
// public Response(String url, int status, String reason, List<Header> headers, TypedInput body) {
// this.url = url;
// this.status = status;
// this.reason = reason;
// this.headers = headers;
// this.body = body;
// }
//
// /** Request URL. */
// public String getUrl() {
// return url;
// }
//
// /** Status line code. */
// public int getStatus() {
// return status;
// }
//
// /** Status line reason phrase. */
// public String getReason() {
// return reason;
// }
//
// /** An unmodifiable collection of headers. */
// public List<Header> getHeaders() {
// return headers;
// }
//
// /** Response body. May be {@code null}. */
// public TypedInput getBody() {
// return body;
// }
// }
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/CookieAuthenticator.java
import com.uphyca.idobata.http.Client;
import com.uphyca.idobata.http.Request;
import com.uphyca.idobata.http.Response;
import java.io.IOException;
/*
* Copyright (C) 2014 uPhyca Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.uphyca.idobata;
/**
* Represents cookie authentication.
*
* @author Sosuke Masui (masui@uphyca.com)
*/
public class CookieAuthenticator implements RequestInterceptor {
@Override | public Response execute(Client client, Request request) throws IdobataError { |
uPhyca/idobata4j | idobata4j-core/src/main/java/com/uphyca/idobata/transform/JSONConverter.java | // Path: idobata4j-core/src/main/java/com/uphyca/idobata/http/TypedInput.java
// public interface TypedInput {
//
// /** Returns the mime type. */
// String mimeType();
//
// /** Length in bytes. Returns {@code -1} if length is unknown. */
// long length();
//
// /**
// * Read bytes as stream. Unless otherwise specified, this method may only be called once. It is
// * the responsibility of the caller to close the stream.
// */
// InputStream in() throws IOException;
// }
| import com.uphyca.idobata.event.*;
import com.uphyca.idobata.http.TypedInput;
import com.uphyca.idobata.model.*;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List; | /*
* Copyright (C) 2014 uPhyca Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.uphyca.idobata.transform;
/**
* A {@link com.uphyca.idobata.transform.Converter} which uses org.json for deserialization of entities.
*
* @author Sosuke Masui (masui@uphyca.com)
*/
public class JSONConverter implements Converter {
@Override | // Path: idobata4j-core/src/main/java/com/uphyca/idobata/http/TypedInput.java
// public interface TypedInput {
//
// /** Returns the mime type. */
// String mimeType();
//
// /** Length in bytes. Returns {@code -1} if length is unknown. */
// long length();
//
// /**
// * Read bytes as stream. Unless otherwise specified, this method may only be called once. It is
// * the responsibility of the caller to close the stream.
// */
// InputStream in() throws IOException;
// }
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/transform/JSONConverter.java
import com.uphyca.idobata.event.*;
import com.uphyca.idobata.http.TypedInput;
import com.uphyca.idobata.model.*;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;
/*
* Copyright (C) 2014 uPhyca Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.uphyca.idobata.transform;
/**
* A {@link com.uphyca.idobata.transform.Converter} which uses org.json for deserialization of entities.
*
* @author Sosuke Masui (masui@uphyca.com)
*/
public class JSONConverter implements Converter {
@Override | public Object convert(TypedInput body, Type type) throws ConversionException, IOException { |
uPhyca/idobata4j | idobata4j-core/src/test/java/com/uphyca/idobata/IdobataStreamTest.java | // Path: idobata4j-core/src/main/java/com/uphyca/idobata/event/MemberStatusChangedEvent.java
// public interface MemberStatusChangedEvent extends Serializable {
// long getId();
//
// String getStatus();
//
// String getType();
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/event/MessageCreatedEvent.java
// public interface MessageCreatedEvent extends Serializable {
// long getId();
//
// String getBody();
//
// String getBodyPlain();
//
// List<String> getImageUrls();
//
// boolean isMultiline();
//
// List<Long> getMentions();
//
// String getCreatedAt();
//
// long getRoomId();
//
// String getRoomName();
//
// String getOrganizationSlug();
//
// String getSenderType();
//
// long getSenderId();
//
// String getSenderName();
//
// String getSenderIconUrl();
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/event/RoomTouchedEvent.java
// public interface RoomTouchedEvent extends Serializable {
//
// long getRoomId();
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/transform/Converter.java
// public interface Converter {
//
// /**
// * Convert an HTTP response body to a concrete object of the specified type.
// *
// * @param body HTTP response body.
// * @param type Target object type.
// * @return Instance of {@code type} which will be cast by the caller.
// * @throws Exception
// */
// <T> T convert(TypedInput body, Type type) throws ConversionException, IOException;
// }
| import com.pusher.client.Pusher;
import com.pusher.client.channel.PresenceChannel;
import com.pusher.client.channel.PresenceChannelEventListener;
import com.uphyca.idobata.event.MemberStatusChangedEvent;
import com.uphyca.idobata.event.MessageCreatedEvent;
import com.uphyca.idobata.event.RoomTouchedEvent;
import com.uphyca.idobata.transform.Converter;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import static org.mockito.BDDMockito.*; | /*
* Copyright (C) 2014 uPhyca Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.uphyca.idobata;
/**
* @author Sosuke Masui (masui@uphyca.com)
*/
@RunWith(MockitoJUnitRunner.class)
public class IdobataStreamTest {
IdobataStreamImpl underTest;
@Mock
Idobata idobata;
@Mock
Pusher pusher;
@Mock
PresenceChannel presenceChannel;
String channelName;
@Mock | // Path: idobata4j-core/src/main/java/com/uphyca/idobata/event/MemberStatusChangedEvent.java
// public interface MemberStatusChangedEvent extends Serializable {
// long getId();
//
// String getStatus();
//
// String getType();
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/event/MessageCreatedEvent.java
// public interface MessageCreatedEvent extends Serializable {
// long getId();
//
// String getBody();
//
// String getBodyPlain();
//
// List<String> getImageUrls();
//
// boolean isMultiline();
//
// List<Long> getMentions();
//
// String getCreatedAt();
//
// long getRoomId();
//
// String getRoomName();
//
// String getOrganizationSlug();
//
// String getSenderType();
//
// long getSenderId();
//
// String getSenderName();
//
// String getSenderIconUrl();
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/event/RoomTouchedEvent.java
// public interface RoomTouchedEvent extends Serializable {
//
// long getRoomId();
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/transform/Converter.java
// public interface Converter {
//
// /**
// * Convert an HTTP response body to a concrete object of the specified type.
// *
// * @param body HTTP response body.
// * @param type Target object type.
// * @return Instance of {@code type} which will be cast by the caller.
// * @throws Exception
// */
// <T> T convert(TypedInput body, Type type) throws ConversionException, IOException;
// }
// Path: idobata4j-core/src/test/java/com/uphyca/idobata/IdobataStreamTest.java
import com.pusher.client.Pusher;
import com.pusher.client.channel.PresenceChannel;
import com.pusher.client.channel.PresenceChannelEventListener;
import com.uphyca.idobata.event.MemberStatusChangedEvent;
import com.uphyca.idobata.event.MessageCreatedEvent;
import com.uphyca.idobata.event.RoomTouchedEvent;
import com.uphyca.idobata.transform.Converter;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import static org.mockito.BDDMockito.*;
/*
* Copyright (C) 2014 uPhyca Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.uphyca.idobata;
/**
* @author Sosuke Masui (masui@uphyca.com)
*/
@RunWith(MockitoJUnitRunner.class)
public class IdobataStreamTest {
IdobataStreamImpl underTest;
@Mock
Idobata idobata;
@Mock
Pusher pusher;
@Mock
PresenceChannel presenceChannel;
String channelName;
@Mock | Converter converter; |
uPhyca/idobata4j | idobata4j-core/src/test/java/com/uphyca/idobata/IdobataStreamTest.java | // Path: idobata4j-core/src/main/java/com/uphyca/idobata/event/MemberStatusChangedEvent.java
// public interface MemberStatusChangedEvent extends Serializable {
// long getId();
//
// String getStatus();
//
// String getType();
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/event/MessageCreatedEvent.java
// public interface MessageCreatedEvent extends Serializable {
// long getId();
//
// String getBody();
//
// String getBodyPlain();
//
// List<String> getImageUrls();
//
// boolean isMultiline();
//
// List<Long> getMentions();
//
// String getCreatedAt();
//
// long getRoomId();
//
// String getRoomName();
//
// String getOrganizationSlug();
//
// String getSenderType();
//
// long getSenderId();
//
// String getSenderName();
//
// String getSenderIconUrl();
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/event/RoomTouchedEvent.java
// public interface RoomTouchedEvent extends Serializable {
//
// long getRoomId();
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/transform/Converter.java
// public interface Converter {
//
// /**
// * Convert an HTTP response body to a concrete object of the specified type.
// *
// * @param body HTTP response body.
// * @param type Target object type.
// * @return Instance of {@code type} which will be cast by the caller.
// * @throws Exception
// */
// <T> T convert(TypedInput body, Type type) throws ConversionException, IOException;
// }
| import com.pusher.client.Pusher;
import com.pusher.client.channel.PresenceChannel;
import com.pusher.client.channel.PresenceChannelEventListener;
import com.uphyca.idobata.event.MemberStatusChangedEvent;
import com.uphyca.idobata.event.MessageCreatedEvent;
import com.uphyca.idobata.event.RoomTouchedEvent;
import com.uphyca.idobata.transform.Converter;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import static org.mockito.BDDMockito.*; | /*
* Copyright (C) 2014 uPhyca Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.uphyca.idobata;
/**
* @author Sosuke Masui (masui@uphyca.com)
*/
@RunWith(MockitoJUnitRunner.class)
public class IdobataStreamTest {
IdobataStreamImpl underTest;
@Mock
Idobata idobata;
@Mock
Pusher pusher;
@Mock
PresenceChannel presenceChannel;
String channelName;
@Mock
Converter converter;
@Before
public void setUp() throws Exception {
channelName = "abc";
given(pusher.subscribePresence(channelName)).willReturn(presenceChannel);
underTest = new IdobataStreamImpl(idobata, pusher, channelName, converter);
}
@Test
public void close() throws Exception {
underTest.close();
verify(pusher).disconnect();
}
@Test
public void subscribeMessageCreated() throws Exception {
final String eventName = "message_created";
| // Path: idobata4j-core/src/main/java/com/uphyca/idobata/event/MemberStatusChangedEvent.java
// public interface MemberStatusChangedEvent extends Serializable {
// long getId();
//
// String getStatus();
//
// String getType();
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/event/MessageCreatedEvent.java
// public interface MessageCreatedEvent extends Serializable {
// long getId();
//
// String getBody();
//
// String getBodyPlain();
//
// List<String> getImageUrls();
//
// boolean isMultiline();
//
// List<Long> getMentions();
//
// String getCreatedAt();
//
// long getRoomId();
//
// String getRoomName();
//
// String getOrganizationSlug();
//
// String getSenderType();
//
// long getSenderId();
//
// String getSenderName();
//
// String getSenderIconUrl();
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/event/RoomTouchedEvent.java
// public interface RoomTouchedEvent extends Serializable {
//
// long getRoomId();
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/transform/Converter.java
// public interface Converter {
//
// /**
// * Convert an HTTP response body to a concrete object of the specified type.
// *
// * @param body HTTP response body.
// * @param type Target object type.
// * @return Instance of {@code type} which will be cast by the caller.
// * @throws Exception
// */
// <T> T convert(TypedInput body, Type type) throws ConversionException, IOException;
// }
// Path: idobata4j-core/src/test/java/com/uphyca/idobata/IdobataStreamTest.java
import com.pusher.client.Pusher;
import com.pusher.client.channel.PresenceChannel;
import com.pusher.client.channel.PresenceChannelEventListener;
import com.uphyca.idobata.event.MemberStatusChangedEvent;
import com.uphyca.idobata.event.MessageCreatedEvent;
import com.uphyca.idobata.event.RoomTouchedEvent;
import com.uphyca.idobata.transform.Converter;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import static org.mockito.BDDMockito.*;
/*
* Copyright (C) 2014 uPhyca Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.uphyca.idobata;
/**
* @author Sosuke Masui (masui@uphyca.com)
*/
@RunWith(MockitoJUnitRunner.class)
public class IdobataStreamTest {
IdobataStreamImpl underTest;
@Mock
Idobata idobata;
@Mock
Pusher pusher;
@Mock
PresenceChannel presenceChannel;
String channelName;
@Mock
Converter converter;
@Before
public void setUp() throws Exception {
channelName = "abc";
given(pusher.subscribePresence(channelName)).willReturn(presenceChannel);
underTest = new IdobataStreamImpl(idobata, pusher, channelName, converter);
}
@Test
public void close() throws Exception {
underTest.close();
verify(pusher).disconnect();
}
@Test
public void subscribeMessageCreated() throws Exception {
final String eventName = "message_created";
| IdobataStream.Listener<MessageCreatedEvent> listener = mock(IdobataStream.Listener.class); |
uPhyca/idobata4j | idobata4j-core/src/test/java/com/uphyca/idobata/IdobataStreamTest.java | // Path: idobata4j-core/src/main/java/com/uphyca/idobata/event/MemberStatusChangedEvent.java
// public interface MemberStatusChangedEvent extends Serializable {
// long getId();
//
// String getStatus();
//
// String getType();
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/event/MessageCreatedEvent.java
// public interface MessageCreatedEvent extends Serializable {
// long getId();
//
// String getBody();
//
// String getBodyPlain();
//
// List<String> getImageUrls();
//
// boolean isMultiline();
//
// List<Long> getMentions();
//
// String getCreatedAt();
//
// long getRoomId();
//
// String getRoomName();
//
// String getOrganizationSlug();
//
// String getSenderType();
//
// long getSenderId();
//
// String getSenderName();
//
// String getSenderIconUrl();
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/event/RoomTouchedEvent.java
// public interface RoomTouchedEvent extends Serializable {
//
// long getRoomId();
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/transform/Converter.java
// public interface Converter {
//
// /**
// * Convert an HTTP response body to a concrete object of the specified type.
// *
// * @param body HTTP response body.
// * @param type Target object type.
// * @return Instance of {@code type} which will be cast by the caller.
// * @throws Exception
// */
// <T> T convert(TypedInput body, Type type) throws ConversionException, IOException;
// }
| import com.pusher.client.Pusher;
import com.pusher.client.channel.PresenceChannel;
import com.pusher.client.channel.PresenceChannelEventListener;
import com.uphyca.idobata.event.MemberStatusChangedEvent;
import com.uphyca.idobata.event.MessageCreatedEvent;
import com.uphyca.idobata.event.RoomTouchedEvent;
import com.uphyca.idobata.transform.Converter;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import static org.mockito.BDDMockito.*; | channelName = "abc";
given(pusher.subscribePresence(channelName)).willReturn(presenceChannel);
underTest = new IdobataStreamImpl(idobata, pusher, channelName, converter);
}
@Test
public void close() throws Exception {
underTest.close();
verify(pusher).disconnect();
}
@Test
public void subscribeMessageCreated() throws Exception {
final String eventName = "message_created";
IdobataStream.Listener<MessageCreatedEvent> listener = mock(IdobataStream.Listener.class);
underTest.subscribeMessageCreated(listener);
underTest.onEvent(channelName, eventName, "{}");
verify(presenceChannel).bind(eq(eventName), any(PresenceChannelEventListener.class));
verify(listener).onEvent(any(MessageCreatedEvent.class));
}
@Test
public void subscribeMemberStatusChanged() throws Exception {
final String eventName = "member_status_changed";
| // Path: idobata4j-core/src/main/java/com/uphyca/idobata/event/MemberStatusChangedEvent.java
// public interface MemberStatusChangedEvent extends Serializable {
// long getId();
//
// String getStatus();
//
// String getType();
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/event/MessageCreatedEvent.java
// public interface MessageCreatedEvent extends Serializable {
// long getId();
//
// String getBody();
//
// String getBodyPlain();
//
// List<String> getImageUrls();
//
// boolean isMultiline();
//
// List<Long> getMentions();
//
// String getCreatedAt();
//
// long getRoomId();
//
// String getRoomName();
//
// String getOrganizationSlug();
//
// String getSenderType();
//
// long getSenderId();
//
// String getSenderName();
//
// String getSenderIconUrl();
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/event/RoomTouchedEvent.java
// public interface RoomTouchedEvent extends Serializable {
//
// long getRoomId();
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/transform/Converter.java
// public interface Converter {
//
// /**
// * Convert an HTTP response body to a concrete object of the specified type.
// *
// * @param body HTTP response body.
// * @param type Target object type.
// * @return Instance of {@code type} which will be cast by the caller.
// * @throws Exception
// */
// <T> T convert(TypedInput body, Type type) throws ConversionException, IOException;
// }
// Path: idobata4j-core/src/test/java/com/uphyca/idobata/IdobataStreamTest.java
import com.pusher.client.Pusher;
import com.pusher.client.channel.PresenceChannel;
import com.pusher.client.channel.PresenceChannelEventListener;
import com.uphyca.idobata.event.MemberStatusChangedEvent;
import com.uphyca.idobata.event.MessageCreatedEvent;
import com.uphyca.idobata.event.RoomTouchedEvent;
import com.uphyca.idobata.transform.Converter;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import static org.mockito.BDDMockito.*;
channelName = "abc";
given(pusher.subscribePresence(channelName)).willReturn(presenceChannel);
underTest = new IdobataStreamImpl(idobata, pusher, channelName, converter);
}
@Test
public void close() throws Exception {
underTest.close();
verify(pusher).disconnect();
}
@Test
public void subscribeMessageCreated() throws Exception {
final String eventName = "message_created";
IdobataStream.Listener<MessageCreatedEvent> listener = mock(IdobataStream.Listener.class);
underTest.subscribeMessageCreated(listener);
underTest.onEvent(channelName, eventName, "{}");
verify(presenceChannel).bind(eq(eventName), any(PresenceChannelEventListener.class));
verify(listener).onEvent(any(MessageCreatedEvent.class));
}
@Test
public void subscribeMemberStatusChanged() throws Exception {
final String eventName = "member_status_changed";
| IdobataStream.Listener<MemberStatusChangedEvent> listener = mock(IdobataStream.Listener.class); |
uPhyca/idobata4j | idobata4j-core/src/test/java/com/uphyca/idobata/IdobataStreamTest.java | // Path: idobata4j-core/src/main/java/com/uphyca/idobata/event/MemberStatusChangedEvent.java
// public interface MemberStatusChangedEvent extends Serializable {
// long getId();
//
// String getStatus();
//
// String getType();
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/event/MessageCreatedEvent.java
// public interface MessageCreatedEvent extends Serializable {
// long getId();
//
// String getBody();
//
// String getBodyPlain();
//
// List<String> getImageUrls();
//
// boolean isMultiline();
//
// List<Long> getMentions();
//
// String getCreatedAt();
//
// long getRoomId();
//
// String getRoomName();
//
// String getOrganizationSlug();
//
// String getSenderType();
//
// long getSenderId();
//
// String getSenderName();
//
// String getSenderIconUrl();
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/event/RoomTouchedEvent.java
// public interface RoomTouchedEvent extends Serializable {
//
// long getRoomId();
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/transform/Converter.java
// public interface Converter {
//
// /**
// * Convert an HTTP response body to a concrete object of the specified type.
// *
// * @param body HTTP response body.
// * @param type Target object type.
// * @return Instance of {@code type} which will be cast by the caller.
// * @throws Exception
// */
// <T> T convert(TypedInput body, Type type) throws ConversionException, IOException;
// }
| import com.pusher.client.Pusher;
import com.pusher.client.channel.PresenceChannel;
import com.pusher.client.channel.PresenceChannelEventListener;
import com.uphyca.idobata.event.MemberStatusChangedEvent;
import com.uphyca.idobata.event.MessageCreatedEvent;
import com.uphyca.idobata.event.RoomTouchedEvent;
import com.uphyca.idobata.transform.Converter;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import static org.mockito.BDDMockito.*; | @Test
public void subscribeMessageCreated() throws Exception {
final String eventName = "message_created";
IdobataStream.Listener<MessageCreatedEvent> listener = mock(IdobataStream.Listener.class);
underTest.subscribeMessageCreated(listener);
underTest.onEvent(channelName, eventName, "{}");
verify(presenceChannel).bind(eq(eventName), any(PresenceChannelEventListener.class));
verify(listener).onEvent(any(MessageCreatedEvent.class));
}
@Test
public void subscribeMemberStatusChanged() throws Exception {
final String eventName = "member_status_changed";
IdobataStream.Listener<MemberStatusChangedEvent> listener = mock(IdobataStream.Listener.class);
underTest.subscribeMemberStatusChanged(listener);
underTest.onEvent(channelName, eventName, "{}");
verify(presenceChannel).bind(eq(eventName), any(PresenceChannelEventListener.class));
verify(listener).onEvent(any(MemberStatusChangedEvent.class));
}
@Test
public void subscribeRoomTouched() throws Exception {
final String eventName = "room_touched";
| // Path: idobata4j-core/src/main/java/com/uphyca/idobata/event/MemberStatusChangedEvent.java
// public interface MemberStatusChangedEvent extends Serializable {
// long getId();
//
// String getStatus();
//
// String getType();
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/event/MessageCreatedEvent.java
// public interface MessageCreatedEvent extends Serializable {
// long getId();
//
// String getBody();
//
// String getBodyPlain();
//
// List<String> getImageUrls();
//
// boolean isMultiline();
//
// List<Long> getMentions();
//
// String getCreatedAt();
//
// long getRoomId();
//
// String getRoomName();
//
// String getOrganizationSlug();
//
// String getSenderType();
//
// long getSenderId();
//
// String getSenderName();
//
// String getSenderIconUrl();
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/event/RoomTouchedEvent.java
// public interface RoomTouchedEvent extends Serializable {
//
// long getRoomId();
// }
//
// Path: idobata4j-core/src/main/java/com/uphyca/idobata/transform/Converter.java
// public interface Converter {
//
// /**
// * Convert an HTTP response body to a concrete object of the specified type.
// *
// * @param body HTTP response body.
// * @param type Target object type.
// * @return Instance of {@code type} which will be cast by the caller.
// * @throws Exception
// */
// <T> T convert(TypedInput body, Type type) throws ConversionException, IOException;
// }
// Path: idobata4j-core/src/test/java/com/uphyca/idobata/IdobataStreamTest.java
import com.pusher.client.Pusher;
import com.pusher.client.channel.PresenceChannel;
import com.pusher.client.channel.PresenceChannelEventListener;
import com.uphyca.idobata.event.MemberStatusChangedEvent;
import com.uphyca.idobata.event.MessageCreatedEvent;
import com.uphyca.idobata.event.RoomTouchedEvent;
import com.uphyca.idobata.transform.Converter;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import static org.mockito.BDDMockito.*;
@Test
public void subscribeMessageCreated() throws Exception {
final String eventName = "message_created";
IdobataStream.Listener<MessageCreatedEvent> listener = mock(IdobataStream.Listener.class);
underTest.subscribeMessageCreated(listener);
underTest.onEvent(channelName, eventName, "{}");
verify(presenceChannel).bind(eq(eventName), any(PresenceChannelEventListener.class));
verify(listener).onEvent(any(MessageCreatedEvent.class));
}
@Test
public void subscribeMemberStatusChanged() throws Exception {
final String eventName = "member_status_changed";
IdobataStream.Listener<MemberStatusChangedEvent> listener = mock(IdobataStream.Listener.class);
underTest.subscribeMemberStatusChanged(listener);
underTest.onEvent(channelName, eventName, "{}");
verify(presenceChannel).bind(eq(eventName), any(PresenceChannelEventListener.class));
verify(listener).onEvent(any(MemberStatusChangedEvent.class));
}
@Test
public void subscribeRoomTouched() throws Exception {
final String eventName = "room_touched";
| IdobataStream.Listener<RoomTouchedEvent> listener = mock(IdobataStream.Listener.class); |
scijava/scijava-ui-swing | src/main/java/org/scijava/ui/swing/widget/SwingMdiInputHarvester.java | // Path: src/main/java/org/scijava/ui/swing/mdi/SwingMdiUI.java
// @Plugin(type = UserInterface.class, name = SwingMdiUI.NAME,
// priority = Priority.LOW)
// public class SwingMdiUI extends AbstractSwingUI {
//
// public static final String NAME = "swing-mdi";
//
// @Parameter
// private EventService eventService;
//
// @Parameter
// private UIService uiService;
//
// private JMDIDesktopPane desktopPane;
//
// private JScrollPane scrollPane;
//
// // -- UserInterface methods --
//
// @Override
// public Desktop getDesktop() {
// return desktopPane;
// }
//
// @Override
// public SwingMdiDisplayWindow createDisplayWindow(Display<?> display) {
// final SwingMdiDisplayWindow displayWindow = new SwingMdiDisplayWindow();
//
// // broadcast internal frame events
// displayWindow
// .addEventDispatcher(new InternalFrameEventDispatcher(display));
//
// // broadcast drag-and-drop events
// new AWTDropTargetEventDispatcher(display, eventService);
//
// return displayWindow;
// }
//
// @Override
// public SwingMdiDialogPrompt dialogPrompt(final String message,
// final String title, final MessageType msg, final OptionType option)
// {
// final UserInterface ui = uiService.getDefaultUI();
// return new SwingMdiDialogPrompt(ui, message, title, msg, option);
// }
//
// // -- Internal methods --
//
// @Override
// protected void setupAppFrame() {
// final SwingApplicationFrame appFrame = getApplicationFrame();
// desktopPane = new JMDIDesktopPane();
// // TODO desktopPane.setTransferHandler(new DropFileTransferHandler());
// scrollPane = new JScrollPane();
// scrollPane.setViewportView(desktopPane);
// desktopPane.setBackground(new Color(200, 200, 255));
// appFrame.getContentPane().add(scrollPane);
// appFrame.setBounds(getWorkSpaceBounds());
// }
//
// @Override
// protected void setupConsole() {
// final SwingConsolePane cPane = getConsolePane();
// if (cPane == null) return;
// final JInternalFrame frame = new JInternalFrame("Console");
// desktopPane.add(frame);
// frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
// frame.setContentPane(cPane.getComponent());
// frame.setJMenuBar(createConsoleMenu());
// frame.pack();
// cPane.setWindow(frame);
// }
//
// // -- Helper methods --
//
// private Rectangle getWorkSpaceBounds() {
// return GraphicsEnvironment.getLocalGraphicsEnvironment()
// .getMaximumWindowBounds();
// }
//
// }
| import org.scijava.plugin.Plugin;
import org.scijava.ui.swing.mdi.SwingMdiUI;
import org.scijava.widget.InputHarvester;
import org.scijava.module.process.PreprocessorPlugin; | /*
* #%L
* SciJava UI components for Java Swing.
* %%
* Copyright (C) 2010 - 2021 SciJava developers.
* %%
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
* #L%
*/
package org.scijava.ui.swing.widget;
/**
* SwingInputHarvester is an {@link InputHarvester} that collects input
* parameter values from the user using a {@link SwingInputPanel} dialog box.
*
* @author Curtis Rueden
*/
@Plugin(type = PreprocessorPlugin.class, priority = InputHarvester.PRIORITY)
public class SwingMdiInputHarvester extends SwingInputHarvester {
// TODO - Show an internal (MDI-style) dialog box.
// -- Internal methods --
@Override
protected String getUI() { | // Path: src/main/java/org/scijava/ui/swing/mdi/SwingMdiUI.java
// @Plugin(type = UserInterface.class, name = SwingMdiUI.NAME,
// priority = Priority.LOW)
// public class SwingMdiUI extends AbstractSwingUI {
//
// public static final String NAME = "swing-mdi";
//
// @Parameter
// private EventService eventService;
//
// @Parameter
// private UIService uiService;
//
// private JMDIDesktopPane desktopPane;
//
// private JScrollPane scrollPane;
//
// // -- UserInterface methods --
//
// @Override
// public Desktop getDesktop() {
// return desktopPane;
// }
//
// @Override
// public SwingMdiDisplayWindow createDisplayWindow(Display<?> display) {
// final SwingMdiDisplayWindow displayWindow = new SwingMdiDisplayWindow();
//
// // broadcast internal frame events
// displayWindow
// .addEventDispatcher(new InternalFrameEventDispatcher(display));
//
// // broadcast drag-and-drop events
// new AWTDropTargetEventDispatcher(display, eventService);
//
// return displayWindow;
// }
//
// @Override
// public SwingMdiDialogPrompt dialogPrompt(final String message,
// final String title, final MessageType msg, final OptionType option)
// {
// final UserInterface ui = uiService.getDefaultUI();
// return new SwingMdiDialogPrompt(ui, message, title, msg, option);
// }
//
// // -- Internal methods --
//
// @Override
// protected void setupAppFrame() {
// final SwingApplicationFrame appFrame = getApplicationFrame();
// desktopPane = new JMDIDesktopPane();
// // TODO desktopPane.setTransferHandler(new DropFileTransferHandler());
// scrollPane = new JScrollPane();
// scrollPane.setViewportView(desktopPane);
// desktopPane.setBackground(new Color(200, 200, 255));
// appFrame.getContentPane().add(scrollPane);
// appFrame.setBounds(getWorkSpaceBounds());
// }
//
// @Override
// protected void setupConsole() {
// final SwingConsolePane cPane = getConsolePane();
// if (cPane == null) return;
// final JInternalFrame frame = new JInternalFrame("Console");
// desktopPane.add(frame);
// frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
// frame.setContentPane(cPane.getComponent());
// frame.setJMenuBar(createConsoleMenu());
// frame.pack();
// cPane.setWindow(frame);
// }
//
// // -- Helper methods --
//
// private Rectangle getWorkSpaceBounds() {
// return GraphicsEnvironment.getLocalGraphicsEnvironment()
// .getMaximumWindowBounds();
// }
//
// }
// Path: src/main/java/org/scijava/ui/swing/widget/SwingMdiInputHarvester.java
import org.scijava.plugin.Plugin;
import org.scijava.ui.swing.mdi.SwingMdiUI;
import org.scijava.widget.InputHarvester;
import org.scijava.module.process.PreprocessorPlugin;
/*
* #%L
* SciJava UI components for Java Swing.
* %%
* Copyright (C) 2010 - 2021 SciJava developers.
* %%
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
* #L%
*/
package org.scijava.ui.swing.widget;
/**
* SwingInputHarvester is an {@link InputHarvester} that collects input
* parameter values from the user using a {@link SwingInputPanel} dialog box.
*
* @author Curtis Rueden
*/
@Plugin(type = PreprocessorPlugin.class, priority = InputHarvester.PRIORITY)
public class SwingMdiInputHarvester extends SwingInputHarvester {
// TODO - Show an internal (MDI-style) dialog box.
// -- Internal methods --
@Override
protected String getUI() { | return SwingMdiUI.NAME; |
scijava/scijava-ui-swing | src/main/java/org/scijava/ui/swing/viewer/table/SwingTableDisplayViewer.java | // Path: src/main/java/org/scijava/ui/swing/SwingUI.java
// public interface SwingUI {
//
// public static final String NAME = "swing";
//
// }
| import org.scijava.table.Table;
import org.scijava.ui.viewer.table.AbstractTableDisplayViewer;
import org.scijava.display.Display;
import org.scijava.plugin.Plugin;
import org.scijava.ui.UserInterface;
import org.scijava.ui.swing.SwingUI;
import org.scijava.ui.viewer.DisplayViewer;
import org.scijava.ui.viewer.DisplayWindow;
import javax.swing.JTable; | /*
* #%L
* SciJava UI components for Java Swing.
* %%
* Copyright (C) 2010 - 2021 SciJava developers.
* %%
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
* #L%
*/
package org.scijava.ui.swing.viewer.table;
/**
* A Swing {@link Table} display viewer, which displays tables in a
* {@link JTable}.
*
* @author Curtis Rueden
*/
@Plugin(type = DisplayViewer.class)
public class SwingTableDisplayViewer extends AbstractTableDisplayViewer {
@Override
public boolean isCompatible(final UserInterface ui) {
// TODO: Consider whether to use an interface for Swing UIs instead? | // Path: src/main/java/org/scijava/ui/swing/SwingUI.java
// public interface SwingUI {
//
// public static final String NAME = "swing";
//
// }
// Path: src/main/java/org/scijava/ui/swing/viewer/table/SwingTableDisplayViewer.java
import org.scijava.table.Table;
import org.scijava.ui.viewer.table.AbstractTableDisplayViewer;
import org.scijava.display.Display;
import org.scijava.plugin.Plugin;
import org.scijava.ui.UserInterface;
import org.scijava.ui.swing.SwingUI;
import org.scijava.ui.viewer.DisplayViewer;
import org.scijava.ui.viewer.DisplayWindow;
import javax.swing.JTable;
/*
* #%L
* SciJava UI components for Java Swing.
* %%
* Copyright (C) 2010 - 2021 SciJava developers.
* %%
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
* #L%
*/
package org.scijava.ui.swing.viewer.table;
/**
* A Swing {@link Table} display viewer, which displays tables in a
* {@link JTable}.
*
* @author Curtis Rueden
*/
@Plugin(type = DisplayViewer.class)
public class SwingTableDisplayViewer extends AbstractTableDisplayViewer {
@Override
public boolean isCompatible(final UserInterface ui) {
// TODO: Consider whether to use an interface for Swing UIs instead? | return ui instanceof SwingUI; |
scijava/scijava-ui-swing | src/main/java/org/scijava/ui/swing/viewer/EasySwingDisplayViewer.java | // Path: src/main/java/org/scijava/ui/swing/SwingUI.java
// public interface SwingUI {
//
// public static final String NAME = "swing";
//
// }
| import javax.swing.JPanel;
import org.scijava.command.Command;
import org.scijava.display.Display;
import org.scijava.display.event.DisplayDeletedEvent;
import org.scijava.object.ObjectService;
import org.scijava.plugin.Parameter;
import org.scijava.ui.UserInterface;
import org.scijava.ui.swing.SwingUI;
import org.scijava.ui.viewer.AbstractDisplayViewer;
import org.scijava.ui.viewer.DisplayPanel;
import org.scijava.ui.viewer.DisplayWindow;
import java.awt.BorderLayout; | /*
* #%L
* SciJava UI components for Java Swing.
* %%
* Copyright (C) 2010 - 2021 SciJava developers.
* %%
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
* #L%
*/
package org.scijava.ui.swing.viewer;
/**
* Class helping to build a simple Swing {@link JPanel} viewer for any object of
* class T declared as a {@link org.scijava.ItemIO} output {@link Parameter} in
* a {@link Command}.
*
* @param <T> class of object needed to be displayed in a Swing UI
* @author Matthias Arzt
* @see <a href="https://github.com/maarzt/example-imagej-display">Usage
* example</a>
* @see <a href=
* "https://forum.image.sc/t/displaying-and-using-and-any-object-in-a-scijava-fiji-command">Image.sc
* forum thread</a>
*/
public abstract class EasySwingDisplayViewer<T> extends
AbstractDisplayViewer<T>
{
private final Class<T> classOfObject;
@Parameter
ObjectService objectService;
protected EasySwingDisplayViewer(Class<T> classOfObject) {
this.classOfObject = classOfObject;
}
@Override
public boolean isCompatible(final UserInterface ui) { | // Path: src/main/java/org/scijava/ui/swing/SwingUI.java
// public interface SwingUI {
//
// public static final String NAME = "swing";
//
// }
// Path: src/main/java/org/scijava/ui/swing/viewer/EasySwingDisplayViewer.java
import javax.swing.JPanel;
import org.scijava.command.Command;
import org.scijava.display.Display;
import org.scijava.display.event.DisplayDeletedEvent;
import org.scijava.object.ObjectService;
import org.scijava.plugin.Parameter;
import org.scijava.ui.UserInterface;
import org.scijava.ui.swing.SwingUI;
import org.scijava.ui.viewer.AbstractDisplayViewer;
import org.scijava.ui.viewer.DisplayPanel;
import org.scijava.ui.viewer.DisplayWindow;
import java.awt.BorderLayout;
/*
* #%L
* SciJava UI components for Java Swing.
* %%
* Copyright (C) 2010 - 2021 SciJava developers.
* %%
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
* #L%
*/
package org.scijava.ui.swing.viewer;
/**
* Class helping to build a simple Swing {@link JPanel} viewer for any object of
* class T declared as a {@link org.scijava.ItemIO} output {@link Parameter} in
* a {@link Command}.
*
* @param <T> class of object needed to be displayed in a Swing UI
* @author Matthias Arzt
* @see <a href="https://github.com/maarzt/example-imagej-display">Usage
* example</a>
* @see <a href=
* "https://forum.image.sc/t/displaying-and-using-and-any-object-in-a-scijava-fiji-command">Image.sc
* forum thread</a>
*/
public abstract class EasySwingDisplayViewer<T> extends
AbstractDisplayViewer<T>
{
private final Class<T> classOfObject;
@Parameter
ObjectService objectService;
protected EasySwingDisplayViewer(Class<T> classOfObject) {
this.classOfObject = classOfObject;
}
@Override
public boolean isCompatible(final UserInterface ui) { | return ui instanceof SwingUI; |
scijava/scijava-ui-swing | src/main/java/org/scijava/ui/swing/widget/SwingInputWidget.java | // Path: src/main/java/org/scijava/ui/swing/SwingUI.java
// public interface SwingUI {
//
// public static final String NAME = "swing";
//
// }
| import javax.swing.JPanel;
import net.miginfocom.swing.MigLayout;
import org.scijava.ui.AbstractUIInputWidget;
import org.scijava.ui.UserInterface;
import org.scijava.ui.swing.SwingUI;
import org.scijava.widget.WidgetModel;
import javax.swing.JComponent; | /*
* #%L
* SciJava UI components for Java Swing.
* %%
* Copyright (C) 2010 - 2021 SciJava developers.
* %%
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
* #L%
*/
package org.scijava.ui.swing.widget;
/**
* Common superclass for Swing-based input widgets.
*
* @author Curtis Rueden
*/
public abstract class SwingInputWidget<T> extends
AbstractUIInputWidget<T, JPanel>
{
private JPanel uiComponent;
// -- WrapperPlugin methods --
@Override
public void set(final WidgetModel model) {
super.set(model);
uiComponent = new JPanel();
final MigLayout layout =
new MigLayout("fillx,ins 3 0 3 0", "[fill,grow|pref]");
uiComponent.setLayout(layout);
}
// -- UIComponent methods --
@Override
public JPanel getComponent() {
return uiComponent;
}
@Override
public Class<JPanel> getComponentType() {
return JPanel.class;
}
// -- AbstractUIInputWidget methods --
@Override
protected UserInterface ui() { | // Path: src/main/java/org/scijava/ui/swing/SwingUI.java
// public interface SwingUI {
//
// public static final String NAME = "swing";
//
// }
// Path: src/main/java/org/scijava/ui/swing/widget/SwingInputWidget.java
import javax.swing.JPanel;
import net.miginfocom.swing.MigLayout;
import org.scijava.ui.AbstractUIInputWidget;
import org.scijava.ui.UserInterface;
import org.scijava.ui.swing.SwingUI;
import org.scijava.widget.WidgetModel;
import javax.swing.JComponent;
/*
* #%L
* SciJava UI components for Java Swing.
* %%
* Copyright (C) 2010 - 2021 SciJava developers.
* %%
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
* #L%
*/
package org.scijava.ui.swing.widget;
/**
* Common superclass for Swing-based input widgets.
*
* @author Curtis Rueden
*/
public abstract class SwingInputWidget<T> extends
AbstractUIInputWidget<T, JPanel>
{
private JPanel uiComponent;
// -- WrapperPlugin methods --
@Override
public void set(final WidgetModel model) {
super.set(model);
uiComponent = new JPanel();
final MigLayout layout =
new MigLayout("fillx,ins 3 0 3 0", "[fill,grow|pref]");
uiComponent.setLayout(layout);
}
// -- UIComponent methods --
@Override
public JPanel getComponent() {
return uiComponent;
}
@Override
public Class<JPanel> getComponentType() {
return JPanel.class;
}
// -- AbstractUIInputWidget methods --
@Override
protected UserInterface ui() { | return ui(SwingUI.NAME); |
scijava/scijava-ui-swing | src/main/java/org/scijava/ui/swing/viewer/text/SwingTextDisplayViewer.java | // Path: src/main/java/org/scijava/ui/swing/SwingUI.java
// public interface SwingUI {
//
// public static final String NAME = "swing";
//
// }
| import org.scijava.plugin.Plugin;
import org.scijava.ui.UserInterface;
import org.scijava.ui.swing.SwingUI;
import org.scijava.ui.viewer.DisplayViewer;
import org.scijava.ui.viewer.DisplayWindow;
import org.scijava.ui.viewer.text.AbstractTextDisplayViewer;
import org.scijava.display.Display; | /*
* #%L
* SciJava UI components for Java Swing.
* %%
* Copyright (C) 2010 - 2021 SciJava developers.
* %%
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
* #L%
*/
package org.scijava.ui.swing.viewer.text;
/**
* A Swing text display viewer, which displays strings in a simple text panel.
*
* @author Lee Kamentsky
*/
@Plugin(type = DisplayViewer.class)
public class SwingTextDisplayViewer extends AbstractTextDisplayViewer {
@Override
public boolean isCompatible(final UserInterface ui) { | // Path: src/main/java/org/scijava/ui/swing/SwingUI.java
// public interface SwingUI {
//
// public static final String NAME = "swing";
//
// }
// Path: src/main/java/org/scijava/ui/swing/viewer/text/SwingTextDisplayViewer.java
import org.scijava.plugin.Plugin;
import org.scijava.ui.UserInterface;
import org.scijava.ui.swing.SwingUI;
import org.scijava.ui.viewer.DisplayViewer;
import org.scijava.ui.viewer.DisplayWindow;
import org.scijava.ui.viewer.text.AbstractTextDisplayViewer;
import org.scijava.display.Display;
/*
* #%L
* SciJava UI components for Java Swing.
* %%
* Copyright (C) 2010 - 2021 SciJava developers.
* %%
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
* #L%
*/
package org.scijava.ui.swing.viewer.text;
/**
* A Swing text display viewer, which displays strings in a simple text panel.
*
* @author Lee Kamentsky
*/
@Plugin(type = DisplayViewer.class)
public class SwingTextDisplayViewer extends AbstractTextDisplayViewer {
@Override
public boolean isCompatible(final UserInterface ui) { | return ui instanceof SwingUI; |
scijava/scijava-ui-swing | src/main/java/org/scijava/ui/swing/mdi/SwingMdiDialogPrompt.java | // Path: src/main/java/org/scijava/ui/swing/SwingApplicationFrame.java
// public class SwingApplicationFrame extends JFrame implements ApplicationFrame {
//
// public SwingApplicationFrame(final String title) throws HeadlessException {
// super(title);
// }
//
// // -- SwingApplicationFrame methods --
//
// public void addEventDispatcher(final AWTInputEventDispatcher dispatcher) {
// dispatcher.register(this, false, true);
// addKeyDispatcher(dispatcher, getContentPane());
// }
//
// // -- ApplicationFrame methods --
//
// @Override
// public int getLocationX() {
// return getLocation().x;
// }
//
// @Override
// public int getLocationY() {
// return getLocation().y;
// }
//
// @Override
// public void activate() {
// EventQueue.invokeLater(new Runnable() {
//
// @Override
// public void run() {
// // NB: You might think calling requestFocus() would work, but no.
// // The following solution is from: http://bit.ly/zAXzd5
// toFront();
// repaint();
// }
// });
// }
//
// // -- Helper methods --
//
// /** Recursively listens for keyboard events on the given component. */
// private void addKeyDispatcher(final AWTInputEventDispatcher dispatcher,
// final Component comp)
// {
// comp.addKeyListener(dispatcher);
// if (!(comp instanceof Container)) return;
// final Container c = (Container) comp;
// final int childCount = c.getComponentCount();
// for (int i = 0; i < childCount; i++) {
// final Component child = c.getComponent(i);
// addKeyDispatcher(dispatcher, child);
// }
// }
//
// }
| import java.util.Map;
import javax.swing.JInternalFrame;
import javax.swing.JOptionPane;
import org.scijava.ui.DialogPrompt;
import org.scijava.ui.UserInterface;
import org.scijava.ui.swing.SwingApplicationFrame;
import java.util.HashMap; | /*
* #%L
* SciJava UI components for Java Swing.
* %%
* Copyright (C) 2010 - 2021 SciJava developers.
* %%
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
* #L%
*/
package org.scijava.ui.swing.mdi;
/**
* TODO
*
* @author Grant Harris
*/
public class SwingMdiDialogPrompt implements DialogPrompt {
JInternalFrame dialog;
JOptionPane pane;
public SwingMdiDialogPrompt(final UserInterface ui, final String message,
final String title, final MessageType messageType,
final OptionType optionType)
{ | // Path: src/main/java/org/scijava/ui/swing/SwingApplicationFrame.java
// public class SwingApplicationFrame extends JFrame implements ApplicationFrame {
//
// public SwingApplicationFrame(final String title) throws HeadlessException {
// super(title);
// }
//
// // -- SwingApplicationFrame methods --
//
// public void addEventDispatcher(final AWTInputEventDispatcher dispatcher) {
// dispatcher.register(this, false, true);
// addKeyDispatcher(dispatcher, getContentPane());
// }
//
// // -- ApplicationFrame methods --
//
// @Override
// public int getLocationX() {
// return getLocation().x;
// }
//
// @Override
// public int getLocationY() {
// return getLocation().y;
// }
//
// @Override
// public void activate() {
// EventQueue.invokeLater(new Runnable() {
//
// @Override
// public void run() {
// // NB: You might think calling requestFocus() would work, but no.
// // The following solution is from: http://bit.ly/zAXzd5
// toFront();
// repaint();
// }
// });
// }
//
// // -- Helper methods --
//
// /** Recursively listens for keyboard events on the given component. */
// private void addKeyDispatcher(final AWTInputEventDispatcher dispatcher,
// final Component comp)
// {
// comp.addKeyListener(dispatcher);
// if (!(comp instanceof Container)) return;
// final Container c = (Container) comp;
// final int childCount = c.getComponentCount();
// for (int i = 0; i < childCount; i++) {
// final Component child = c.getComponent(i);
// addKeyDispatcher(dispatcher, child);
// }
// }
//
// }
// Path: src/main/java/org/scijava/ui/swing/mdi/SwingMdiDialogPrompt.java
import java.util.Map;
import javax.swing.JInternalFrame;
import javax.swing.JOptionPane;
import org.scijava.ui.DialogPrompt;
import org.scijava.ui.UserInterface;
import org.scijava.ui.swing.SwingApplicationFrame;
import java.util.HashMap;
/*
* #%L
* SciJava UI components for Java Swing.
* %%
* Copyright (C) 2010 - 2021 SciJava developers.
* %%
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
* #L%
*/
package org.scijava.ui.swing.mdi;
/**
* TODO
*
* @author Grant Harris
*/
public class SwingMdiDialogPrompt implements DialogPrompt {
JInternalFrame dialog;
JOptionPane pane;
public SwingMdiDialogPrompt(final UserInterface ui, final String message,
final String title, final MessageType messageType,
final OptionType optionType)
{ | final SwingApplicationFrame appFrame = |
airbnb/RxGroups | rxgroups-annotation-test/src/test/resources/AutoTaggableObserver_Pass_All.java | // Path: rxgroups-annotation-test/src/test/java/com/airbnb/rxgroups/AutoTaggableObserverImpl.java
// public class AutoTaggableObserverImpl<T> implements AutoTaggableObserver<T> {
// @Override public void setTag(String tag) {
//
// }
//
// @Override public String getTag() {
// return null;
// }
//
// @Override public void onComplete() {
//
// }
//
// @Override public void onError(Throwable e) {
//
// }
//
// @Override public void onSubscribe(@NonNull Disposable d) {
//
// }
//
// @Override public void onNext(T t) {
//
// }
// }
| import com.airbnb.rxgroups.AutoResubscribe;
import com.airbnb.rxgroups.AutoTag;
import com.airbnb.rxgroups.AutoTaggableObserverImpl; | package test;
public class AutoTaggableObserver_Pass_All {
@AutoResubscribe | // Path: rxgroups-annotation-test/src/test/java/com/airbnb/rxgroups/AutoTaggableObserverImpl.java
// public class AutoTaggableObserverImpl<T> implements AutoTaggableObserver<T> {
// @Override public void setTag(String tag) {
//
// }
//
// @Override public String getTag() {
// return null;
// }
//
// @Override public void onComplete() {
//
// }
//
// @Override public void onError(Throwable e) {
//
// }
//
// @Override public void onSubscribe(@NonNull Disposable d) {
//
// }
//
// @Override public void onNext(T t) {
//
// }
// }
// Path: rxgroups-annotation-test/src/test/resources/AutoTaggableObserver_Pass_All.java
import com.airbnb.rxgroups.AutoResubscribe;
import com.airbnb.rxgroups.AutoTag;
import com.airbnb.rxgroups.AutoTaggableObserverImpl;
package test;
public class AutoTaggableObserver_Pass_All {
@AutoResubscribe | public AutoTaggableObserverImpl<Object> resubscribeObserver = new AutoTaggableObserverImpl<Object>(); |
airbnb/RxGroups | rxgroups/src/main/java/com/airbnb/rxgroups/ResubscribeHelper.java | // Path: rxgroups/src/main/java/com/airbnb/rxgroups/processor/ProcessorHelper.java
// public class ProcessorHelper {
//
// public static final String GENERATED_CLASS_NAME_SUFFIX = "_ObservableResubscriber";
//
// }
| import com.airbnb.rxgroups.processor.ProcessorHelper;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.LinkedHashMap;
import java.util.Map;
import javax.annotation.Nullable; | } catch (IllegalAccessException e) {
throw new RuntimeException("Unable to invoke " + constructor, e);
} catch (InstantiationException e) {
throw new RuntimeException("Unable to invoke " + constructor, e);
} catch (InvocationTargetException e) {
Throwable cause = e.getCause();
if (cause instanceof RuntimeException) {
throw (RuntimeException) cause;
}
if (cause instanceof Error) {
throw (Error) cause;
}
throw new RuntimeException("Unable to create resubscribeAll instance.", cause);
}
}
@Nullable
private static Constructor<?> findConstructorForClass(Class<?> cls) {
Constructor<?> bindingCtor = BINDINGS.get(cls);
if (bindingCtor != null || BINDINGS.containsKey(cls)) {
return bindingCtor;
}
String clsName = cls.getName();
if (clsName.startsWith("android.") || clsName.startsWith("java.")) {
BINDINGS.put(cls, bindingCtor);
return null;
}
try {
Class<?> bindingClass = Class.forName(clsName | // Path: rxgroups/src/main/java/com/airbnb/rxgroups/processor/ProcessorHelper.java
// public class ProcessorHelper {
//
// public static final String GENERATED_CLASS_NAME_SUFFIX = "_ObservableResubscriber";
//
// }
// Path: rxgroups/src/main/java/com/airbnb/rxgroups/ResubscribeHelper.java
import com.airbnb.rxgroups.processor.ProcessorHelper;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.LinkedHashMap;
import java.util.Map;
import javax.annotation.Nullable;
} catch (IllegalAccessException e) {
throw new RuntimeException("Unable to invoke " + constructor, e);
} catch (InstantiationException e) {
throw new RuntimeException("Unable to invoke " + constructor, e);
} catch (InvocationTargetException e) {
Throwable cause = e.getCause();
if (cause instanceof RuntimeException) {
throw (RuntimeException) cause;
}
if (cause instanceof Error) {
throw (Error) cause;
}
throw new RuntimeException("Unable to create resubscribeAll instance.", cause);
}
}
@Nullable
private static Constructor<?> findConstructorForClass(Class<?> cls) {
Constructor<?> bindingCtor = BINDINGS.get(cls);
if (bindingCtor != null || BINDINGS.containsKey(cls)) {
return bindingCtor;
}
String clsName = cls.getName();
if (clsName.startsWith("android.") || clsName.startsWith("java.")) {
BINDINGS.put(cls, bindingCtor);
return null;
}
try {
Class<?> bindingClass = Class.forName(clsName | + ProcessorHelper.GENERATED_CLASS_NAME_SUFFIX); |
airbnb/RxGroups | rxgroups-annotation-test/src/test/resources/AutoResubscribingObserver_Fail_Private_AutoTag.java | // Path: rxgroups/src/main/java/com/airbnb/rxgroups/AutoResubscribingObserver.java
// public abstract class AutoResubscribingObserver<T> implements TaggedObserver<T> {
//
// private String tag;
//
// public final String getTag() {
// return tag;
// }
//
// void setTag(String tag) {
// this.tag = tag;
// }
//
// @Override
// public void onComplete() {
//
// }
//
// @Override
// public void onError(Throwable e) {
//
// }
//
// @Override
// public void onNext(T t) {
//
// }
//
// @Override public void onSubscribe(@NonNull Disposable d) {
//
// }
// }
| import com.airbnb.rxgroups.AutoTag;
import com.airbnb.rxgroups.AutoResubscribingObserver; | package test;
public class AutoResubscribingObserver_Fail_Private_AutoTag {
@AutoTag | // Path: rxgroups/src/main/java/com/airbnb/rxgroups/AutoResubscribingObserver.java
// public abstract class AutoResubscribingObserver<T> implements TaggedObserver<T> {
//
// private String tag;
//
// public final String getTag() {
// return tag;
// }
//
// void setTag(String tag) {
// this.tag = tag;
// }
//
// @Override
// public void onComplete() {
//
// }
//
// @Override
// public void onError(Throwable e) {
//
// }
//
// @Override
// public void onNext(T t) {
//
// }
//
// @Override public void onSubscribe(@NonNull Disposable d) {
//
// }
// }
// Path: rxgroups-annotation-test/src/test/resources/AutoResubscribingObserver_Fail_Private_AutoTag.java
import com.airbnb.rxgroups.AutoTag;
import com.airbnb.rxgroups.AutoResubscribingObserver;
package test;
public class AutoResubscribingObserver_Fail_Private_AutoTag {
@AutoTag | private AutoResubscribingObserver<Object> observer = new AutoResubscribingObserver<Object>() { }; |
airbnb/RxGroups | rxgroups-annotation-test/src/test/resources/AutoResubscribingObserver_Fail_Private.java | // Path: rxgroups/src/main/java/com/airbnb/rxgroups/AutoResubscribingObserver.java
// public abstract class AutoResubscribingObserver<T> implements TaggedObserver<T> {
//
// private String tag;
//
// public final String getTag() {
// return tag;
// }
//
// void setTag(String tag) {
// this.tag = tag;
// }
//
// @Override
// public void onComplete() {
//
// }
//
// @Override
// public void onError(Throwable e) {
//
// }
//
// @Override
// public void onNext(T t) {
//
// }
//
// @Override public void onSubscribe(@NonNull Disposable d) {
//
// }
// }
| import com.airbnb.rxgroups.AutoResubscribe;
import com.airbnb.rxgroups.AutoResubscribingObserver; | package test;
public class AutoResubscribingObserver_Fail_Private {
@AutoResubscribe | // Path: rxgroups/src/main/java/com/airbnb/rxgroups/AutoResubscribingObserver.java
// public abstract class AutoResubscribingObserver<T> implements TaggedObserver<T> {
//
// private String tag;
//
// public final String getTag() {
// return tag;
// }
//
// void setTag(String tag) {
// this.tag = tag;
// }
//
// @Override
// public void onComplete() {
//
// }
//
// @Override
// public void onError(Throwable e) {
//
// }
//
// @Override
// public void onNext(T t) {
//
// }
//
// @Override public void onSubscribe(@NonNull Disposable d) {
//
// }
// }
// Path: rxgroups-annotation-test/src/test/resources/AutoResubscribingObserver_Fail_Private.java
import com.airbnb.rxgroups.AutoResubscribe;
import com.airbnb.rxgroups.AutoResubscribingObserver;
package test;
public class AutoResubscribingObserver_Fail_Private {
@AutoResubscribe | private AutoResubscribingObserver<Object> observer = new AutoResubscribingObserver<Object>() { }; |
airbnb/RxGroups | rxgroups-annotation-test/src/test/resources/TaggedObserver_Fail_AutoTag.java | // Path: rxgroups/src/main/java/com/airbnb/rxgroups/TaggedObserver.java
// public interface TaggedObserver<T> extends Observer<T> {
//
// /**
// * @return A string which uniquely identifies this Observer. In order to use
// * {@link ObservableGroup#resubscribe(TaggedObserver, String)} the tag must be
// * stable across lifecycles of the observer.
// */
// String getTag();
//
// }
| import com.airbnb.rxgroups.AutoTag;
import com.airbnb.rxgroups.TaggedObserver; | package test;
public class TaggedObserver_Fail_AutoTag {
@AutoTag | // Path: rxgroups/src/main/java/com/airbnb/rxgroups/TaggedObserver.java
// public interface TaggedObserver<T> extends Observer<T> {
//
// /**
// * @return A string which uniquely identifies this Observer. In order to use
// * {@link ObservableGroup#resubscribe(TaggedObserver, String)} the tag must be
// * stable across lifecycles of the observer.
// */
// String getTag();
//
// }
// Path: rxgroups-annotation-test/src/test/resources/TaggedObserver_Fail_AutoTag.java
import com.airbnb.rxgroups.AutoTag;
import com.airbnb.rxgroups.TaggedObserver;
package test;
public class TaggedObserver_Fail_AutoTag {
@AutoTag | public TaggedObserver<Object> taggedObserver = new TaggedObserver<Object>() { |
airbnb/RxGroups | rxgroups-processor/src/main/java/com/airbnb/rxgroups/processor/ProcessorUtils.java | // Path: rxgroups/src/main/java/com/airbnb/rxgroups/AutoResubscribingObserver.java
// public abstract class AutoResubscribingObserver<T> implements TaggedObserver<T> {
//
// private String tag;
//
// public final String getTag() {
// return tag;
// }
//
// void setTag(String tag) {
// this.tag = tag;
// }
//
// @Override
// public void onComplete() {
//
// }
//
// @Override
// public void onError(Throwable e) {
//
// }
//
// @Override
// public void onNext(T t) {
//
// }
//
// @Override public void onSubscribe(@NonNull Disposable d) {
//
// }
// }
//
// Path: rxgroups/src/main/java/com/airbnb/rxgroups/AutoTaggableObserver.java
// public interface AutoTaggableObserver<T> extends TaggedObserver<T> {
// void setTag(String tag);
// }
//
// Path: rxgroups/src/main/java/com/airbnb/rxgroups/TaggedObserver.java
// public interface TaggedObserver<T> extends Observer<T> {
//
// /**
// * @return A string which uniquely identifies this Observer. In order to use
// * {@link ObservableGroup#resubscribe(TaggedObserver, String)} the tag must be
// * stable across lifecycles of the observer.
// */
// String getTag();
//
// }
| import com.airbnb.rxgroups.AutoResubscribingObserver;
import com.airbnb.rxgroups.AutoTaggableObserver;
import com.airbnb.rxgroups.TaggedObserver;
import javax.lang.model.element.Element;
import javax.lang.model.type.TypeMirror;
import javax.lang.model.util.Elements;
import javax.lang.model.util.Types; | package com.airbnb.rxgroups.processor;
class ProcessorUtils {
static boolean isResubscribingObserver(Element observerFieldElement, Types typeUtil, Elements
elementUtil) {
final TypeMirror autoResubscribingTypeMirror = elementUtil.getTypeElement( | // Path: rxgroups/src/main/java/com/airbnb/rxgroups/AutoResubscribingObserver.java
// public abstract class AutoResubscribingObserver<T> implements TaggedObserver<T> {
//
// private String tag;
//
// public final String getTag() {
// return tag;
// }
//
// void setTag(String tag) {
// this.tag = tag;
// }
//
// @Override
// public void onComplete() {
//
// }
//
// @Override
// public void onError(Throwable e) {
//
// }
//
// @Override
// public void onNext(T t) {
//
// }
//
// @Override public void onSubscribe(@NonNull Disposable d) {
//
// }
// }
//
// Path: rxgroups/src/main/java/com/airbnb/rxgroups/AutoTaggableObserver.java
// public interface AutoTaggableObserver<T> extends TaggedObserver<T> {
// void setTag(String tag);
// }
//
// Path: rxgroups/src/main/java/com/airbnb/rxgroups/TaggedObserver.java
// public interface TaggedObserver<T> extends Observer<T> {
//
// /**
// * @return A string which uniquely identifies this Observer. In order to use
// * {@link ObservableGroup#resubscribe(TaggedObserver, String)} the tag must be
// * stable across lifecycles of the observer.
// */
// String getTag();
//
// }
// Path: rxgroups-processor/src/main/java/com/airbnb/rxgroups/processor/ProcessorUtils.java
import com.airbnb.rxgroups.AutoResubscribingObserver;
import com.airbnb.rxgroups.AutoTaggableObserver;
import com.airbnb.rxgroups.TaggedObserver;
import javax.lang.model.element.Element;
import javax.lang.model.type.TypeMirror;
import javax.lang.model.util.Elements;
import javax.lang.model.util.Types;
package com.airbnb.rxgroups.processor;
class ProcessorUtils {
static boolean isResubscribingObserver(Element observerFieldElement, Types typeUtil, Elements
elementUtil) {
final TypeMirror autoResubscribingTypeMirror = elementUtil.getTypeElement( | AutoResubscribingObserver.class.getCanonicalName()).asType(); |
airbnb/RxGroups | rxgroups-processor/src/main/java/com/airbnb/rxgroups/processor/ProcessorUtils.java | // Path: rxgroups/src/main/java/com/airbnb/rxgroups/AutoResubscribingObserver.java
// public abstract class AutoResubscribingObserver<T> implements TaggedObserver<T> {
//
// private String tag;
//
// public final String getTag() {
// return tag;
// }
//
// void setTag(String tag) {
// this.tag = tag;
// }
//
// @Override
// public void onComplete() {
//
// }
//
// @Override
// public void onError(Throwable e) {
//
// }
//
// @Override
// public void onNext(T t) {
//
// }
//
// @Override public void onSubscribe(@NonNull Disposable d) {
//
// }
// }
//
// Path: rxgroups/src/main/java/com/airbnb/rxgroups/AutoTaggableObserver.java
// public interface AutoTaggableObserver<T> extends TaggedObserver<T> {
// void setTag(String tag);
// }
//
// Path: rxgroups/src/main/java/com/airbnb/rxgroups/TaggedObserver.java
// public interface TaggedObserver<T> extends Observer<T> {
//
// /**
// * @return A string which uniquely identifies this Observer. In order to use
// * {@link ObservableGroup#resubscribe(TaggedObserver, String)} the tag must be
// * stable across lifecycles of the observer.
// */
// String getTag();
//
// }
| import com.airbnb.rxgroups.AutoResubscribingObserver;
import com.airbnb.rxgroups.AutoTaggableObserver;
import com.airbnb.rxgroups.TaggedObserver;
import javax.lang.model.element.Element;
import javax.lang.model.type.TypeMirror;
import javax.lang.model.util.Elements;
import javax.lang.model.util.Types; | package com.airbnb.rxgroups.processor;
class ProcessorUtils {
static boolean isResubscribingObserver(Element observerFieldElement, Types typeUtil, Elements
elementUtil) {
final TypeMirror autoResubscribingTypeMirror = elementUtil.getTypeElement(
AutoResubscribingObserver.class.getCanonicalName()).asType();
return typeUtil.isAssignable(observerFieldElement.asType(), typeUtil.erasure(
autoResubscribingTypeMirror));
}
static boolean isTaggedObserver(Element observerFieldElement, Types typeUtil, Elements
elementUtil) {
final TypeMirror autoResubscribingTypeMirror = elementUtil.getTypeElement( | // Path: rxgroups/src/main/java/com/airbnb/rxgroups/AutoResubscribingObserver.java
// public abstract class AutoResubscribingObserver<T> implements TaggedObserver<T> {
//
// private String tag;
//
// public final String getTag() {
// return tag;
// }
//
// void setTag(String tag) {
// this.tag = tag;
// }
//
// @Override
// public void onComplete() {
//
// }
//
// @Override
// public void onError(Throwable e) {
//
// }
//
// @Override
// public void onNext(T t) {
//
// }
//
// @Override public void onSubscribe(@NonNull Disposable d) {
//
// }
// }
//
// Path: rxgroups/src/main/java/com/airbnb/rxgroups/AutoTaggableObserver.java
// public interface AutoTaggableObserver<T> extends TaggedObserver<T> {
// void setTag(String tag);
// }
//
// Path: rxgroups/src/main/java/com/airbnb/rxgroups/TaggedObserver.java
// public interface TaggedObserver<T> extends Observer<T> {
//
// /**
// * @return A string which uniquely identifies this Observer. In order to use
// * {@link ObservableGroup#resubscribe(TaggedObserver, String)} the tag must be
// * stable across lifecycles of the observer.
// */
// String getTag();
//
// }
// Path: rxgroups-processor/src/main/java/com/airbnb/rxgroups/processor/ProcessorUtils.java
import com.airbnb.rxgroups.AutoResubscribingObserver;
import com.airbnb.rxgroups.AutoTaggableObserver;
import com.airbnb.rxgroups.TaggedObserver;
import javax.lang.model.element.Element;
import javax.lang.model.type.TypeMirror;
import javax.lang.model.util.Elements;
import javax.lang.model.util.Types;
package com.airbnb.rxgroups.processor;
class ProcessorUtils {
static boolean isResubscribingObserver(Element observerFieldElement, Types typeUtil, Elements
elementUtil) {
final TypeMirror autoResubscribingTypeMirror = elementUtil.getTypeElement(
AutoResubscribingObserver.class.getCanonicalName()).asType();
return typeUtil.isAssignable(observerFieldElement.asType(), typeUtil.erasure(
autoResubscribingTypeMirror));
}
static boolean isTaggedObserver(Element observerFieldElement, Types typeUtil, Elements
elementUtil) {
final TypeMirror autoResubscribingTypeMirror = elementUtil.getTypeElement( | TaggedObserver.class.getCanonicalName()).asType(); |
airbnb/RxGroups | rxgroups-processor/src/main/java/com/airbnb/rxgroups/processor/ProcessorUtils.java | // Path: rxgroups/src/main/java/com/airbnb/rxgroups/AutoResubscribingObserver.java
// public abstract class AutoResubscribingObserver<T> implements TaggedObserver<T> {
//
// private String tag;
//
// public final String getTag() {
// return tag;
// }
//
// void setTag(String tag) {
// this.tag = tag;
// }
//
// @Override
// public void onComplete() {
//
// }
//
// @Override
// public void onError(Throwable e) {
//
// }
//
// @Override
// public void onNext(T t) {
//
// }
//
// @Override public void onSubscribe(@NonNull Disposable d) {
//
// }
// }
//
// Path: rxgroups/src/main/java/com/airbnb/rxgroups/AutoTaggableObserver.java
// public interface AutoTaggableObserver<T> extends TaggedObserver<T> {
// void setTag(String tag);
// }
//
// Path: rxgroups/src/main/java/com/airbnb/rxgroups/TaggedObserver.java
// public interface TaggedObserver<T> extends Observer<T> {
//
// /**
// * @return A string which uniquely identifies this Observer. In order to use
// * {@link ObservableGroup#resubscribe(TaggedObserver, String)} the tag must be
// * stable across lifecycles of the observer.
// */
// String getTag();
//
// }
| import com.airbnb.rxgroups.AutoResubscribingObserver;
import com.airbnb.rxgroups.AutoTaggableObserver;
import com.airbnb.rxgroups.TaggedObserver;
import javax.lang.model.element.Element;
import javax.lang.model.type.TypeMirror;
import javax.lang.model.util.Elements;
import javax.lang.model.util.Types; | package com.airbnb.rxgroups.processor;
class ProcessorUtils {
static boolean isResubscribingObserver(Element observerFieldElement, Types typeUtil, Elements
elementUtil) {
final TypeMirror autoResubscribingTypeMirror = elementUtil.getTypeElement(
AutoResubscribingObserver.class.getCanonicalName()).asType();
return typeUtil.isAssignable(observerFieldElement.asType(), typeUtil.erasure(
autoResubscribingTypeMirror));
}
static boolean isTaggedObserver(Element observerFieldElement, Types typeUtil, Elements
elementUtil) {
final TypeMirror autoResubscribingTypeMirror = elementUtil.getTypeElement(
TaggedObserver.class.getCanonicalName()).asType();
return typeUtil.isAssignable(observerFieldElement.asType(), typeUtil.erasure(
autoResubscribingTypeMirror));
}
static boolean isAutoTaggable(Element observerFieldElement, Types typeUtil, Elements
elementUtil) {
final TypeMirror autoResubscribingTypeMirror = elementUtil.getTypeElement( | // Path: rxgroups/src/main/java/com/airbnb/rxgroups/AutoResubscribingObserver.java
// public abstract class AutoResubscribingObserver<T> implements TaggedObserver<T> {
//
// private String tag;
//
// public final String getTag() {
// return tag;
// }
//
// void setTag(String tag) {
// this.tag = tag;
// }
//
// @Override
// public void onComplete() {
//
// }
//
// @Override
// public void onError(Throwable e) {
//
// }
//
// @Override
// public void onNext(T t) {
//
// }
//
// @Override public void onSubscribe(@NonNull Disposable d) {
//
// }
// }
//
// Path: rxgroups/src/main/java/com/airbnb/rxgroups/AutoTaggableObserver.java
// public interface AutoTaggableObserver<T> extends TaggedObserver<T> {
// void setTag(String tag);
// }
//
// Path: rxgroups/src/main/java/com/airbnb/rxgroups/TaggedObserver.java
// public interface TaggedObserver<T> extends Observer<T> {
//
// /**
// * @return A string which uniquely identifies this Observer. In order to use
// * {@link ObservableGroup#resubscribe(TaggedObserver, String)} the tag must be
// * stable across lifecycles of the observer.
// */
// String getTag();
//
// }
// Path: rxgroups-processor/src/main/java/com/airbnb/rxgroups/processor/ProcessorUtils.java
import com.airbnb.rxgroups.AutoResubscribingObserver;
import com.airbnb.rxgroups.AutoTaggableObserver;
import com.airbnb.rxgroups.TaggedObserver;
import javax.lang.model.element.Element;
import javax.lang.model.type.TypeMirror;
import javax.lang.model.util.Elements;
import javax.lang.model.util.Types;
package com.airbnb.rxgroups.processor;
class ProcessorUtils {
static boolean isResubscribingObserver(Element observerFieldElement, Types typeUtil, Elements
elementUtil) {
final TypeMirror autoResubscribingTypeMirror = elementUtil.getTypeElement(
AutoResubscribingObserver.class.getCanonicalName()).asType();
return typeUtil.isAssignable(observerFieldElement.asType(), typeUtil.erasure(
autoResubscribingTypeMirror));
}
static boolean isTaggedObserver(Element observerFieldElement, Types typeUtil, Elements
elementUtil) {
final TypeMirror autoResubscribingTypeMirror = elementUtil.getTypeElement(
TaggedObserver.class.getCanonicalName()).asType();
return typeUtil.isAssignable(observerFieldElement.asType(), typeUtil.erasure(
autoResubscribingTypeMirror));
}
static boolean isAutoTaggable(Element observerFieldElement, Types typeUtil, Elements
elementUtil) {
final TypeMirror autoResubscribingTypeMirror = elementUtil.getTypeElement( | AutoTaggableObserver.class.getCanonicalName()).asType(); |
airbnb/RxGroups | rxgroups-annotation-test/src/test/resources/AutoResubscribingObserver_Fail_NonStatic.java | // Path: rxgroups/src/main/java/com/airbnb/rxgroups/AutoResubscribingObserver.java
// public abstract class AutoResubscribingObserver<T> implements TaggedObserver<T> {
//
// private String tag;
//
// public final String getTag() {
// return tag;
// }
//
// void setTag(String tag) {
// this.tag = tag;
// }
//
// @Override
// public void onComplete() {
//
// }
//
// @Override
// public void onError(Throwable e) {
//
// }
//
// @Override
// public void onNext(T t) {
//
// }
//
// @Override public void onSubscribe(@NonNull Disposable d) {
//
// }
// }
| import com.airbnb.rxgroups.AutoResubscribe;
import com.airbnb.rxgroups.AutoResubscribingObserver; | package test;
public class AutoResubscribingObserver_Fail_NonStatic {
class Inner {
@AutoResubscribe | // Path: rxgroups/src/main/java/com/airbnb/rxgroups/AutoResubscribingObserver.java
// public abstract class AutoResubscribingObserver<T> implements TaggedObserver<T> {
//
// private String tag;
//
// public final String getTag() {
// return tag;
// }
//
// void setTag(String tag) {
// this.tag = tag;
// }
//
// @Override
// public void onComplete() {
//
// }
//
// @Override
// public void onError(Throwable e) {
//
// }
//
// @Override
// public void onNext(T t) {
//
// }
//
// @Override public void onSubscribe(@NonNull Disposable d) {
//
// }
// }
// Path: rxgroups-annotation-test/src/test/resources/AutoResubscribingObserver_Fail_NonStatic.java
import com.airbnb.rxgroups.AutoResubscribe;
import com.airbnb.rxgroups.AutoResubscribingObserver;
package test;
public class AutoResubscribingObserver_Fail_NonStatic {
class Inner {
@AutoResubscribe | private AutoResubscribingObserver<Object> observer = new AutoResubscribingObserver<Object>() { }; |
airbnb/RxGroups | rxgroups-annotation-test/src/test/resources/AutoTaggableObserver_Pass_All_CustomTag.java | // Path: rxgroups-annotation-test/src/test/java/com/airbnb/rxgroups/AutoTaggableObserverImpl.java
// public class AutoTaggableObserverImpl<T> implements AutoTaggableObserver<T> {
// @Override public void setTag(String tag) {
//
// }
//
// @Override public String getTag() {
// return null;
// }
//
// @Override public void onComplete() {
//
// }
//
// @Override public void onError(Throwable e) {
//
// }
//
// @Override public void onSubscribe(@NonNull Disposable d) {
//
// }
//
// @Override public void onNext(T t) {
//
// }
// }
| import com.airbnb.rxgroups.AutoResubscribe;
import com.airbnb.rxgroups.AutoTag;
import com.airbnb.rxgroups.AutoTaggableObserverImpl; | package test;
public class AutoTaggableObserver_Pass_All_CustomTag {
@AutoResubscribe(customTag = "tag1") | // Path: rxgroups-annotation-test/src/test/java/com/airbnb/rxgroups/AutoTaggableObserverImpl.java
// public class AutoTaggableObserverImpl<T> implements AutoTaggableObserver<T> {
// @Override public void setTag(String tag) {
//
// }
//
// @Override public String getTag() {
// return null;
// }
//
// @Override public void onComplete() {
//
// }
//
// @Override public void onError(Throwable e) {
//
// }
//
// @Override public void onSubscribe(@NonNull Disposable d) {
//
// }
//
// @Override public void onNext(T t) {
//
// }
// }
// Path: rxgroups-annotation-test/src/test/resources/AutoTaggableObserver_Pass_All_CustomTag.java
import com.airbnb.rxgroups.AutoResubscribe;
import com.airbnb.rxgroups.AutoTag;
import com.airbnb.rxgroups.AutoTaggableObserverImpl;
package test;
public class AutoTaggableObserver_Pass_All_CustomTag {
@AutoResubscribe(customTag = "tag1") | public AutoTaggableObserverImpl<Object> resubscribeObserver = new AutoTaggableObserverImpl<Object>(); |
airbnb/RxGroups | rxgroups-annotation-test/src/test/resources/AutoResubscribingObserver_Pass_All.java | // Path: rxgroups/src/main/java/com/airbnb/rxgroups/AutoResubscribingObserver.java
// public abstract class AutoResubscribingObserver<T> implements TaggedObserver<T> {
//
// private String tag;
//
// public final String getTag() {
// return tag;
// }
//
// void setTag(String tag) {
// this.tag = tag;
// }
//
// @Override
// public void onComplete() {
//
// }
//
// @Override
// public void onError(Throwable e) {
//
// }
//
// @Override
// public void onNext(T t) {
//
// }
//
// @Override public void onSubscribe(@NonNull Disposable d) {
//
// }
// }
| import com.airbnb.rxgroups.AutoResubscribe;
import com.airbnb.rxgroups.AutoTag;
import com.airbnb.rxgroups.AutoResubscribingObserver; | package test;
public class AutoResubscribingObserver_Pass_All {
@AutoResubscribe | // Path: rxgroups/src/main/java/com/airbnb/rxgroups/AutoResubscribingObserver.java
// public abstract class AutoResubscribingObserver<T> implements TaggedObserver<T> {
//
// private String tag;
//
// public final String getTag() {
// return tag;
// }
//
// void setTag(String tag) {
// this.tag = tag;
// }
//
// @Override
// public void onComplete() {
//
// }
//
// @Override
// public void onError(Throwable e) {
//
// }
//
// @Override
// public void onNext(T t) {
//
// }
//
// @Override public void onSubscribe(@NonNull Disposable d) {
//
// }
// }
// Path: rxgroups-annotation-test/src/test/resources/AutoResubscribingObserver_Pass_All.java
import com.airbnb.rxgroups.AutoResubscribe;
import com.airbnb.rxgroups.AutoTag;
import com.airbnb.rxgroups.AutoResubscribingObserver;
package test;
public class AutoResubscribingObserver_Pass_All {
@AutoResubscribe | AutoResubscribingObserver<Object> observer = new AutoResubscribingObserver<Object>() { }; |
airbnb/RxGroups | rxgroups-annotation-test/src/test/resources/TaggedObserver_Pass_AutoResubscribe.java | // Path: rxgroups/src/main/java/com/airbnb/rxgroups/TaggedObserver.java
// public interface TaggedObserver<T> extends Observer<T> {
//
// /**
// * @return A string which uniquely identifies this Observer. In order to use
// * {@link ObservableGroup#resubscribe(TaggedObserver, String)} the tag must be
// * stable across lifecycles of the observer.
// */
// String getTag();
//
// }
| import com.airbnb.rxgroups.AutoResubscribe;
import com.airbnb.rxgroups.TaggedObserver;
import io.reactivex.disposables.Disposable; | package test;
public class TaggedObserver_Pass_AutoResubscribe {
@AutoResubscribe | // Path: rxgroups/src/main/java/com/airbnb/rxgroups/TaggedObserver.java
// public interface TaggedObserver<T> extends Observer<T> {
//
// /**
// * @return A string which uniquely identifies this Observer. In order to use
// * {@link ObservableGroup#resubscribe(TaggedObserver, String)} the tag must be
// * stable across lifecycles of the observer.
// */
// String getTag();
//
// }
// Path: rxgroups-annotation-test/src/test/resources/TaggedObserver_Pass_AutoResubscribe.java
import com.airbnb.rxgroups.AutoResubscribe;
import com.airbnb.rxgroups.TaggedObserver;
import io.reactivex.disposables.Disposable;
package test;
public class TaggedObserver_Pass_AutoResubscribe {
@AutoResubscribe | public TaggedObserver<Object> taggedObserver = new TaggedObserver<Object>() { |
Pkmmte/TechDissected | app/src/main/java/com/pkmmte/techdissected/adapter/AuthorAdapter.java | // Path: app/src/main/java/com/pkmmte/techdissected/model/Author.java
// public class Author {
// private Uri url;
// private Uri avatar;
// private String username;
// private String name;
// private String description;
//
// public Author() {
// this.url = null;
// this.avatar = null;
// this.username = null;
// this.name = null;
// this.description = null;
// }
//
// public Author(Uri url, Uri avatar, String username, String name, String description) {
// this.url = url;
// this.avatar = avatar;
// this.username = username;
// this.name = name;
// this.description = description;
// }
//
// public Uri getUrl() {
// return url;
// }
//
// public void setUrl(Uri url) {
// this.url = url;
// }
//
// public Uri getAvatar() {
// return avatar;
// }
//
// public void setAvatar(Uri avatar) {
// this.avatar = avatar;
// }
//
// public String getUsername() {
// return username;
// }
//
// public void setUsername(String username) {
// this.username = username;
// }
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public String getDescription() {
// return description;
// }
//
// public void setDescription(String description) {
// this.description = description;
// }
//
// public static class ListBuilder {
// private final List<Author> authorList;
//
// public ListBuilder() {
// authorList = new ArrayList<Author>();
// }
//
// public ListBuilder add(Uri url, Uri avatar, String username, String name, String description) {
// authorList.add(new Author(url, avatar, username, name, description));
// return this;
// }
//
// public List<Author> build() {
// return authorList;
// }
// }
// }
| import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import com.pkmmte.techdissected.R;
import com.pkmmte.techdissected.model.Author;
import com.pkmmte.view.CircularImageView;
import com.squareup.picasso.Picasso;
import java.util.ArrayList;
import java.util.List; | package com.pkmmte.techdissected.adapter;
public class AuthorAdapter extends BaseAdapter{
private Context mContext; | // Path: app/src/main/java/com/pkmmte/techdissected/model/Author.java
// public class Author {
// private Uri url;
// private Uri avatar;
// private String username;
// private String name;
// private String description;
//
// public Author() {
// this.url = null;
// this.avatar = null;
// this.username = null;
// this.name = null;
// this.description = null;
// }
//
// public Author(Uri url, Uri avatar, String username, String name, String description) {
// this.url = url;
// this.avatar = avatar;
// this.username = username;
// this.name = name;
// this.description = description;
// }
//
// public Uri getUrl() {
// return url;
// }
//
// public void setUrl(Uri url) {
// this.url = url;
// }
//
// public Uri getAvatar() {
// return avatar;
// }
//
// public void setAvatar(Uri avatar) {
// this.avatar = avatar;
// }
//
// public String getUsername() {
// return username;
// }
//
// public void setUsername(String username) {
// this.username = username;
// }
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public String getDescription() {
// return description;
// }
//
// public void setDescription(String description) {
// this.description = description;
// }
//
// public static class ListBuilder {
// private final List<Author> authorList;
//
// public ListBuilder() {
// authorList = new ArrayList<Author>();
// }
//
// public ListBuilder add(Uri url, Uri avatar, String username, String name, String description) {
// authorList.add(new Author(url, avatar, username, name, description));
// return this;
// }
//
// public List<Author> build() {
// return authorList;
// }
// }
// }
// Path: app/src/main/java/com/pkmmte/techdissected/adapter/AuthorAdapter.java
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import com.pkmmte.techdissected.R;
import com.pkmmte.techdissected.model.Author;
import com.pkmmte.view.CircularImageView;
import com.squareup.picasso.Picasso;
import java.util.ArrayList;
import java.util.List;
package com.pkmmte.techdissected.adapter;
public class AuthorAdapter extends BaseAdapter{
private Context mContext; | private List<Author> authorList; |
Pkmmte/TechDissected | app/src/main/java/com/pkmmte/techdissected/adapter/SettingsAdapter.java | // Path: app/src/main/java/com/pkmmte/techdissected/model/SettingsItem.java
// public class SettingsItem {
// private int ID;
// private int Type;
// private String Title;
// private String Description;
// private boolean Selected;
//
// public SettingsItem() {
// this.ID = -1;
// this.Type = -1;
// this.Title = "null";
// this.Description = "null";
// this.Selected = false;
// }
//
// public SettingsItem(int Type) {
// this.ID = -1;
// this.Type = Type;
// this.Title = "null";
// this.Description = "null";
// this.Selected = false;
// }
//
// public SettingsItem(int Type, String Title) {
// this.ID = -1;
// this.Type = Type;
// this.Title = Title;
// this.Description = "null";
// this.Selected = false;
// }
//
// public SettingsItem(int Type, String Title, String Description) {
// this.ID = -1;
// this.Type = Type;
// this.Title = Title;
// this.Description = Description;
// this.Selected = false;
// }
//
// public SettingsItem(int Type, String Title, String Description, boolean Selected) {
// this.ID = -1;
// this.Type = Type;
// this.Title = Title;
// this.Description = Description;
// this.Selected = Selected;
// }
//
// public SettingsItem(Builder builder) {
// this.ID = builder.ID;
// this.Type = builder.Type;
// this.Title = builder.Title;
// this.Description = builder.Description;
// this.Selected = builder.Selected;
// }
//
// public int getID() {
// return this.ID;
// }
//
// public void setID(int ID) {
// this.ID = ID;
// }
//
// public int getType() {
// return this.Type;
// }
//
// public void setType(int Type) {
// this.Type = Type;
// }
//
// public String getTitle() {
// return this.Title;
// }
//
// public void setTitle(String Title) {
// this.Title = Title;
// }
//
// public String getDescription() {
// return this.Description;
// }
//
// public void setDescription(String Description) {
// this.Description = Description;
// }
//
// public boolean isSelected() {
// return this.Selected;
// }
//
// public void setSelected(boolean Selected) {
// this.Selected = Selected;
// }
//
// @Override
// public String toString() {
// return "SettingsItem{" +
// "ID=" + ID +
// ", Type=" + Type +
// ", Title='" + Title + '\'' +
// ", Description='" + Description + '\'' +
// ", Selected=" + Selected +
// '}';
// }
//
// public static class Builder {
// private int ID;
// private int Type;
// private String Title;
// private String Description;
// private boolean Selected;
//
// public Builder() {
// this.ID = -1;
// this.Type = -1;
// this.Title = "null";
// this.Description = "null";
// this.Selected = false;
// }
//
// public Builder id(int ID) {
// this.ID = ID;
// return this;
// }
//
// public Builder type(int Type) {
// this.Type = Type;
// return this;
// }
//
// public Builder title(String Title) {
// this.Title = Title;
// return this;
// }
//
// public Builder description(String Description) {
// this.Description = Description;
// return this;
// }
//
// public Builder selected(boolean Selected) {
// this.Selected = Selected;
// return this;
// }
//
// public SettingsItem build() {
// return new SettingsItem(this);
// }
// }
// }
| import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import com.pkmmte.techdissected.R;
import com.pkmmte.techdissected.model.SettingsItem;
import java.util.ArrayList;
import java.util.List; | package com.pkmmte.techdissected.adapter;
public class SettingsAdapter extends BaseAdapter {
// View Types
public static final int TYPE_HEADER = 0;
public static final int TYPE_DIVIDER = 1;
public static final int TYPE_TEXT = 2;
public static final int TYPE_CHECKBOX = 3;
public static final int TYPE_MAX_COUNT = 4;
// Essential Resources | // Path: app/src/main/java/com/pkmmte/techdissected/model/SettingsItem.java
// public class SettingsItem {
// private int ID;
// private int Type;
// private String Title;
// private String Description;
// private boolean Selected;
//
// public SettingsItem() {
// this.ID = -1;
// this.Type = -1;
// this.Title = "null";
// this.Description = "null";
// this.Selected = false;
// }
//
// public SettingsItem(int Type) {
// this.ID = -1;
// this.Type = Type;
// this.Title = "null";
// this.Description = "null";
// this.Selected = false;
// }
//
// public SettingsItem(int Type, String Title) {
// this.ID = -1;
// this.Type = Type;
// this.Title = Title;
// this.Description = "null";
// this.Selected = false;
// }
//
// public SettingsItem(int Type, String Title, String Description) {
// this.ID = -1;
// this.Type = Type;
// this.Title = Title;
// this.Description = Description;
// this.Selected = false;
// }
//
// public SettingsItem(int Type, String Title, String Description, boolean Selected) {
// this.ID = -1;
// this.Type = Type;
// this.Title = Title;
// this.Description = Description;
// this.Selected = Selected;
// }
//
// public SettingsItem(Builder builder) {
// this.ID = builder.ID;
// this.Type = builder.Type;
// this.Title = builder.Title;
// this.Description = builder.Description;
// this.Selected = builder.Selected;
// }
//
// public int getID() {
// return this.ID;
// }
//
// public void setID(int ID) {
// this.ID = ID;
// }
//
// public int getType() {
// return this.Type;
// }
//
// public void setType(int Type) {
// this.Type = Type;
// }
//
// public String getTitle() {
// return this.Title;
// }
//
// public void setTitle(String Title) {
// this.Title = Title;
// }
//
// public String getDescription() {
// return this.Description;
// }
//
// public void setDescription(String Description) {
// this.Description = Description;
// }
//
// public boolean isSelected() {
// return this.Selected;
// }
//
// public void setSelected(boolean Selected) {
// this.Selected = Selected;
// }
//
// @Override
// public String toString() {
// return "SettingsItem{" +
// "ID=" + ID +
// ", Type=" + Type +
// ", Title='" + Title + '\'' +
// ", Description='" + Description + '\'' +
// ", Selected=" + Selected +
// '}';
// }
//
// public static class Builder {
// private int ID;
// private int Type;
// private String Title;
// private String Description;
// private boolean Selected;
//
// public Builder() {
// this.ID = -1;
// this.Type = -1;
// this.Title = "null";
// this.Description = "null";
// this.Selected = false;
// }
//
// public Builder id(int ID) {
// this.ID = ID;
// return this;
// }
//
// public Builder type(int Type) {
// this.Type = Type;
// return this;
// }
//
// public Builder title(String Title) {
// this.Title = Title;
// return this;
// }
//
// public Builder description(String Description) {
// this.Description = Description;
// return this;
// }
//
// public Builder selected(boolean Selected) {
// this.Selected = Selected;
// return this;
// }
//
// public SettingsItem build() {
// return new SettingsItem(this);
// }
// }
// }
// Path: app/src/main/java/com/pkmmte/techdissected/adapter/SettingsAdapter.java
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import com.pkmmte.techdissected.R;
import com.pkmmte.techdissected.model.SettingsItem;
import java.util.ArrayList;
import java.util.List;
package com.pkmmte.techdissected.adapter;
public class SettingsAdapter extends BaseAdapter {
// View Types
public static final int TYPE_HEADER = 0;
public static final int TYPE_DIVIDER = 1;
public static final int TYPE_TEXT = 2;
public static final int TYPE_CHECKBOX = 3;
public static final int TYPE_MAX_COUNT = 4;
// Essential Resources | private List<SettingsItem> mSettings; |
Pkmmte/TechDissected | app/src/main/java/com/pkmmte/techdissected/util/Constants.java | // Path: app/src/main/java/com/pkmmte/techdissected/model/Author.java
// public class Author {
// private Uri url;
// private Uri avatar;
// private String username;
// private String name;
// private String description;
//
// public Author() {
// this.url = null;
// this.avatar = null;
// this.username = null;
// this.name = null;
// this.description = null;
// }
//
// public Author(Uri url, Uri avatar, String username, String name, String description) {
// this.url = url;
// this.avatar = avatar;
// this.username = username;
// this.name = name;
// this.description = description;
// }
//
// public Uri getUrl() {
// return url;
// }
//
// public void setUrl(Uri url) {
// this.url = url;
// }
//
// public Uri getAvatar() {
// return avatar;
// }
//
// public void setAvatar(Uri avatar) {
// this.avatar = avatar;
// }
//
// public String getUsername() {
// return username;
// }
//
// public void setUsername(String username) {
// this.username = username;
// }
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public String getDescription() {
// return description;
// }
//
// public void setDescription(String description) {
// this.description = description;
// }
//
// public static class ListBuilder {
// private final List<Author> authorList;
//
// public ListBuilder() {
// authorList = new ArrayList<Author>();
// }
//
// public ListBuilder add(Uri url, Uri avatar, String username, String name, String description) {
// authorList.add(new Author(url, avatar, username, name, description));
// return this;
// }
//
// public List<Author> build() {
// return authorList;
// }
// }
// }
| import android.net.Uri;
import com.pkmmte.pkrss.Category;
import com.pkmmte.techdissected.model.Author;
import java.util.List; | package com.pkmmte.techdissected.util;
public class Constants {
public static final String PREFS_NAME = "TechDissected";
public static final String PREF_READ = "MARK READ";
public static final String WEBSITE_URL = "http://techdissected.com";
public static final String CATEGORY_URL = WEBSITE_URL + "/category";
public static final String MAIN_FEED = WEBSITE_URL + "/feed";
public static final String PKRSS_URL = "https://github.com/Pkmmte/PkRSS";
public static final String DEV_URL = "http://pkmmte.com";
public static final List<Category> CATEGORIES = new Category.ListBuilder()
.add("All Posts", MAIN_FEED)
.add("News", CATEGORY_URL + "/news/feed")
.add("Editorials", CATEGORY_URL + "/editorials-and-discussions/feed")
.add("Web & Computing", CATEGORY_URL + "/web-and-computing/feed")
.add("Google", CATEGORY_URL + "/google/feed")
.add("Apple", CATEGORY_URL + "/apple/feed")
.add("Microsoft", CATEGORY_URL + "/microsoft/feed")
.add("Alternative Tech", CATEGORY_URL + "/alternative-tech/feed")
.add("Automobile", CATEGORY_URL + "/automotive/feed")
.add("Gaming", CATEGORY_URL + "/gaming/feed")
.add("Satire", CATEGORY_URL + "/satire/feed")
.add("Wearables", CATEGORY_URL + "/wearables/feed")
.build();
public static final Category DEFAULT_CATEGORY = CATEGORIES.get(0);
| // Path: app/src/main/java/com/pkmmte/techdissected/model/Author.java
// public class Author {
// private Uri url;
// private Uri avatar;
// private String username;
// private String name;
// private String description;
//
// public Author() {
// this.url = null;
// this.avatar = null;
// this.username = null;
// this.name = null;
// this.description = null;
// }
//
// public Author(Uri url, Uri avatar, String username, String name, String description) {
// this.url = url;
// this.avatar = avatar;
// this.username = username;
// this.name = name;
// this.description = description;
// }
//
// public Uri getUrl() {
// return url;
// }
//
// public void setUrl(Uri url) {
// this.url = url;
// }
//
// public Uri getAvatar() {
// return avatar;
// }
//
// public void setAvatar(Uri avatar) {
// this.avatar = avatar;
// }
//
// public String getUsername() {
// return username;
// }
//
// public void setUsername(String username) {
// this.username = username;
// }
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public String getDescription() {
// return description;
// }
//
// public void setDescription(String description) {
// this.description = description;
// }
//
// public static class ListBuilder {
// private final List<Author> authorList;
//
// public ListBuilder() {
// authorList = new ArrayList<Author>();
// }
//
// public ListBuilder add(Uri url, Uri avatar, String username, String name, String description) {
// authorList.add(new Author(url, avatar, username, name, description));
// return this;
// }
//
// public List<Author> build() {
// return authorList;
// }
// }
// }
// Path: app/src/main/java/com/pkmmte/techdissected/util/Constants.java
import android.net.Uri;
import com.pkmmte.pkrss.Category;
import com.pkmmte.techdissected.model.Author;
import java.util.List;
package com.pkmmte.techdissected.util;
public class Constants {
public static final String PREFS_NAME = "TechDissected";
public static final String PREF_READ = "MARK READ";
public static final String WEBSITE_URL = "http://techdissected.com";
public static final String CATEGORY_URL = WEBSITE_URL + "/category";
public static final String MAIN_FEED = WEBSITE_URL + "/feed";
public static final String PKRSS_URL = "https://github.com/Pkmmte/PkRSS";
public static final String DEV_URL = "http://pkmmte.com";
public static final List<Category> CATEGORIES = new Category.ListBuilder()
.add("All Posts", MAIN_FEED)
.add("News", CATEGORY_URL + "/news/feed")
.add("Editorials", CATEGORY_URL + "/editorials-and-discussions/feed")
.add("Web & Computing", CATEGORY_URL + "/web-and-computing/feed")
.add("Google", CATEGORY_URL + "/google/feed")
.add("Apple", CATEGORY_URL + "/apple/feed")
.add("Microsoft", CATEGORY_URL + "/microsoft/feed")
.add("Alternative Tech", CATEGORY_URL + "/alternative-tech/feed")
.add("Automobile", CATEGORY_URL + "/automotive/feed")
.add("Gaming", CATEGORY_URL + "/gaming/feed")
.add("Satire", CATEGORY_URL + "/satire/feed")
.add("Wearables", CATEGORY_URL + "/wearables/feed")
.build();
public static final Category DEFAULT_CATEGORY = CATEGORIES.get(0);
| public static final List<Author> AUTHORS = new Author.ListBuilder() |
google/mug | mug/src/test/java/com/google/mu/util/concurrent/UtilsTest.java | // Path: mug/src/test/java/com/google/mu/util/concurrent/FutureAssertions.java
// public static ThrowableSubject assertCauseOf(
// Class<? extends Throwable> exceptionType, CompletionStage<?> stage) {
// CompletableFuture<?> future = stage.toCompletableFuture();
// Throwable thrown = Assertions.assertThrows(exceptionType, future::get);
// assertThat(future.isDone()).isTrue();
// assertThat(future.isCompletedExceptionally()).isTrue();
// return assertThat(thrown.getCause());
// }
| import org.junit.Test;
import org.mockito.Mockito;
import com.google.common.testing.NullPointerTester;
import static com.google.common.truth.Truth.assertThat;
import static com.google.mu.util.concurrent.FutureAssertions.assertCauseOf;
import static java.util.Arrays.asList;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import java.io.IOException;
import java.lang.reflect.Method;
import java.util.Optional;
import java.util.concurrent.CancellationException;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.atomic.AtomicReference; | }
@Test public void testPropagateCancellation_innerAlreadyCompleted() throws Exception {
CompletableFuture<String> outer = new CompletableFuture<>();
CompletableFuture<String> inner = new CompletableFuture<>();
assertThat(Utils.propagateCancellation(outer, inner)).isSameAs(outer);
inner.complete("inner");
outer.cancel(false);
assertThat(outer.isCancelled()).isTrue();
assertThat(inner.isCancelled()).isFalse();
assertThat(outer.isCompletedExceptionally()).isTrue();
assertThat(inner.isCompletedExceptionally()).isFalse();
assertThat(outer.isDone()).isTrue();
assertThat(inner.isDone()).isTrue();
assertThat(inner.get()).isEqualTo("inner");
}
@Test public void testPropagateCancellation_innerAlreadyFailed() {
CompletableFuture<String> outer = new CompletableFuture<>();
CompletableFuture<String> inner = new CompletableFuture<>();
assertThat(Utils.propagateCancellation(outer, inner)).isSameAs(outer);
IOException exception = new IOException();
inner.completeExceptionally(exception);
outer.cancel(false);
assertThat(outer.isCancelled()).isTrue();
assertThat(inner.isCancelled()).isFalse();
assertThat(outer.isCompletedExceptionally()).isTrue();
assertThat(inner.isCompletedExceptionally()).isTrue();
assertThat(outer.isDone()).isTrue();
assertThat(inner.isDone()).isTrue(); | // Path: mug/src/test/java/com/google/mu/util/concurrent/FutureAssertions.java
// public static ThrowableSubject assertCauseOf(
// Class<? extends Throwable> exceptionType, CompletionStage<?> stage) {
// CompletableFuture<?> future = stage.toCompletableFuture();
// Throwable thrown = Assertions.assertThrows(exceptionType, future::get);
// assertThat(future.isDone()).isTrue();
// assertThat(future.isCompletedExceptionally()).isTrue();
// return assertThat(thrown.getCause());
// }
// Path: mug/src/test/java/com/google/mu/util/concurrent/UtilsTest.java
import org.junit.Test;
import org.mockito.Mockito;
import com.google.common.testing.NullPointerTester;
import static com.google.common.truth.Truth.assertThat;
import static com.google.mu.util.concurrent.FutureAssertions.assertCauseOf;
import static java.util.Arrays.asList;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import java.io.IOException;
import java.lang.reflect.Method;
import java.util.Optional;
import java.util.concurrent.CancellationException;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.atomic.AtomicReference;
}
@Test public void testPropagateCancellation_innerAlreadyCompleted() throws Exception {
CompletableFuture<String> outer = new CompletableFuture<>();
CompletableFuture<String> inner = new CompletableFuture<>();
assertThat(Utils.propagateCancellation(outer, inner)).isSameAs(outer);
inner.complete("inner");
outer.cancel(false);
assertThat(outer.isCancelled()).isTrue();
assertThat(inner.isCancelled()).isFalse();
assertThat(outer.isCompletedExceptionally()).isTrue();
assertThat(inner.isCompletedExceptionally()).isFalse();
assertThat(outer.isDone()).isTrue();
assertThat(inner.isDone()).isTrue();
assertThat(inner.get()).isEqualTo("inner");
}
@Test public void testPropagateCancellation_innerAlreadyFailed() {
CompletableFuture<String> outer = new CompletableFuture<>();
CompletableFuture<String> inner = new CompletableFuture<>();
assertThat(Utils.propagateCancellation(outer, inner)).isSameAs(outer);
IOException exception = new IOException();
inner.completeExceptionally(exception);
outer.cancel(false);
assertThat(outer.isCancelled()).isTrue();
assertThat(inner.isCancelled()).isFalse();
assertThat(outer.isCompletedExceptionally()).isTrue();
assertThat(inner.isCompletedExceptionally()).isTrue();
assertThat(outer.isDone()).isTrue();
assertThat(inner.isDone()).isTrue(); | assertCauseOf(ExecutionException.class, inner).isSameAs(exception); |
google/mug | mug-protobuf/src/test/java/com/google/mu/protobuf/util/StructBuilderTest.java | // Path: mug-guava/src/main/java/com/google/mu/collect/Immutables.java
// public static <E> ImmutableList<E> list() {
// return ImmutableList.of();
// }
//
// Path: mug-guava/src/main/java/com/google/mu/collect/Immutables.java
// public static <K, V> ImmutableMap<K, V> map() {
// return ImmutableMap.of();
// }
//
// Path: mug-guava/src/main/java/com/google/mu/collect/Immutables.java
// public static <R, C, V> ImmutableTable<R, C, V> table() {
// return ImmutableTable.of();
// }
//
// Path: mug-protobuf/src/main/java/com/google/mu/protobuf/util/MoreStructs.java
// public static Struct struct(String name, boolean value) {
// return struct(name, valueOf(value));
// }
//
// Path: mug-protobuf/src/main/java/com/google/mu/protobuf/util/MoreValues.java
// public static ListValue listValueOf(double... values) {
// return stream(values).mapToObj(MoreValues::valueOf).collect(toListValue());
// }
| import static com.google.common.truth.Truth.assertThat;
import static com.google.mu.collect.Immutables.list;
import static com.google.mu.collect.Immutables.map;
import static com.google.mu.collect.Immutables.table;
import static com.google.mu.protobuf.util.MoreStructs.struct;
import static com.google.mu.protobuf.util.MoreValues.listValueOf;
import static org.junit.Assert.assertThrows;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import com.google.common.collect.ImmutableListMultimap;
import com.google.common.testing.NullPointerTester;
import com.google.protobuf.ListValue;
import com.google.protobuf.Struct;
import com.google.protobuf.Value;
import com.google.protobuf.util.Structs;
import com.google.protobuf.util.Values; | package com.google.mu.protobuf.util;
@RunWith(JUnit4.class)
public class StructBuilderTest {
@Test public void testAdd_boolean() {
assertThat(new StructBuilder().add("k", true).build())
.isEqualTo(Structs.of("k", Values.of(true)));
assertThat(new StructBuilder().add("k", false).build())
.isEqualTo(Structs.of("k", Values.of(false)));
}
@Test public void testAdd_string() {
assertThat(new StructBuilder().add("k", "v").build())
.isEqualTo(Structs.of("k", Values.of("v")));
}
@Test public void testAdd_number() {
assertThat(new StructBuilder().add("k", 1).build())
.isEqualTo(Structs.of("k", Values.of(1)));
}
@Test public void testAdd_listValue() { | // Path: mug-guava/src/main/java/com/google/mu/collect/Immutables.java
// public static <E> ImmutableList<E> list() {
// return ImmutableList.of();
// }
//
// Path: mug-guava/src/main/java/com/google/mu/collect/Immutables.java
// public static <K, V> ImmutableMap<K, V> map() {
// return ImmutableMap.of();
// }
//
// Path: mug-guava/src/main/java/com/google/mu/collect/Immutables.java
// public static <R, C, V> ImmutableTable<R, C, V> table() {
// return ImmutableTable.of();
// }
//
// Path: mug-protobuf/src/main/java/com/google/mu/protobuf/util/MoreStructs.java
// public static Struct struct(String name, boolean value) {
// return struct(name, valueOf(value));
// }
//
// Path: mug-protobuf/src/main/java/com/google/mu/protobuf/util/MoreValues.java
// public static ListValue listValueOf(double... values) {
// return stream(values).mapToObj(MoreValues::valueOf).collect(toListValue());
// }
// Path: mug-protobuf/src/test/java/com/google/mu/protobuf/util/StructBuilderTest.java
import static com.google.common.truth.Truth.assertThat;
import static com.google.mu.collect.Immutables.list;
import static com.google.mu.collect.Immutables.map;
import static com.google.mu.collect.Immutables.table;
import static com.google.mu.protobuf.util.MoreStructs.struct;
import static com.google.mu.protobuf.util.MoreValues.listValueOf;
import static org.junit.Assert.assertThrows;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import com.google.common.collect.ImmutableListMultimap;
import com.google.common.testing.NullPointerTester;
import com.google.protobuf.ListValue;
import com.google.protobuf.Struct;
import com.google.protobuf.Value;
import com.google.protobuf.util.Structs;
import com.google.protobuf.util.Values;
package com.google.mu.protobuf.util;
@RunWith(JUnit4.class)
public class StructBuilderTest {
@Test public void testAdd_boolean() {
assertThat(new StructBuilder().add("k", true).build())
.isEqualTo(Structs.of("k", Values.of(true)));
assertThat(new StructBuilder().add("k", false).build())
.isEqualTo(Structs.of("k", Values.of(false)));
}
@Test public void testAdd_string() {
assertThat(new StructBuilder().add("k", "v").build())
.isEqualTo(Structs.of("k", Values.of("v")));
}
@Test public void testAdd_number() {
assertThat(new StructBuilder().add("k", 1).build())
.isEqualTo(Structs.of("k", Values.of(1)));
}
@Test public void testAdd_listValue() { | ListValue listValue = listValueOf(1, 2); |
google/mug | mug-protobuf/src/test/java/com/google/mu/protobuf/util/StructBuilderTest.java | // Path: mug-guava/src/main/java/com/google/mu/collect/Immutables.java
// public static <E> ImmutableList<E> list() {
// return ImmutableList.of();
// }
//
// Path: mug-guava/src/main/java/com/google/mu/collect/Immutables.java
// public static <K, V> ImmutableMap<K, V> map() {
// return ImmutableMap.of();
// }
//
// Path: mug-guava/src/main/java/com/google/mu/collect/Immutables.java
// public static <R, C, V> ImmutableTable<R, C, V> table() {
// return ImmutableTable.of();
// }
//
// Path: mug-protobuf/src/main/java/com/google/mu/protobuf/util/MoreStructs.java
// public static Struct struct(String name, boolean value) {
// return struct(name, valueOf(value));
// }
//
// Path: mug-protobuf/src/main/java/com/google/mu/protobuf/util/MoreValues.java
// public static ListValue listValueOf(double... values) {
// return stream(values).mapToObj(MoreValues::valueOf).collect(toListValue());
// }
| import static com.google.common.truth.Truth.assertThat;
import static com.google.mu.collect.Immutables.list;
import static com.google.mu.collect.Immutables.map;
import static com.google.mu.collect.Immutables.table;
import static com.google.mu.protobuf.util.MoreStructs.struct;
import static com.google.mu.protobuf.util.MoreValues.listValueOf;
import static org.junit.Assert.assertThrows;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import com.google.common.collect.ImmutableListMultimap;
import com.google.common.testing.NullPointerTester;
import com.google.protobuf.ListValue;
import com.google.protobuf.Struct;
import com.google.protobuf.Value;
import com.google.protobuf.util.Structs;
import com.google.protobuf.util.Values; | package com.google.mu.protobuf.util;
@RunWith(JUnit4.class)
public class StructBuilderTest {
@Test public void testAdd_boolean() {
assertThat(new StructBuilder().add("k", true).build())
.isEqualTo(Structs.of("k", Values.of(true)));
assertThat(new StructBuilder().add("k", false).build())
.isEqualTo(Structs.of("k", Values.of(false)));
}
@Test public void testAdd_string() {
assertThat(new StructBuilder().add("k", "v").build())
.isEqualTo(Structs.of("k", Values.of("v")));
}
@Test public void testAdd_number() {
assertThat(new StructBuilder().add("k", 1).build())
.isEqualTo(Structs.of("k", Values.of(1)));
}
@Test public void testAdd_listValue() {
ListValue listValue = listValueOf(1, 2);
assertThat(new StructBuilder().add("k", listValue).build())
.isEqualTo(Structs.of("k", Values.of(listValue)));
}
@Test public void testAdd_list() { | // Path: mug-guava/src/main/java/com/google/mu/collect/Immutables.java
// public static <E> ImmutableList<E> list() {
// return ImmutableList.of();
// }
//
// Path: mug-guava/src/main/java/com/google/mu/collect/Immutables.java
// public static <K, V> ImmutableMap<K, V> map() {
// return ImmutableMap.of();
// }
//
// Path: mug-guava/src/main/java/com/google/mu/collect/Immutables.java
// public static <R, C, V> ImmutableTable<R, C, V> table() {
// return ImmutableTable.of();
// }
//
// Path: mug-protobuf/src/main/java/com/google/mu/protobuf/util/MoreStructs.java
// public static Struct struct(String name, boolean value) {
// return struct(name, valueOf(value));
// }
//
// Path: mug-protobuf/src/main/java/com/google/mu/protobuf/util/MoreValues.java
// public static ListValue listValueOf(double... values) {
// return stream(values).mapToObj(MoreValues::valueOf).collect(toListValue());
// }
// Path: mug-protobuf/src/test/java/com/google/mu/protobuf/util/StructBuilderTest.java
import static com.google.common.truth.Truth.assertThat;
import static com.google.mu.collect.Immutables.list;
import static com.google.mu.collect.Immutables.map;
import static com.google.mu.collect.Immutables.table;
import static com.google.mu.protobuf.util.MoreStructs.struct;
import static com.google.mu.protobuf.util.MoreValues.listValueOf;
import static org.junit.Assert.assertThrows;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import com.google.common.collect.ImmutableListMultimap;
import com.google.common.testing.NullPointerTester;
import com.google.protobuf.ListValue;
import com.google.protobuf.Struct;
import com.google.protobuf.Value;
import com.google.protobuf.util.Structs;
import com.google.protobuf.util.Values;
package com.google.mu.protobuf.util;
@RunWith(JUnit4.class)
public class StructBuilderTest {
@Test public void testAdd_boolean() {
assertThat(new StructBuilder().add("k", true).build())
.isEqualTo(Structs.of("k", Values.of(true)));
assertThat(new StructBuilder().add("k", false).build())
.isEqualTo(Structs.of("k", Values.of(false)));
}
@Test public void testAdd_string() {
assertThat(new StructBuilder().add("k", "v").build())
.isEqualTo(Structs.of("k", Values.of("v")));
}
@Test public void testAdd_number() {
assertThat(new StructBuilder().add("k", 1).build())
.isEqualTo(Structs.of("k", Values.of(1)));
}
@Test public void testAdd_listValue() {
ListValue listValue = listValueOf(1, 2);
assertThat(new StructBuilder().add("k", listValue).build())
.isEqualTo(Structs.of("k", Values.of(listValue)));
}
@Test public void testAdd_list() { | assertThat(new StructBuilder().add("k", list(Values.of(1), Values.of(2))).build()) |
google/mug | mug-protobuf/src/test/java/com/google/mu/protobuf/util/StructBuilderTest.java | // Path: mug-guava/src/main/java/com/google/mu/collect/Immutables.java
// public static <E> ImmutableList<E> list() {
// return ImmutableList.of();
// }
//
// Path: mug-guava/src/main/java/com/google/mu/collect/Immutables.java
// public static <K, V> ImmutableMap<K, V> map() {
// return ImmutableMap.of();
// }
//
// Path: mug-guava/src/main/java/com/google/mu/collect/Immutables.java
// public static <R, C, V> ImmutableTable<R, C, V> table() {
// return ImmutableTable.of();
// }
//
// Path: mug-protobuf/src/main/java/com/google/mu/protobuf/util/MoreStructs.java
// public static Struct struct(String name, boolean value) {
// return struct(name, valueOf(value));
// }
//
// Path: mug-protobuf/src/main/java/com/google/mu/protobuf/util/MoreValues.java
// public static ListValue listValueOf(double... values) {
// return stream(values).mapToObj(MoreValues::valueOf).collect(toListValue());
// }
| import static com.google.common.truth.Truth.assertThat;
import static com.google.mu.collect.Immutables.list;
import static com.google.mu.collect.Immutables.map;
import static com.google.mu.collect.Immutables.table;
import static com.google.mu.protobuf.util.MoreStructs.struct;
import static com.google.mu.protobuf.util.MoreValues.listValueOf;
import static org.junit.Assert.assertThrows;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import com.google.common.collect.ImmutableListMultimap;
import com.google.common.testing.NullPointerTester;
import com.google.protobuf.ListValue;
import com.google.protobuf.Struct;
import com.google.protobuf.Value;
import com.google.protobuf.util.Structs;
import com.google.protobuf.util.Values; | package com.google.mu.protobuf.util;
@RunWith(JUnit4.class)
public class StructBuilderTest {
@Test public void testAdd_boolean() {
assertThat(new StructBuilder().add("k", true).build())
.isEqualTo(Structs.of("k", Values.of(true)));
assertThat(new StructBuilder().add("k", false).build())
.isEqualTo(Structs.of("k", Values.of(false)));
}
@Test public void testAdd_string() {
assertThat(new StructBuilder().add("k", "v").build())
.isEqualTo(Structs.of("k", Values.of("v")));
}
@Test public void testAdd_number() {
assertThat(new StructBuilder().add("k", 1).build())
.isEqualTo(Structs.of("k", Values.of(1)));
}
@Test public void testAdd_listValue() {
ListValue listValue = listValueOf(1, 2);
assertThat(new StructBuilder().add("k", listValue).build())
.isEqualTo(Structs.of("k", Values.of(listValue)));
}
@Test public void testAdd_list() {
assertThat(new StructBuilder().add("k", list(Values.of(1), Values.of(2))).build())
.isEqualTo(Structs.of("k", Values.of(listValueOf(1, 2))));
}
@Test public void testAddAll_map() { | // Path: mug-guava/src/main/java/com/google/mu/collect/Immutables.java
// public static <E> ImmutableList<E> list() {
// return ImmutableList.of();
// }
//
// Path: mug-guava/src/main/java/com/google/mu/collect/Immutables.java
// public static <K, V> ImmutableMap<K, V> map() {
// return ImmutableMap.of();
// }
//
// Path: mug-guava/src/main/java/com/google/mu/collect/Immutables.java
// public static <R, C, V> ImmutableTable<R, C, V> table() {
// return ImmutableTable.of();
// }
//
// Path: mug-protobuf/src/main/java/com/google/mu/protobuf/util/MoreStructs.java
// public static Struct struct(String name, boolean value) {
// return struct(name, valueOf(value));
// }
//
// Path: mug-protobuf/src/main/java/com/google/mu/protobuf/util/MoreValues.java
// public static ListValue listValueOf(double... values) {
// return stream(values).mapToObj(MoreValues::valueOf).collect(toListValue());
// }
// Path: mug-protobuf/src/test/java/com/google/mu/protobuf/util/StructBuilderTest.java
import static com.google.common.truth.Truth.assertThat;
import static com.google.mu.collect.Immutables.list;
import static com.google.mu.collect.Immutables.map;
import static com.google.mu.collect.Immutables.table;
import static com.google.mu.protobuf.util.MoreStructs.struct;
import static com.google.mu.protobuf.util.MoreValues.listValueOf;
import static org.junit.Assert.assertThrows;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import com.google.common.collect.ImmutableListMultimap;
import com.google.common.testing.NullPointerTester;
import com.google.protobuf.ListValue;
import com.google.protobuf.Struct;
import com.google.protobuf.Value;
import com.google.protobuf.util.Structs;
import com.google.protobuf.util.Values;
package com.google.mu.protobuf.util;
@RunWith(JUnit4.class)
public class StructBuilderTest {
@Test public void testAdd_boolean() {
assertThat(new StructBuilder().add("k", true).build())
.isEqualTo(Structs.of("k", Values.of(true)));
assertThat(new StructBuilder().add("k", false).build())
.isEqualTo(Structs.of("k", Values.of(false)));
}
@Test public void testAdd_string() {
assertThat(new StructBuilder().add("k", "v").build())
.isEqualTo(Structs.of("k", Values.of("v")));
}
@Test public void testAdd_number() {
assertThat(new StructBuilder().add("k", 1).build())
.isEqualTo(Structs.of("k", Values.of(1)));
}
@Test public void testAdd_listValue() {
ListValue listValue = listValueOf(1, 2);
assertThat(new StructBuilder().add("k", listValue).build())
.isEqualTo(Structs.of("k", Values.of(listValue)));
}
@Test public void testAdd_list() {
assertThat(new StructBuilder().add("k", list(Values.of(1), Values.of(2))).build())
.isEqualTo(Structs.of("k", Values.of(listValueOf(1, 2))));
}
@Test public void testAddAll_map() { | assertThat(new StructBuilder().addAll(map("one", Values.of(1))).build()) |
google/mug | mug-protobuf/src/test/java/com/google/mu/protobuf/util/StructBuilderTest.java | // Path: mug-guava/src/main/java/com/google/mu/collect/Immutables.java
// public static <E> ImmutableList<E> list() {
// return ImmutableList.of();
// }
//
// Path: mug-guava/src/main/java/com/google/mu/collect/Immutables.java
// public static <K, V> ImmutableMap<K, V> map() {
// return ImmutableMap.of();
// }
//
// Path: mug-guava/src/main/java/com/google/mu/collect/Immutables.java
// public static <R, C, V> ImmutableTable<R, C, V> table() {
// return ImmutableTable.of();
// }
//
// Path: mug-protobuf/src/main/java/com/google/mu/protobuf/util/MoreStructs.java
// public static Struct struct(String name, boolean value) {
// return struct(name, valueOf(value));
// }
//
// Path: mug-protobuf/src/main/java/com/google/mu/protobuf/util/MoreValues.java
// public static ListValue listValueOf(double... values) {
// return stream(values).mapToObj(MoreValues::valueOf).collect(toListValue());
// }
| import static com.google.common.truth.Truth.assertThat;
import static com.google.mu.collect.Immutables.list;
import static com.google.mu.collect.Immutables.map;
import static com.google.mu.collect.Immutables.table;
import static com.google.mu.protobuf.util.MoreStructs.struct;
import static com.google.mu.protobuf.util.MoreValues.listValueOf;
import static org.junit.Assert.assertThrows;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import com.google.common.collect.ImmutableListMultimap;
import com.google.common.testing.NullPointerTester;
import com.google.protobuf.ListValue;
import com.google.protobuf.Struct;
import com.google.protobuf.Value;
import com.google.protobuf.util.Structs;
import com.google.protobuf.util.Values; | package com.google.mu.protobuf.util;
@RunWith(JUnit4.class)
public class StructBuilderTest {
@Test public void testAdd_boolean() {
assertThat(new StructBuilder().add("k", true).build())
.isEqualTo(Structs.of("k", Values.of(true)));
assertThat(new StructBuilder().add("k", false).build())
.isEqualTo(Structs.of("k", Values.of(false)));
}
@Test public void testAdd_string() {
assertThat(new StructBuilder().add("k", "v").build())
.isEqualTo(Structs.of("k", Values.of("v")));
}
@Test public void testAdd_number() {
assertThat(new StructBuilder().add("k", 1).build())
.isEqualTo(Structs.of("k", Values.of(1)));
}
@Test public void testAdd_listValue() {
ListValue listValue = listValueOf(1, 2);
assertThat(new StructBuilder().add("k", listValue).build())
.isEqualTo(Structs.of("k", Values.of(listValue)));
}
@Test public void testAdd_list() {
assertThat(new StructBuilder().add("k", list(Values.of(1), Values.of(2))).build())
.isEqualTo(Structs.of("k", Values.of(listValueOf(1, 2))));
}
@Test public void testAddAll_map() {
assertThat(new StructBuilder().addAll(map("one", Values.of(1))).build()) | // Path: mug-guava/src/main/java/com/google/mu/collect/Immutables.java
// public static <E> ImmutableList<E> list() {
// return ImmutableList.of();
// }
//
// Path: mug-guava/src/main/java/com/google/mu/collect/Immutables.java
// public static <K, V> ImmutableMap<K, V> map() {
// return ImmutableMap.of();
// }
//
// Path: mug-guava/src/main/java/com/google/mu/collect/Immutables.java
// public static <R, C, V> ImmutableTable<R, C, V> table() {
// return ImmutableTable.of();
// }
//
// Path: mug-protobuf/src/main/java/com/google/mu/protobuf/util/MoreStructs.java
// public static Struct struct(String name, boolean value) {
// return struct(name, valueOf(value));
// }
//
// Path: mug-protobuf/src/main/java/com/google/mu/protobuf/util/MoreValues.java
// public static ListValue listValueOf(double... values) {
// return stream(values).mapToObj(MoreValues::valueOf).collect(toListValue());
// }
// Path: mug-protobuf/src/test/java/com/google/mu/protobuf/util/StructBuilderTest.java
import static com.google.common.truth.Truth.assertThat;
import static com.google.mu.collect.Immutables.list;
import static com.google.mu.collect.Immutables.map;
import static com.google.mu.collect.Immutables.table;
import static com.google.mu.protobuf.util.MoreStructs.struct;
import static com.google.mu.protobuf.util.MoreValues.listValueOf;
import static org.junit.Assert.assertThrows;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import com.google.common.collect.ImmutableListMultimap;
import com.google.common.testing.NullPointerTester;
import com.google.protobuf.ListValue;
import com.google.protobuf.Struct;
import com.google.protobuf.Value;
import com.google.protobuf.util.Structs;
import com.google.protobuf.util.Values;
package com.google.mu.protobuf.util;
@RunWith(JUnit4.class)
public class StructBuilderTest {
@Test public void testAdd_boolean() {
assertThat(new StructBuilder().add("k", true).build())
.isEqualTo(Structs.of("k", Values.of(true)));
assertThat(new StructBuilder().add("k", false).build())
.isEqualTo(Structs.of("k", Values.of(false)));
}
@Test public void testAdd_string() {
assertThat(new StructBuilder().add("k", "v").build())
.isEqualTo(Structs.of("k", Values.of("v")));
}
@Test public void testAdd_number() {
assertThat(new StructBuilder().add("k", 1).build())
.isEqualTo(Structs.of("k", Values.of(1)));
}
@Test public void testAdd_listValue() {
ListValue listValue = listValueOf(1, 2);
assertThat(new StructBuilder().add("k", listValue).build())
.isEqualTo(Structs.of("k", Values.of(listValue)));
}
@Test public void testAdd_list() {
assertThat(new StructBuilder().add("k", list(Values.of(1), Values.of(2))).build())
.isEqualTo(Structs.of("k", Values.of(listValueOf(1, 2))));
}
@Test public void testAddAll_map() {
assertThat(new StructBuilder().addAll(map("one", Values.of(1))).build()) | .isEqualTo(struct("one", 1)); |
google/mug | mug-protobuf/src/test/java/com/google/mu/protobuf/util/StructBuilderTest.java | // Path: mug-guava/src/main/java/com/google/mu/collect/Immutables.java
// public static <E> ImmutableList<E> list() {
// return ImmutableList.of();
// }
//
// Path: mug-guava/src/main/java/com/google/mu/collect/Immutables.java
// public static <K, V> ImmutableMap<K, V> map() {
// return ImmutableMap.of();
// }
//
// Path: mug-guava/src/main/java/com/google/mu/collect/Immutables.java
// public static <R, C, V> ImmutableTable<R, C, V> table() {
// return ImmutableTable.of();
// }
//
// Path: mug-protobuf/src/main/java/com/google/mu/protobuf/util/MoreStructs.java
// public static Struct struct(String name, boolean value) {
// return struct(name, valueOf(value));
// }
//
// Path: mug-protobuf/src/main/java/com/google/mu/protobuf/util/MoreValues.java
// public static ListValue listValueOf(double... values) {
// return stream(values).mapToObj(MoreValues::valueOf).collect(toListValue());
// }
| import static com.google.common.truth.Truth.assertThat;
import static com.google.mu.collect.Immutables.list;
import static com.google.mu.collect.Immutables.map;
import static com.google.mu.collect.Immutables.table;
import static com.google.mu.protobuf.util.MoreStructs.struct;
import static com.google.mu.protobuf.util.MoreValues.listValueOf;
import static org.junit.Assert.assertThrows;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import com.google.common.collect.ImmutableListMultimap;
import com.google.common.testing.NullPointerTester;
import com.google.protobuf.ListValue;
import com.google.protobuf.Struct;
import com.google.protobuf.Value;
import com.google.protobuf.util.Structs;
import com.google.protobuf.util.Values; | .isEqualTo(Structs.of("k", Values.of("v")));
}
@Test public void testAdd_number() {
assertThat(new StructBuilder().add("k", 1).build())
.isEqualTo(Structs.of("k", Values.of(1)));
}
@Test public void testAdd_listValue() {
ListValue listValue = listValueOf(1, 2);
assertThat(new StructBuilder().add("k", listValue).build())
.isEqualTo(Structs.of("k", Values.of(listValue)));
}
@Test public void testAdd_list() {
assertThat(new StructBuilder().add("k", list(Values.of(1), Values.of(2))).build())
.isEqualTo(Structs.of("k", Values.of(listValueOf(1, 2))));
}
@Test public void testAddAll_map() {
assertThat(new StructBuilder().addAll(map("one", Values.of(1))).build())
.isEqualTo(struct("one", 1));
}
@Test public void testAddAll_multimap() {
assertThat(new StructBuilder().addAll(ImmutableListMultimap.of("one", Values.of(1))).build())
.isEqualTo(struct("one", listValueOf(1)));
}
@Test public void testAddAll_table() { | // Path: mug-guava/src/main/java/com/google/mu/collect/Immutables.java
// public static <E> ImmutableList<E> list() {
// return ImmutableList.of();
// }
//
// Path: mug-guava/src/main/java/com/google/mu/collect/Immutables.java
// public static <K, V> ImmutableMap<K, V> map() {
// return ImmutableMap.of();
// }
//
// Path: mug-guava/src/main/java/com/google/mu/collect/Immutables.java
// public static <R, C, V> ImmutableTable<R, C, V> table() {
// return ImmutableTable.of();
// }
//
// Path: mug-protobuf/src/main/java/com/google/mu/protobuf/util/MoreStructs.java
// public static Struct struct(String name, boolean value) {
// return struct(name, valueOf(value));
// }
//
// Path: mug-protobuf/src/main/java/com/google/mu/protobuf/util/MoreValues.java
// public static ListValue listValueOf(double... values) {
// return stream(values).mapToObj(MoreValues::valueOf).collect(toListValue());
// }
// Path: mug-protobuf/src/test/java/com/google/mu/protobuf/util/StructBuilderTest.java
import static com.google.common.truth.Truth.assertThat;
import static com.google.mu.collect.Immutables.list;
import static com.google.mu.collect.Immutables.map;
import static com.google.mu.collect.Immutables.table;
import static com.google.mu.protobuf.util.MoreStructs.struct;
import static com.google.mu.protobuf.util.MoreValues.listValueOf;
import static org.junit.Assert.assertThrows;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import com.google.common.collect.ImmutableListMultimap;
import com.google.common.testing.NullPointerTester;
import com.google.protobuf.ListValue;
import com.google.protobuf.Struct;
import com.google.protobuf.Value;
import com.google.protobuf.util.Structs;
import com.google.protobuf.util.Values;
.isEqualTo(Structs.of("k", Values.of("v")));
}
@Test public void testAdd_number() {
assertThat(new StructBuilder().add("k", 1).build())
.isEqualTo(Structs.of("k", Values.of(1)));
}
@Test public void testAdd_listValue() {
ListValue listValue = listValueOf(1, 2);
assertThat(new StructBuilder().add("k", listValue).build())
.isEqualTo(Structs.of("k", Values.of(listValue)));
}
@Test public void testAdd_list() {
assertThat(new StructBuilder().add("k", list(Values.of(1), Values.of(2))).build())
.isEqualTo(Structs.of("k", Values.of(listValueOf(1, 2))));
}
@Test public void testAddAll_map() {
assertThat(new StructBuilder().addAll(map("one", Values.of(1))).build())
.isEqualTo(struct("one", 1));
}
@Test public void testAddAll_multimap() {
assertThat(new StructBuilder().addAll(ImmutableListMultimap.of("one", Values.of(1))).build())
.isEqualTo(struct("one", listValueOf(1)));
}
@Test public void testAddAll_table() { | assertThat(new StructBuilder().addAll(table("row", "col", Values.of(1))).build()) |
google/mug | mug-protobuf/src/test/java/com/google/mu/protobuf/util/MoreValuesTest.java | // Path: mug-guava/src/main/java/com/google/mu/collect/Immutables.java
// public static <E> ImmutableList<E> list() {
// return ImmutableList.of();
// }
//
// Path: mug-guava/src/main/java/com/google/mu/collect/Immutables.java
// public static <K, V> ImmutableMap<K, V> map() {
// return ImmutableMap.of();
// }
//
// Path: mug-protobuf/src/main/java/com/google/mu/protobuf/util/MoreStructs.java
// public static Struct struct(String name, boolean value) {
// return struct(name, valueOf(value));
// }
//
// Path: mug-protobuf/src/main/java/com/google/mu/protobuf/util/MoreValues.java
// public static final Value FALSE = Value.newBuilder().setBoolValue(false).build();
//
// Path: mug-protobuf/src/main/java/com/google/mu/protobuf/util/MoreValues.java
// public static final Value NULL =
// Value.newBuilder().setNullValue(NullValue.NULL_VALUE).build();
//
// Path: mug-protobuf/src/main/java/com/google/mu/protobuf/util/MoreValues.java
// public static final Value TRUE = Value.newBuilder().setBoolValue(true).build();
//
// Path: mug-protobuf/src/main/java/com/google/mu/protobuf/util/MoreValues.java
// public static ListValue listValueOf(double... values) {
// return stream(values).mapToObj(MoreValues::valueOf).collect(toListValue());
// }
//
// Path: mug-protobuf/src/main/java/com/google/mu/protobuf/util/MoreValues.java
// public static Collector<Value, ?, ListValue> toListValue() {
// return Collector.of(
// ListValue::newBuilder,
// ListValue.Builder::addValues,
// (a, b) -> a.addAllValues(b.getValuesList()),
// ListValue.Builder::build);
// }
| import static com.google.common.truth.Truth.assertThat;
import static com.google.mu.collect.Immutables.list;
import static com.google.mu.collect.Immutables.map;
import static com.google.mu.protobuf.util.MoreStructs.struct;
import static com.google.mu.protobuf.util.MoreValues.FALSE;
import static com.google.mu.protobuf.util.MoreValues.NULL;
import static com.google.mu.protobuf.util.MoreValues.TRUE;
import static com.google.mu.protobuf.util.MoreValues.listValueOf;
import static com.google.mu.protobuf.util.MoreValues.toListValue;
import static org.junit.Assert.assertThrows;
import java.util.List;
import java.util.stream.Stream;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import com.google.common.testing.NullPointerTester;
import com.google.protobuf.ListValue;
import com.google.protobuf.Value;
import com.google.protobuf.util.Structs;
import com.google.protobuf.util.Values; | package com.google.mu.protobuf.util;
@RunWith(JUnit4.class)
public class MoreValuesTest {
@Test public void testToListValue() {
Structor converter = new Structor();
assertThat( | // Path: mug-guava/src/main/java/com/google/mu/collect/Immutables.java
// public static <E> ImmutableList<E> list() {
// return ImmutableList.of();
// }
//
// Path: mug-guava/src/main/java/com/google/mu/collect/Immutables.java
// public static <K, V> ImmutableMap<K, V> map() {
// return ImmutableMap.of();
// }
//
// Path: mug-protobuf/src/main/java/com/google/mu/protobuf/util/MoreStructs.java
// public static Struct struct(String name, boolean value) {
// return struct(name, valueOf(value));
// }
//
// Path: mug-protobuf/src/main/java/com/google/mu/protobuf/util/MoreValues.java
// public static final Value FALSE = Value.newBuilder().setBoolValue(false).build();
//
// Path: mug-protobuf/src/main/java/com/google/mu/protobuf/util/MoreValues.java
// public static final Value NULL =
// Value.newBuilder().setNullValue(NullValue.NULL_VALUE).build();
//
// Path: mug-protobuf/src/main/java/com/google/mu/protobuf/util/MoreValues.java
// public static final Value TRUE = Value.newBuilder().setBoolValue(true).build();
//
// Path: mug-protobuf/src/main/java/com/google/mu/protobuf/util/MoreValues.java
// public static ListValue listValueOf(double... values) {
// return stream(values).mapToObj(MoreValues::valueOf).collect(toListValue());
// }
//
// Path: mug-protobuf/src/main/java/com/google/mu/protobuf/util/MoreValues.java
// public static Collector<Value, ?, ListValue> toListValue() {
// return Collector.of(
// ListValue::newBuilder,
// ListValue.Builder::addValues,
// (a, b) -> a.addAllValues(b.getValuesList()),
// ListValue.Builder::build);
// }
// Path: mug-protobuf/src/test/java/com/google/mu/protobuf/util/MoreValuesTest.java
import static com.google.common.truth.Truth.assertThat;
import static com.google.mu.collect.Immutables.list;
import static com.google.mu.collect.Immutables.map;
import static com.google.mu.protobuf.util.MoreStructs.struct;
import static com.google.mu.protobuf.util.MoreValues.FALSE;
import static com.google.mu.protobuf.util.MoreValues.NULL;
import static com.google.mu.protobuf.util.MoreValues.TRUE;
import static com.google.mu.protobuf.util.MoreValues.listValueOf;
import static com.google.mu.protobuf.util.MoreValues.toListValue;
import static org.junit.Assert.assertThrows;
import java.util.List;
import java.util.stream.Stream;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import com.google.common.testing.NullPointerTester;
import com.google.protobuf.ListValue;
import com.google.protobuf.Value;
import com.google.protobuf.util.Structs;
import com.google.protobuf.util.Values;
package com.google.mu.protobuf.util;
@RunWith(JUnit4.class)
public class MoreValuesTest {
@Test public void testToListValue() {
Structor converter = new Structor();
assertThat( | Stream.of(1, "foo", list(true, false), map("k", 20L)).map(converter::toValue).collect(toListValue())) |
google/mug | mug-protobuf/src/test/java/com/google/mu/protobuf/util/MoreValuesTest.java | // Path: mug-guava/src/main/java/com/google/mu/collect/Immutables.java
// public static <E> ImmutableList<E> list() {
// return ImmutableList.of();
// }
//
// Path: mug-guava/src/main/java/com/google/mu/collect/Immutables.java
// public static <K, V> ImmutableMap<K, V> map() {
// return ImmutableMap.of();
// }
//
// Path: mug-protobuf/src/main/java/com/google/mu/protobuf/util/MoreStructs.java
// public static Struct struct(String name, boolean value) {
// return struct(name, valueOf(value));
// }
//
// Path: mug-protobuf/src/main/java/com/google/mu/protobuf/util/MoreValues.java
// public static final Value FALSE = Value.newBuilder().setBoolValue(false).build();
//
// Path: mug-protobuf/src/main/java/com/google/mu/protobuf/util/MoreValues.java
// public static final Value NULL =
// Value.newBuilder().setNullValue(NullValue.NULL_VALUE).build();
//
// Path: mug-protobuf/src/main/java/com/google/mu/protobuf/util/MoreValues.java
// public static final Value TRUE = Value.newBuilder().setBoolValue(true).build();
//
// Path: mug-protobuf/src/main/java/com/google/mu/protobuf/util/MoreValues.java
// public static ListValue listValueOf(double... values) {
// return stream(values).mapToObj(MoreValues::valueOf).collect(toListValue());
// }
//
// Path: mug-protobuf/src/main/java/com/google/mu/protobuf/util/MoreValues.java
// public static Collector<Value, ?, ListValue> toListValue() {
// return Collector.of(
// ListValue::newBuilder,
// ListValue.Builder::addValues,
// (a, b) -> a.addAllValues(b.getValuesList()),
// ListValue.Builder::build);
// }
| import static com.google.common.truth.Truth.assertThat;
import static com.google.mu.collect.Immutables.list;
import static com.google.mu.collect.Immutables.map;
import static com.google.mu.protobuf.util.MoreStructs.struct;
import static com.google.mu.protobuf.util.MoreValues.FALSE;
import static com.google.mu.protobuf.util.MoreValues.NULL;
import static com.google.mu.protobuf.util.MoreValues.TRUE;
import static com.google.mu.protobuf.util.MoreValues.listValueOf;
import static com.google.mu.protobuf.util.MoreValues.toListValue;
import static org.junit.Assert.assertThrows;
import java.util.List;
import java.util.stream.Stream;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import com.google.common.testing.NullPointerTester;
import com.google.protobuf.ListValue;
import com.google.protobuf.Value;
import com.google.protobuf.util.Structs;
import com.google.protobuf.util.Values; | package com.google.mu.protobuf.util;
@RunWith(JUnit4.class)
public class MoreValuesTest {
@Test public void testToListValue() {
Structor converter = new Structor();
assertThat( | // Path: mug-guava/src/main/java/com/google/mu/collect/Immutables.java
// public static <E> ImmutableList<E> list() {
// return ImmutableList.of();
// }
//
// Path: mug-guava/src/main/java/com/google/mu/collect/Immutables.java
// public static <K, V> ImmutableMap<K, V> map() {
// return ImmutableMap.of();
// }
//
// Path: mug-protobuf/src/main/java/com/google/mu/protobuf/util/MoreStructs.java
// public static Struct struct(String name, boolean value) {
// return struct(name, valueOf(value));
// }
//
// Path: mug-protobuf/src/main/java/com/google/mu/protobuf/util/MoreValues.java
// public static final Value FALSE = Value.newBuilder().setBoolValue(false).build();
//
// Path: mug-protobuf/src/main/java/com/google/mu/protobuf/util/MoreValues.java
// public static final Value NULL =
// Value.newBuilder().setNullValue(NullValue.NULL_VALUE).build();
//
// Path: mug-protobuf/src/main/java/com/google/mu/protobuf/util/MoreValues.java
// public static final Value TRUE = Value.newBuilder().setBoolValue(true).build();
//
// Path: mug-protobuf/src/main/java/com/google/mu/protobuf/util/MoreValues.java
// public static ListValue listValueOf(double... values) {
// return stream(values).mapToObj(MoreValues::valueOf).collect(toListValue());
// }
//
// Path: mug-protobuf/src/main/java/com/google/mu/protobuf/util/MoreValues.java
// public static Collector<Value, ?, ListValue> toListValue() {
// return Collector.of(
// ListValue::newBuilder,
// ListValue.Builder::addValues,
// (a, b) -> a.addAllValues(b.getValuesList()),
// ListValue.Builder::build);
// }
// Path: mug-protobuf/src/test/java/com/google/mu/protobuf/util/MoreValuesTest.java
import static com.google.common.truth.Truth.assertThat;
import static com.google.mu.collect.Immutables.list;
import static com.google.mu.collect.Immutables.map;
import static com.google.mu.protobuf.util.MoreStructs.struct;
import static com.google.mu.protobuf.util.MoreValues.FALSE;
import static com.google.mu.protobuf.util.MoreValues.NULL;
import static com.google.mu.protobuf.util.MoreValues.TRUE;
import static com.google.mu.protobuf.util.MoreValues.listValueOf;
import static com.google.mu.protobuf.util.MoreValues.toListValue;
import static org.junit.Assert.assertThrows;
import java.util.List;
import java.util.stream.Stream;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import com.google.common.testing.NullPointerTester;
import com.google.protobuf.ListValue;
import com.google.protobuf.Value;
import com.google.protobuf.util.Structs;
import com.google.protobuf.util.Values;
package com.google.mu.protobuf.util;
@RunWith(JUnit4.class)
public class MoreValuesTest {
@Test public void testToListValue() {
Structor converter = new Structor();
assertThat( | Stream.of(1, "foo", list(true, false), map("k", 20L)).map(converter::toValue).collect(toListValue())) |
google/mug | mug-protobuf/src/test/java/com/google/mu/protobuf/util/MoreValuesTest.java | // Path: mug-guava/src/main/java/com/google/mu/collect/Immutables.java
// public static <E> ImmutableList<E> list() {
// return ImmutableList.of();
// }
//
// Path: mug-guava/src/main/java/com/google/mu/collect/Immutables.java
// public static <K, V> ImmutableMap<K, V> map() {
// return ImmutableMap.of();
// }
//
// Path: mug-protobuf/src/main/java/com/google/mu/protobuf/util/MoreStructs.java
// public static Struct struct(String name, boolean value) {
// return struct(name, valueOf(value));
// }
//
// Path: mug-protobuf/src/main/java/com/google/mu/protobuf/util/MoreValues.java
// public static final Value FALSE = Value.newBuilder().setBoolValue(false).build();
//
// Path: mug-protobuf/src/main/java/com/google/mu/protobuf/util/MoreValues.java
// public static final Value NULL =
// Value.newBuilder().setNullValue(NullValue.NULL_VALUE).build();
//
// Path: mug-protobuf/src/main/java/com/google/mu/protobuf/util/MoreValues.java
// public static final Value TRUE = Value.newBuilder().setBoolValue(true).build();
//
// Path: mug-protobuf/src/main/java/com/google/mu/protobuf/util/MoreValues.java
// public static ListValue listValueOf(double... values) {
// return stream(values).mapToObj(MoreValues::valueOf).collect(toListValue());
// }
//
// Path: mug-protobuf/src/main/java/com/google/mu/protobuf/util/MoreValues.java
// public static Collector<Value, ?, ListValue> toListValue() {
// return Collector.of(
// ListValue::newBuilder,
// ListValue.Builder::addValues,
// (a, b) -> a.addAllValues(b.getValuesList()),
// ListValue.Builder::build);
// }
| import static com.google.common.truth.Truth.assertThat;
import static com.google.mu.collect.Immutables.list;
import static com.google.mu.collect.Immutables.map;
import static com.google.mu.protobuf.util.MoreStructs.struct;
import static com.google.mu.protobuf.util.MoreValues.FALSE;
import static com.google.mu.protobuf.util.MoreValues.NULL;
import static com.google.mu.protobuf.util.MoreValues.TRUE;
import static com.google.mu.protobuf.util.MoreValues.listValueOf;
import static com.google.mu.protobuf.util.MoreValues.toListValue;
import static org.junit.Assert.assertThrows;
import java.util.List;
import java.util.stream.Stream;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import com.google.common.testing.NullPointerTester;
import com.google.protobuf.ListValue;
import com.google.protobuf.Value;
import com.google.protobuf.util.Structs;
import com.google.protobuf.util.Values; | package com.google.mu.protobuf.util;
@RunWith(JUnit4.class)
public class MoreValuesTest {
@Test public void testToListValue() {
Structor converter = new Structor();
assertThat( | // Path: mug-guava/src/main/java/com/google/mu/collect/Immutables.java
// public static <E> ImmutableList<E> list() {
// return ImmutableList.of();
// }
//
// Path: mug-guava/src/main/java/com/google/mu/collect/Immutables.java
// public static <K, V> ImmutableMap<K, V> map() {
// return ImmutableMap.of();
// }
//
// Path: mug-protobuf/src/main/java/com/google/mu/protobuf/util/MoreStructs.java
// public static Struct struct(String name, boolean value) {
// return struct(name, valueOf(value));
// }
//
// Path: mug-protobuf/src/main/java/com/google/mu/protobuf/util/MoreValues.java
// public static final Value FALSE = Value.newBuilder().setBoolValue(false).build();
//
// Path: mug-protobuf/src/main/java/com/google/mu/protobuf/util/MoreValues.java
// public static final Value NULL =
// Value.newBuilder().setNullValue(NullValue.NULL_VALUE).build();
//
// Path: mug-protobuf/src/main/java/com/google/mu/protobuf/util/MoreValues.java
// public static final Value TRUE = Value.newBuilder().setBoolValue(true).build();
//
// Path: mug-protobuf/src/main/java/com/google/mu/protobuf/util/MoreValues.java
// public static ListValue listValueOf(double... values) {
// return stream(values).mapToObj(MoreValues::valueOf).collect(toListValue());
// }
//
// Path: mug-protobuf/src/main/java/com/google/mu/protobuf/util/MoreValues.java
// public static Collector<Value, ?, ListValue> toListValue() {
// return Collector.of(
// ListValue::newBuilder,
// ListValue.Builder::addValues,
// (a, b) -> a.addAllValues(b.getValuesList()),
// ListValue.Builder::build);
// }
// Path: mug-protobuf/src/test/java/com/google/mu/protobuf/util/MoreValuesTest.java
import static com.google.common.truth.Truth.assertThat;
import static com.google.mu.collect.Immutables.list;
import static com.google.mu.collect.Immutables.map;
import static com.google.mu.protobuf.util.MoreStructs.struct;
import static com.google.mu.protobuf.util.MoreValues.FALSE;
import static com.google.mu.protobuf.util.MoreValues.NULL;
import static com.google.mu.protobuf.util.MoreValues.TRUE;
import static com.google.mu.protobuf.util.MoreValues.listValueOf;
import static com.google.mu.protobuf.util.MoreValues.toListValue;
import static org.junit.Assert.assertThrows;
import java.util.List;
import java.util.stream.Stream;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import com.google.common.testing.NullPointerTester;
import com.google.protobuf.ListValue;
import com.google.protobuf.Value;
import com.google.protobuf.util.Structs;
import com.google.protobuf.util.Values;
package com.google.mu.protobuf.util;
@RunWith(JUnit4.class)
public class MoreValuesTest {
@Test public void testToListValue() {
Structor converter = new Structor();
assertThat( | Stream.of(1, "foo", list(true, false), map("k", 20L)).map(converter::toValue).collect(toListValue())) |
google/mug | mug-protobuf/src/test/java/com/google/mu/protobuf/util/MoreValuesTest.java | // Path: mug-guava/src/main/java/com/google/mu/collect/Immutables.java
// public static <E> ImmutableList<E> list() {
// return ImmutableList.of();
// }
//
// Path: mug-guava/src/main/java/com/google/mu/collect/Immutables.java
// public static <K, V> ImmutableMap<K, V> map() {
// return ImmutableMap.of();
// }
//
// Path: mug-protobuf/src/main/java/com/google/mu/protobuf/util/MoreStructs.java
// public static Struct struct(String name, boolean value) {
// return struct(name, valueOf(value));
// }
//
// Path: mug-protobuf/src/main/java/com/google/mu/protobuf/util/MoreValues.java
// public static final Value FALSE = Value.newBuilder().setBoolValue(false).build();
//
// Path: mug-protobuf/src/main/java/com/google/mu/protobuf/util/MoreValues.java
// public static final Value NULL =
// Value.newBuilder().setNullValue(NullValue.NULL_VALUE).build();
//
// Path: mug-protobuf/src/main/java/com/google/mu/protobuf/util/MoreValues.java
// public static final Value TRUE = Value.newBuilder().setBoolValue(true).build();
//
// Path: mug-protobuf/src/main/java/com/google/mu/protobuf/util/MoreValues.java
// public static ListValue listValueOf(double... values) {
// return stream(values).mapToObj(MoreValues::valueOf).collect(toListValue());
// }
//
// Path: mug-protobuf/src/main/java/com/google/mu/protobuf/util/MoreValues.java
// public static Collector<Value, ?, ListValue> toListValue() {
// return Collector.of(
// ListValue::newBuilder,
// ListValue.Builder::addValues,
// (a, b) -> a.addAllValues(b.getValuesList()),
// ListValue.Builder::build);
// }
| import static com.google.common.truth.Truth.assertThat;
import static com.google.mu.collect.Immutables.list;
import static com.google.mu.collect.Immutables.map;
import static com.google.mu.protobuf.util.MoreStructs.struct;
import static com.google.mu.protobuf.util.MoreValues.FALSE;
import static com.google.mu.protobuf.util.MoreValues.NULL;
import static com.google.mu.protobuf.util.MoreValues.TRUE;
import static com.google.mu.protobuf.util.MoreValues.listValueOf;
import static com.google.mu.protobuf.util.MoreValues.toListValue;
import static org.junit.Assert.assertThrows;
import java.util.List;
import java.util.stream.Stream;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import com.google.common.testing.NullPointerTester;
import com.google.protobuf.ListValue;
import com.google.protobuf.Value;
import com.google.protobuf.util.Structs;
import com.google.protobuf.util.Values; | package com.google.mu.protobuf.util;
@RunWith(JUnit4.class)
public class MoreValuesTest {
@Test public void testToListValue() {
Structor converter = new Structor();
assertThat(
Stream.of(1, "foo", list(true, false), map("k", 20L)).map(converter::toValue).collect(toListValue()))
.isEqualTo(
ListValue.newBuilder()
.addValues(Values.of(1))
.addValues(Values.of("foo"))
.addValues(converter.toValue(list(true, false)))
.addValues(converter.toValue(map("k", 20L)))
.build());
}
@Test public void testListValueOfNumbers() { | // Path: mug-guava/src/main/java/com/google/mu/collect/Immutables.java
// public static <E> ImmutableList<E> list() {
// return ImmutableList.of();
// }
//
// Path: mug-guava/src/main/java/com/google/mu/collect/Immutables.java
// public static <K, V> ImmutableMap<K, V> map() {
// return ImmutableMap.of();
// }
//
// Path: mug-protobuf/src/main/java/com/google/mu/protobuf/util/MoreStructs.java
// public static Struct struct(String name, boolean value) {
// return struct(name, valueOf(value));
// }
//
// Path: mug-protobuf/src/main/java/com/google/mu/protobuf/util/MoreValues.java
// public static final Value FALSE = Value.newBuilder().setBoolValue(false).build();
//
// Path: mug-protobuf/src/main/java/com/google/mu/protobuf/util/MoreValues.java
// public static final Value NULL =
// Value.newBuilder().setNullValue(NullValue.NULL_VALUE).build();
//
// Path: mug-protobuf/src/main/java/com/google/mu/protobuf/util/MoreValues.java
// public static final Value TRUE = Value.newBuilder().setBoolValue(true).build();
//
// Path: mug-protobuf/src/main/java/com/google/mu/protobuf/util/MoreValues.java
// public static ListValue listValueOf(double... values) {
// return stream(values).mapToObj(MoreValues::valueOf).collect(toListValue());
// }
//
// Path: mug-protobuf/src/main/java/com/google/mu/protobuf/util/MoreValues.java
// public static Collector<Value, ?, ListValue> toListValue() {
// return Collector.of(
// ListValue::newBuilder,
// ListValue.Builder::addValues,
// (a, b) -> a.addAllValues(b.getValuesList()),
// ListValue.Builder::build);
// }
// Path: mug-protobuf/src/test/java/com/google/mu/protobuf/util/MoreValuesTest.java
import static com.google.common.truth.Truth.assertThat;
import static com.google.mu.collect.Immutables.list;
import static com.google.mu.collect.Immutables.map;
import static com.google.mu.protobuf.util.MoreStructs.struct;
import static com.google.mu.protobuf.util.MoreValues.FALSE;
import static com.google.mu.protobuf.util.MoreValues.NULL;
import static com.google.mu.protobuf.util.MoreValues.TRUE;
import static com.google.mu.protobuf.util.MoreValues.listValueOf;
import static com.google.mu.protobuf.util.MoreValues.toListValue;
import static org.junit.Assert.assertThrows;
import java.util.List;
import java.util.stream.Stream;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import com.google.common.testing.NullPointerTester;
import com.google.protobuf.ListValue;
import com.google.protobuf.Value;
import com.google.protobuf.util.Structs;
import com.google.protobuf.util.Values;
package com.google.mu.protobuf.util;
@RunWith(JUnit4.class)
public class MoreValuesTest {
@Test public void testToListValue() {
Structor converter = new Structor();
assertThat(
Stream.of(1, "foo", list(true, false), map("k", 20L)).map(converter::toValue).collect(toListValue()))
.isEqualTo(
ListValue.newBuilder()
.addValues(Values.of(1))
.addValues(Values.of("foo"))
.addValues(converter.toValue(list(true, false)))
.addValues(converter.toValue(map("k", 20L)))
.build());
}
@Test public void testListValueOfNumbers() { | assertThat(listValueOf(1, 2)) |
google/mug | mug-protobuf/src/test/java/com/google/mu/protobuf/util/MoreValuesTest.java | // Path: mug-guava/src/main/java/com/google/mu/collect/Immutables.java
// public static <E> ImmutableList<E> list() {
// return ImmutableList.of();
// }
//
// Path: mug-guava/src/main/java/com/google/mu/collect/Immutables.java
// public static <K, V> ImmutableMap<K, V> map() {
// return ImmutableMap.of();
// }
//
// Path: mug-protobuf/src/main/java/com/google/mu/protobuf/util/MoreStructs.java
// public static Struct struct(String name, boolean value) {
// return struct(name, valueOf(value));
// }
//
// Path: mug-protobuf/src/main/java/com/google/mu/protobuf/util/MoreValues.java
// public static final Value FALSE = Value.newBuilder().setBoolValue(false).build();
//
// Path: mug-protobuf/src/main/java/com/google/mu/protobuf/util/MoreValues.java
// public static final Value NULL =
// Value.newBuilder().setNullValue(NullValue.NULL_VALUE).build();
//
// Path: mug-protobuf/src/main/java/com/google/mu/protobuf/util/MoreValues.java
// public static final Value TRUE = Value.newBuilder().setBoolValue(true).build();
//
// Path: mug-protobuf/src/main/java/com/google/mu/protobuf/util/MoreValues.java
// public static ListValue listValueOf(double... values) {
// return stream(values).mapToObj(MoreValues::valueOf).collect(toListValue());
// }
//
// Path: mug-protobuf/src/main/java/com/google/mu/protobuf/util/MoreValues.java
// public static Collector<Value, ?, ListValue> toListValue() {
// return Collector.of(
// ListValue::newBuilder,
// ListValue.Builder::addValues,
// (a, b) -> a.addAllValues(b.getValuesList()),
// ListValue.Builder::build);
// }
| import static com.google.common.truth.Truth.assertThat;
import static com.google.mu.collect.Immutables.list;
import static com.google.mu.collect.Immutables.map;
import static com.google.mu.protobuf.util.MoreStructs.struct;
import static com.google.mu.protobuf.util.MoreValues.FALSE;
import static com.google.mu.protobuf.util.MoreValues.NULL;
import static com.google.mu.protobuf.util.MoreValues.TRUE;
import static com.google.mu.protobuf.util.MoreValues.listValueOf;
import static com.google.mu.protobuf.util.MoreValues.toListValue;
import static org.junit.Assert.assertThrows;
import java.util.List;
import java.util.stream.Stream;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import com.google.common.testing.NullPointerTester;
import com.google.protobuf.ListValue;
import com.google.protobuf.Value;
import com.google.protobuf.util.Structs;
import com.google.protobuf.util.Values; | package com.google.mu.protobuf.util;
@RunWith(JUnit4.class)
public class MoreValuesTest {
@Test public void testToListValue() {
Structor converter = new Structor();
assertThat(
Stream.of(1, "foo", list(true, false), map("k", 20L)).map(converter::toValue).collect(toListValue()))
.isEqualTo(
ListValue.newBuilder()
.addValues(Values.of(1))
.addValues(Values.of("foo"))
.addValues(converter.toValue(list(true, false)))
.addValues(converter.toValue(map("k", 20L)))
.build());
}
@Test public void testListValueOfNumbers() {
assertThat(listValueOf(1, 2))
.isEqualTo(
ListValue.newBuilder()
.addValues(Values.of(1))
.addValues(Values.of(2))
.build());
}
@Test public void testListValueOfStrings() {
assertThat(listValueOf("foo", "bar", null))
.isEqualTo(
ListValue.newBuilder()
.addValues(Values.of("foo"))
.addValues(Values.of("bar")) | // Path: mug-guava/src/main/java/com/google/mu/collect/Immutables.java
// public static <E> ImmutableList<E> list() {
// return ImmutableList.of();
// }
//
// Path: mug-guava/src/main/java/com/google/mu/collect/Immutables.java
// public static <K, V> ImmutableMap<K, V> map() {
// return ImmutableMap.of();
// }
//
// Path: mug-protobuf/src/main/java/com/google/mu/protobuf/util/MoreStructs.java
// public static Struct struct(String name, boolean value) {
// return struct(name, valueOf(value));
// }
//
// Path: mug-protobuf/src/main/java/com/google/mu/protobuf/util/MoreValues.java
// public static final Value FALSE = Value.newBuilder().setBoolValue(false).build();
//
// Path: mug-protobuf/src/main/java/com/google/mu/protobuf/util/MoreValues.java
// public static final Value NULL =
// Value.newBuilder().setNullValue(NullValue.NULL_VALUE).build();
//
// Path: mug-protobuf/src/main/java/com/google/mu/protobuf/util/MoreValues.java
// public static final Value TRUE = Value.newBuilder().setBoolValue(true).build();
//
// Path: mug-protobuf/src/main/java/com/google/mu/protobuf/util/MoreValues.java
// public static ListValue listValueOf(double... values) {
// return stream(values).mapToObj(MoreValues::valueOf).collect(toListValue());
// }
//
// Path: mug-protobuf/src/main/java/com/google/mu/protobuf/util/MoreValues.java
// public static Collector<Value, ?, ListValue> toListValue() {
// return Collector.of(
// ListValue::newBuilder,
// ListValue.Builder::addValues,
// (a, b) -> a.addAllValues(b.getValuesList()),
// ListValue.Builder::build);
// }
// Path: mug-protobuf/src/test/java/com/google/mu/protobuf/util/MoreValuesTest.java
import static com.google.common.truth.Truth.assertThat;
import static com.google.mu.collect.Immutables.list;
import static com.google.mu.collect.Immutables.map;
import static com.google.mu.protobuf.util.MoreStructs.struct;
import static com.google.mu.protobuf.util.MoreValues.FALSE;
import static com.google.mu.protobuf.util.MoreValues.NULL;
import static com.google.mu.protobuf.util.MoreValues.TRUE;
import static com.google.mu.protobuf.util.MoreValues.listValueOf;
import static com.google.mu.protobuf.util.MoreValues.toListValue;
import static org.junit.Assert.assertThrows;
import java.util.List;
import java.util.stream.Stream;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import com.google.common.testing.NullPointerTester;
import com.google.protobuf.ListValue;
import com.google.protobuf.Value;
import com.google.protobuf.util.Structs;
import com.google.protobuf.util.Values;
package com.google.mu.protobuf.util;
@RunWith(JUnit4.class)
public class MoreValuesTest {
@Test public void testToListValue() {
Structor converter = new Structor();
assertThat(
Stream.of(1, "foo", list(true, false), map("k", 20L)).map(converter::toValue).collect(toListValue()))
.isEqualTo(
ListValue.newBuilder()
.addValues(Values.of(1))
.addValues(Values.of("foo"))
.addValues(converter.toValue(list(true, false)))
.addValues(converter.toValue(map("k", 20L)))
.build());
}
@Test public void testListValueOfNumbers() {
assertThat(listValueOf(1, 2))
.isEqualTo(
ListValue.newBuilder()
.addValues(Values.of(1))
.addValues(Values.of(2))
.build());
}
@Test public void testListValueOfStrings() {
assertThat(listValueOf("foo", "bar", null))
.isEqualTo(
ListValue.newBuilder()
.addValues(Values.of("foo"))
.addValues(Values.of("bar")) | .addValues(NULL) |
google/mug | mug-protobuf/src/test/java/com/google/mu/protobuf/util/MoreValuesTest.java | // Path: mug-guava/src/main/java/com/google/mu/collect/Immutables.java
// public static <E> ImmutableList<E> list() {
// return ImmutableList.of();
// }
//
// Path: mug-guava/src/main/java/com/google/mu/collect/Immutables.java
// public static <K, V> ImmutableMap<K, V> map() {
// return ImmutableMap.of();
// }
//
// Path: mug-protobuf/src/main/java/com/google/mu/protobuf/util/MoreStructs.java
// public static Struct struct(String name, boolean value) {
// return struct(name, valueOf(value));
// }
//
// Path: mug-protobuf/src/main/java/com/google/mu/protobuf/util/MoreValues.java
// public static final Value FALSE = Value.newBuilder().setBoolValue(false).build();
//
// Path: mug-protobuf/src/main/java/com/google/mu/protobuf/util/MoreValues.java
// public static final Value NULL =
// Value.newBuilder().setNullValue(NullValue.NULL_VALUE).build();
//
// Path: mug-protobuf/src/main/java/com/google/mu/protobuf/util/MoreValues.java
// public static final Value TRUE = Value.newBuilder().setBoolValue(true).build();
//
// Path: mug-protobuf/src/main/java/com/google/mu/protobuf/util/MoreValues.java
// public static ListValue listValueOf(double... values) {
// return stream(values).mapToObj(MoreValues::valueOf).collect(toListValue());
// }
//
// Path: mug-protobuf/src/main/java/com/google/mu/protobuf/util/MoreValues.java
// public static Collector<Value, ?, ListValue> toListValue() {
// return Collector.of(
// ListValue::newBuilder,
// ListValue.Builder::addValues,
// (a, b) -> a.addAllValues(b.getValuesList()),
// ListValue.Builder::build);
// }
| import static com.google.common.truth.Truth.assertThat;
import static com.google.mu.collect.Immutables.list;
import static com.google.mu.collect.Immutables.map;
import static com.google.mu.protobuf.util.MoreStructs.struct;
import static com.google.mu.protobuf.util.MoreValues.FALSE;
import static com.google.mu.protobuf.util.MoreValues.NULL;
import static com.google.mu.protobuf.util.MoreValues.TRUE;
import static com.google.mu.protobuf.util.MoreValues.listValueOf;
import static com.google.mu.protobuf.util.MoreValues.toListValue;
import static org.junit.Assert.assertThrows;
import java.util.List;
import java.util.stream.Stream;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import com.google.common.testing.NullPointerTester;
import com.google.protobuf.ListValue;
import com.google.protobuf.Value;
import com.google.protobuf.util.Structs;
import com.google.protobuf.util.Values; | Stream.of(1, "foo", list(true, false), map("k", 20L)).map(converter::toValue).collect(toListValue()))
.isEqualTo(
ListValue.newBuilder()
.addValues(Values.of(1))
.addValues(Values.of("foo"))
.addValues(converter.toValue(list(true, false)))
.addValues(converter.toValue(map("k", 20L)))
.build());
}
@Test public void testListValueOfNumbers() {
assertThat(listValueOf(1, 2))
.isEqualTo(
ListValue.newBuilder()
.addValues(Values.of(1))
.addValues(Values.of(2))
.build());
}
@Test public void testListValueOfStrings() {
assertThat(listValueOf("foo", "bar", null))
.isEqualTo(
ListValue.newBuilder()
.addValues(Values.of("foo"))
.addValues(Values.of("bar"))
.addValues(NULL)
.build());
}
@Test public void testListValueOfStructs() { | // Path: mug-guava/src/main/java/com/google/mu/collect/Immutables.java
// public static <E> ImmutableList<E> list() {
// return ImmutableList.of();
// }
//
// Path: mug-guava/src/main/java/com/google/mu/collect/Immutables.java
// public static <K, V> ImmutableMap<K, V> map() {
// return ImmutableMap.of();
// }
//
// Path: mug-protobuf/src/main/java/com/google/mu/protobuf/util/MoreStructs.java
// public static Struct struct(String name, boolean value) {
// return struct(name, valueOf(value));
// }
//
// Path: mug-protobuf/src/main/java/com/google/mu/protobuf/util/MoreValues.java
// public static final Value FALSE = Value.newBuilder().setBoolValue(false).build();
//
// Path: mug-protobuf/src/main/java/com/google/mu/protobuf/util/MoreValues.java
// public static final Value NULL =
// Value.newBuilder().setNullValue(NullValue.NULL_VALUE).build();
//
// Path: mug-protobuf/src/main/java/com/google/mu/protobuf/util/MoreValues.java
// public static final Value TRUE = Value.newBuilder().setBoolValue(true).build();
//
// Path: mug-protobuf/src/main/java/com/google/mu/protobuf/util/MoreValues.java
// public static ListValue listValueOf(double... values) {
// return stream(values).mapToObj(MoreValues::valueOf).collect(toListValue());
// }
//
// Path: mug-protobuf/src/main/java/com/google/mu/protobuf/util/MoreValues.java
// public static Collector<Value, ?, ListValue> toListValue() {
// return Collector.of(
// ListValue::newBuilder,
// ListValue.Builder::addValues,
// (a, b) -> a.addAllValues(b.getValuesList()),
// ListValue.Builder::build);
// }
// Path: mug-protobuf/src/test/java/com/google/mu/protobuf/util/MoreValuesTest.java
import static com.google.common.truth.Truth.assertThat;
import static com.google.mu.collect.Immutables.list;
import static com.google.mu.collect.Immutables.map;
import static com.google.mu.protobuf.util.MoreStructs.struct;
import static com.google.mu.protobuf.util.MoreValues.FALSE;
import static com.google.mu.protobuf.util.MoreValues.NULL;
import static com.google.mu.protobuf.util.MoreValues.TRUE;
import static com.google.mu.protobuf.util.MoreValues.listValueOf;
import static com.google.mu.protobuf.util.MoreValues.toListValue;
import static org.junit.Assert.assertThrows;
import java.util.List;
import java.util.stream.Stream;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import com.google.common.testing.NullPointerTester;
import com.google.protobuf.ListValue;
import com.google.protobuf.Value;
import com.google.protobuf.util.Structs;
import com.google.protobuf.util.Values;
Stream.of(1, "foo", list(true, false), map("k", 20L)).map(converter::toValue).collect(toListValue()))
.isEqualTo(
ListValue.newBuilder()
.addValues(Values.of(1))
.addValues(Values.of("foo"))
.addValues(converter.toValue(list(true, false)))
.addValues(converter.toValue(map("k", 20L)))
.build());
}
@Test public void testListValueOfNumbers() {
assertThat(listValueOf(1, 2))
.isEqualTo(
ListValue.newBuilder()
.addValues(Values.of(1))
.addValues(Values.of(2))
.build());
}
@Test public void testListValueOfStrings() {
assertThat(listValueOf("foo", "bar", null))
.isEqualTo(
ListValue.newBuilder()
.addValues(Values.of("foo"))
.addValues(Values.of("bar"))
.addValues(NULL)
.build());
}
@Test public void testListValueOfStructs() { | assertThat(listValueOf(struct("foo", 1), null, struct("bar", 2))) |
google/mug | mug-protobuf/src/test/java/com/google/mu/protobuf/util/MoreValuesTest.java | // Path: mug-guava/src/main/java/com/google/mu/collect/Immutables.java
// public static <E> ImmutableList<E> list() {
// return ImmutableList.of();
// }
//
// Path: mug-guava/src/main/java/com/google/mu/collect/Immutables.java
// public static <K, V> ImmutableMap<K, V> map() {
// return ImmutableMap.of();
// }
//
// Path: mug-protobuf/src/main/java/com/google/mu/protobuf/util/MoreStructs.java
// public static Struct struct(String name, boolean value) {
// return struct(name, valueOf(value));
// }
//
// Path: mug-protobuf/src/main/java/com/google/mu/protobuf/util/MoreValues.java
// public static final Value FALSE = Value.newBuilder().setBoolValue(false).build();
//
// Path: mug-protobuf/src/main/java/com/google/mu/protobuf/util/MoreValues.java
// public static final Value NULL =
// Value.newBuilder().setNullValue(NullValue.NULL_VALUE).build();
//
// Path: mug-protobuf/src/main/java/com/google/mu/protobuf/util/MoreValues.java
// public static final Value TRUE = Value.newBuilder().setBoolValue(true).build();
//
// Path: mug-protobuf/src/main/java/com/google/mu/protobuf/util/MoreValues.java
// public static ListValue listValueOf(double... values) {
// return stream(values).mapToObj(MoreValues::valueOf).collect(toListValue());
// }
//
// Path: mug-protobuf/src/main/java/com/google/mu/protobuf/util/MoreValues.java
// public static Collector<Value, ?, ListValue> toListValue() {
// return Collector.of(
// ListValue::newBuilder,
// ListValue.Builder::addValues,
// (a, b) -> a.addAllValues(b.getValuesList()),
// ListValue.Builder::build);
// }
| import static com.google.common.truth.Truth.assertThat;
import static com.google.mu.collect.Immutables.list;
import static com.google.mu.collect.Immutables.map;
import static com.google.mu.protobuf.util.MoreStructs.struct;
import static com.google.mu.protobuf.util.MoreValues.FALSE;
import static com.google.mu.protobuf.util.MoreValues.NULL;
import static com.google.mu.protobuf.util.MoreValues.TRUE;
import static com.google.mu.protobuf.util.MoreValues.listValueOf;
import static com.google.mu.protobuf.util.MoreValues.toListValue;
import static org.junit.Assert.assertThrows;
import java.util.List;
import java.util.stream.Stream;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import com.google.common.testing.NullPointerTester;
import com.google.protobuf.ListValue;
import com.google.protobuf.Value;
import com.google.protobuf.util.Structs;
import com.google.protobuf.util.Values; | assertThat(MoreValues.nullableValueOf("abc")).isEqualTo(Values.of("abc"));
}
@Test public void testlist() {
assertThat(MoreValues.asList(listValueOf(1, Long.MAX_VALUE, Long.MIN_VALUE)))
.containsExactly(1, Long.MAX_VALUE, Long.MIN_VALUE)
.inOrder();
}
@Test public void testlist_withNullElement() {
assertThat(MoreValues.asList(ListValue.newBuilder().addValues(NULL)))
.containsExactly((Object) null)
.inOrder();
}
@Test public void testlist_fromBuilder_mutation() {
ListValue.Builder builder = ListValue.newBuilder().addValues(Values.of("foo"));
List<Object> list = MoreValues.asList(builder);
builder.addValues(Values.of(2));
assertThat(list)
.containsExactly("foo", 2)
.inOrder();
}
@Test public void testFromValue_null() {
assertThat(MoreValues.fromValue(NULL)).isNull();
assertThat(MoreValues.fromValue(NULL.toBuilder())).isNull();
}
@Test public void testFromValue_boolean() { | // Path: mug-guava/src/main/java/com/google/mu/collect/Immutables.java
// public static <E> ImmutableList<E> list() {
// return ImmutableList.of();
// }
//
// Path: mug-guava/src/main/java/com/google/mu/collect/Immutables.java
// public static <K, V> ImmutableMap<K, V> map() {
// return ImmutableMap.of();
// }
//
// Path: mug-protobuf/src/main/java/com/google/mu/protobuf/util/MoreStructs.java
// public static Struct struct(String name, boolean value) {
// return struct(name, valueOf(value));
// }
//
// Path: mug-protobuf/src/main/java/com/google/mu/protobuf/util/MoreValues.java
// public static final Value FALSE = Value.newBuilder().setBoolValue(false).build();
//
// Path: mug-protobuf/src/main/java/com/google/mu/protobuf/util/MoreValues.java
// public static final Value NULL =
// Value.newBuilder().setNullValue(NullValue.NULL_VALUE).build();
//
// Path: mug-protobuf/src/main/java/com/google/mu/protobuf/util/MoreValues.java
// public static final Value TRUE = Value.newBuilder().setBoolValue(true).build();
//
// Path: mug-protobuf/src/main/java/com/google/mu/protobuf/util/MoreValues.java
// public static ListValue listValueOf(double... values) {
// return stream(values).mapToObj(MoreValues::valueOf).collect(toListValue());
// }
//
// Path: mug-protobuf/src/main/java/com/google/mu/protobuf/util/MoreValues.java
// public static Collector<Value, ?, ListValue> toListValue() {
// return Collector.of(
// ListValue::newBuilder,
// ListValue.Builder::addValues,
// (a, b) -> a.addAllValues(b.getValuesList()),
// ListValue.Builder::build);
// }
// Path: mug-protobuf/src/test/java/com/google/mu/protobuf/util/MoreValuesTest.java
import static com.google.common.truth.Truth.assertThat;
import static com.google.mu.collect.Immutables.list;
import static com.google.mu.collect.Immutables.map;
import static com.google.mu.protobuf.util.MoreStructs.struct;
import static com.google.mu.protobuf.util.MoreValues.FALSE;
import static com.google.mu.protobuf.util.MoreValues.NULL;
import static com.google.mu.protobuf.util.MoreValues.TRUE;
import static com.google.mu.protobuf.util.MoreValues.listValueOf;
import static com.google.mu.protobuf.util.MoreValues.toListValue;
import static org.junit.Assert.assertThrows;
import java.util.List;
import java.util.stream.Stream;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import com.google.common.testing.NullPointerTester;
import com.google.protobuf.ListValue;
import com.google.protobuf.Value;
import com.google.protobuf.util.Structs;
import com.google.protobuf.util.Values;
assertThat(MoreValues.nullableValueOf("abc")).isEqualTo(Values.of("abc"));
}
@Test public void testlist() {
assertThat(MoreValues.asList(listValueOf(1, Long.MAX_VALUE, Long.MIN_VALUE)))
.containsExactly(1, Long.MAX_VALUE, Long.MIN_VALUE)
.inOrder();
}
@Test public void testlist_withNullElement() {
assertThat(MoreValues.asList(ListValue.newBuilder().addValues(NULL)))
.containsExactly((Object) null)
.inOrder();
}
@Test public void testlist_fromBuilder_mutation() {
ListValue.Builder builder = ListValue.newBuilder().addValues(Values.of("foo"));
List<Object> list = MoreValues.asList(builder);
builder.addValues(Values.of(2));
assertThat(list)
.containsExactly("foo", 2)
.inOrder();
}
@Test public void testFromValue_null() {
assertThat(MoreValues.fromValue(NULL)).isNull();
assertThat(MoreValues.fromValue(NULL.toBuilder())).isNull();
}
@Test public void testFromValue_boolean() { | assertThat(MoreValues.fromValue(TRUE)).isEqualTo(true); |
google/mug | mug-protobuf/src/test/java/com/google/mu/protobuf/util/MoreValuesTest.java | // Path: mug-guava/src/main/java/com/google/mu/collect/Immutables.java
// public static <E> ImmutableList<E> list() {
// return ImmutableList.of();
// }
//
// Path: mug-guava/src/main/java/com/google/mu/collect/Immutables.java
// public static <K, V> ImmutableMap<K, V> map() {
// return ImmutableMap.of();
// }
//
// Path: mug-protobuf/src/main/java/com/google/mu/protobuf/util/MoreStructs.java
// public static Struct struct(String name, boolean value) {
// return struct(name, valueOf(value));
// }
//
// Path: mug-protobuf/src/main/java/com/google/mu/protobuf/util/MoreValues.java
// public static final Value FALSE = Value.newBuilder().setBoolValue(false).build();
//
// Path: mug-protobuf/src/main/java/com/google/mu/protobuf/util/MoreValues.java
// public static final Value NULL =
// Value.newBuilder().setNullValue(NullValue.NULL_VALUE).build();
//
// Path: mug-protobuf/src/main/java/com/google/mu/protobuf/util/MoreValues.java
// public static final Value TRUE = Value.newBuilder().setBoolValue(true).build();
//
// Path: mug-protobuf/src/main/java/com/google/mu/protobuf/util/MoreValues.java
// public static ListValue listValueOf(double... values) {
// return stream(values).mapToObj(MoreValues::valueOf).collect(toListValue());
// }
//
// Path: mug-protobuf/src/main/java/com/google/mu/protobuf/util/MoreValues.java
// public static Collector<Value, ?, ListValue> toListValue() {
// return Collector.of(
// ListValue::newBuilder,
// ListValue.Builder::addValues,
// (a, b) -> a.addAllValues(b.getValuesList()),
// ListValue.Builder::build);
// }
| import static com.google.common.truth.Truth.assertThat;
import static com.google.mu.collect.Immutables.list;
import static com.google.mu.collect.Immutables.map;
import static com.google.mu.protobuf.util.MoreStructs.struct;
import static com.google.mu.protobuf.util.MoreValues.FALSE;
import static com.google.mu.protobuf.util.MoreValues.NULL;
import static com.google.mu.protobuf.util.MoreValues.TRUE;
import static com.google.mu.protobuf.util.MoreValues.listValueOf;
import static com.google.mu.protobuf.util.MoreValues.toListValue;
import static org.junit.Assert.assertThrows;
import java.util.List;
import java.util.stream.Stream;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import com.google.common.testing.NullPointerTester;
import com.google.protobuf.ListValue;
import com.google.protobuf.Value;
import com.google.protobuf.util.Structs;
import com.google.protobuf.util.Values; |
@Test public void testlist() {
assertThat(MoreValues.asList(listValueOf(1, Long.MAX_VALUE, Long.MIN_VALUE)))
.containsExactly(1, Long.MAX_VALUE, Long.MIN_VALUE)
.inOrder();
}
@Test public void testlist_withNullElement() {
assertThat(MoreValues.asList(ListValue.newBuilder().addValues(NULL)))
.containsExactly((Object) null)
.inOrder();
}
@Test public void testlist_fromBuilder_mutation() {
ListValue.Builder builder = ListValue.newBuilder().addValues(Values.of("foo"));
List<Object> list = MoreValues.asList(builder);
builder.addValues(Values.of(2));
assertThat(list)
.containsExactly("foo", 2)
.inOrder();
}
@Test public void testFromValue_null() {
assertThat(MoreValues.fromValue(NULL)).isNull();
assertThat(MoreValues.fromValue(NULL.toBuilder())).isNull();
}
@Test public void testFromValue_boolean() {
assertThat(MoreValues.fromValue(TRUE)).isEqualTo(true);
assertThat(MoreValues.fromValue(TRUE.toBuilder())).isEqualTo(true); | // Path: mug-guava/src/main/java/com/google/mu/collect/Immutables.java
// public static <E> ImmutableList<E> list() {
// return ImmutableList.of();
// }
//
// Path: mug-guava/src/main/java/com/google/mu/collect/Immutables.java
// public static <K, V> ImmutableMap<K, V> map() {
// return ImmutableMap.of();
// }
//
// Path: mug-protobuf/src/main/java/com/google/mu/protobuf/util/MoreStructs.java
// public static Struct struct(String name, boolean value) {
// return struct(name, valueOf(value));
// }
//
// Path: mug-protobuf/src/main/java/com/google/mu/protobuf/util/MoreValues.java
// public static final Value FALSE = Value.newBuilder().setBoolValue(false).build();
//
// Path: mug-protobuf/src/main/java/com/google/mu/protobuf/util/MoreValues.java
// public static final Value NULL =
// Value.newBuilder().setNullValue(NullValue.NULL_VALUE).build();
//
// Path: mug-protobuf/src/main/java/com/google/mu/protobuf/util/MoreValues.java
// public static final Value TRUE = Value.newBuilder().setBoolValue(true).build();
//
// Path: mug-protobuf/src/main/java/com/google/mu/protobuf/util/MoreValues.java
// public static ListValue listValueOf(double... values) {
// return stream(values).mapToObj(MoreValues::valueOf).collect(toListValue());
// }
//
// Path: mug-protobuf/src/main/java/com/google/mu/protobuf/util/MoreValues.java
// public static Collector<Value, ?, ListValue> toListValue() {
// return Collector.of(
// ListValue::newBuilder,
// ListValue.Builder::addValues,
// (a, b) -> a.addAllValues(b.getValuesList()),
// ListValue.Builder::build);
// }
// Path: mug-protobuf/src/test/java/com/google/mu/protobuf/util/MoreValuesTest.java
import static com.google.common.truth.Truth.assertThat;
import static com.google.mu.collect.Immutables.list;
import static com.google.mu.collect.Immutables.map;
import static com.google.mu.protobuf.util.MoreStructs.struct;
import static com.google.mu.protobuf.util.MoreValues.FALSE;
import static com.google.mu.protobuf.util.MoreValues.NULL;
import static com.google.mu.protobuf.util.MoreValues.TRUE;
import static com.google.mu.protobuf.util.MoreValues.listValueOf;
import static com.google.mu.protobuf.util.MoreValues.toListValue;
import static org.junit.Assert.assertThrows;
import java.util.List;
import java.util.stream.Stream;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import com.google.common.testing.NullPointerTester;
import com.google.protobuf.ListValue;
import com.google.protobuf.Value;
import com.google.protobuf.util.Structs;
import com.google.protobuf.util.Values;
@Test public void testlist() {
assertThat(MoreValues.asList(listValueOf(1, Long.MAX_VALUE, Long.MIN_VALUE)))
.containsExactly(1, Long.MAX_VALUE, Long.MIN_VALUE)
.inOrder();
}
@Test public void testlist_withNullElement() {
assertThat(MoreValues.asList(ListValue.newBuilder().addValues(NULL)))
.containsExactly((Object) null)
.inOrder();
}
@Test public void testlist_fromBuilder_mutation() {
ListValue.Builder builder = ListValue.newBuilder().addValues(Values.of("foo"));
List<Object> list = MoreValues.asList(builder);
builder.addValues(Values.of(2));
assertThat(list)
.containsExactly("foo", 2)
.inOrder();
}
@Test public void testFromValue_null() {
assertThat(MoreValues.fromValue(NULL)).isNull();
assertThat(MoreValues.fromValue(NULL.toBuilder())).isNull();
}
@Test public void testFromValue_boolean() {
assertThat(MoreValues.fromValue(TRUE)).isEqualTo(true);
assertThat(MoreValues.fromValue(TRUE.toBuilder())).isEqualTo(true); | assertThat(MoreValues.fromValue(FALSE)).isEqualTo(false); |
google/mug | mug-guava/src/main/java/com/google/mu/util/stream/GuavaCollectors.java | // Path: mug/src/main/java/com/google/mu/util/stream/MoreCollectors.java
// public static <T, A, B, R> Collector<T, ?, R> mapping(
// Function<? super T, ? extends Both<? extends A, ? extends B>> mapper,
// BiCollector<A, B, R> downstream) {
// return Collectors.mapping(
// requireNonNull(mapper), downstream.splitting(BiStream::left, BiStream::right));
// }
//
// Path: mug/src/main/java/com/google/mu/util/Both.java
// @FunctionalInterface
// public interface Both<A, B> {
// /**
// * Returns an instance with both {@code a} and {@code b}.
// *
// * @since 5.8
// */
// public static <A, B> Both<A, B> of(A a, B b) {
// return new BiOptional.Present<>(a, b);
// }
//
// /**
// * Applies the {@code mapper} function with this pair of two things as arguments.
// *
// * @throws NullPointerException if {@code mapper} is null
// */
// <T> T andThen(BiFunction<? super A, ? super B, T> mapper);
//
// /**
// * If the pair {@link #matches matches()} {@code condition}, returns a {@link BiOptional} containing
// * the pair, or else returns empty.
// *
// * @throws NullPointerException if {@code condition} is null, or if {@code condition} matches but
// * either value in this pair is null
// */
// default BiOptional<A, B> filter(BiPredicate<? super A, ? super B> condition) {
// requireNonNull(condition);
// return andThen((a, b) -> condition.test(a, b) ? BiOptional.of(a, b) : BiOptional.empty());
// }
//
// /**
// * Returns true if the pair matches {@code condition}.
// *
// * @throws NullPointerException if {@code condition} is null
// */
// default boolean matches(BiPredicate<? super A, ? super B> condition) {
// return andThen(condition::test);
// }
//
// /**
// * Invokes {@code consumer} with this pair and returns this object as is.
// *
// * @throws NullPointerException if {@code consumer} is null
// */
// default Both<A, B> peek(BiConsumer<? super A, ? super B> consumer) {
// requireNonNull(consumer);
// return andThen((a, b) -> {
// consumer.accept(a, b);
// return this;
// });
// }
// }
| import static com.google.common.collect.ImmutableList.toImmutableList;
import static com.google.mu.util.stream.MoreCollectors.mapping;
import static java.util.Objects.requireNonNull;
import static java.util.function.Function.identity;
import java.util.Comparator;
import java.util.function.BinaryOperator;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.function.Supplier;
import java.util.function.ToIntFunction;
import java.util.stream.Collector;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import com.google.common.collect.ImmutableBiMap;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableListMultimap;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableMultiset;
import com.google.common.collect.ImmutableSetMultimap;
import com.google.common.collect.ImmutableSortedMap;
import com.google.common.collect.ImmutableTable;
import com.google.common.collect.Multimap;
import com.google.common.collect.Multimaps;
import com.google.common.collect.Multiset;
import com.google.common.collect.Tables;
import com.google.mu.util.Both; | * Multimap<Address, PhoneNumber> phoneBook = ...;
* ImmutableTable<State, City, ImmutableSet<PhoneNumber>> phoneNumbersByLocation =
* BiStream.from(phoneBook)
* .collect(groupingBy(Address::state, groupingBy(Address::city, toImmutableSet())))
* .collect(toImmutableTable());
* }</pre>
*
* <p>Cells are collected in encounter order.
*
* <p>The returned {@code BiCollector} is not optimized for parallel reduction.
*/
public static <R, C, V>
BiCollector<R, BiStream<? extends C, ? extends V>, ImmutableTable<R, C, V>>
toImmutableTable() {
return BiCollectors.flatMapping(
(R r, BiStream<? extends C, ? extends V> columns) ->
columns.mapToObj((c, v) -> Tables.immutableCell(r, c, v)),
Collector.of(
ImmutableTable.Builder<R, C, V>::new,
ImmutableTable.Builder::put,
(builder, that) -> builder.putAll(that.build()),
ImmutableTable.Builder::build));
}
/**
* Returns a collector that first maps each input into a key-value pair, and then collects them
* into a {@link ImmutableMap}.
*
* @since 5.1
*/
public static <T, K, V> Collector<T, ?, ImmutableMap<K, V>> toImmutableMap( | // Path: mug/src/main/java/com/google/mu/util/stream/MoreCollectors.java
// public static <T, A, B, R> Collector<T, ?, R> mapping(
// Function<? super T, ? extends Both<? extends A, ? extends B>> mapper,
// BiCollector<A, B, R> downstream) {
// return Collectors.mapping(
// requireNonNull(mapper), downstream.splitting(BiStream::left, BiStream::right));
// }
//
// Path: mug/src/main/java/com/google/mu/util/Both.java
// @FunctionalInterface
// public interface Both<A, B> {
// /**
// * Returns an instance with both {@code a} and {@code b}.
// *
// * @since 5.8
// */
// public static <A, B> Both<A, B> of(A a, B b) {
// return new BiOptional.Present<>(a, b);
// }
//
// /**
// * Applies the {@code mapper} function with this pair of two things as arguments.
// *
// * @throws NullPointerException if {@code mapper} is null
// */
// <T> T andThen(BiFunction<? super A, ? super B, T> mapper);
//
// /**
// * If the pair {@link #matches matches()} {@code condition}, returns a {@link BiOptional} containing
// * the pair, or else returns empty.
// *
// * @throws NullPointerException if {@code condition} is null, or if {@code condition} matches but
// * either value in this pair is null
// */
// default BiOptional<A, B> filter(BiPredicate<? super A, ? super B> condition) {
// requireNonNull(condition);
// return andThen((a, b) -> condition.test(a, b) ? BiOptional.of(a, b) : BiOptional.empty());
// }
//
// /**
// * Returns true if the pair matches {@code condition}.
// *
// * @throws NullPointerException if {@code condition} is null
// */
// default boolean matches(BiPredicate<? super A, ? super B> condition) {
// return andThen(condition::test);
// }
//
// /**
// * Invokes {@code consumer} with this pair and returns this object as is.
// *
// * @throws NullPointerException if {@code consumer} is null
// */
// default Both<A, B> peek(BiConsumer<? super A, ? super B> consumer) {
// requireNonNull(consumer);
// return andThen((a, b) -> {
// consumer.accept(a, b);
// return this;
// });
// }
// }
// Path: mug-guava/src/main/java/com/google/mu/util/stream/GuavaCollectors.java
import static com.google.common.collect.ImmutableList.toImmutableList;
import static com.google.mu.util.stream.MoreCollectors.mapping;
import static java.util.Objects.requireNonNull;
import static java.util.function.Function.identity;
import java.util.Comparator;
import java.util.function.BinaryOperator;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.function.Supplier;
import java.util.function.ToIntFunction;
import java.util.stream.Collector;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import com.google.common.collect.ImmutableBiMap;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableListMultimap;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableMultiset;
import com.google.common.collect.ImmutableSetMultimap;
import com.google.common.collect.ImmutableSortedMap;
import com.google.common.collect.ImmutableTable;
import com.google.common.collect.Multimap;
import com.google.common.collect.Multimaps;
import com.google.common.collect.Multiset;
import com.google.common.collect.Tables;
import com.google.mu.util.Both;
* Multimap<Address, PhoneNumber> phoneBook = ...;
* ImmutableTable<State, City, ImmutableSet<PhoneNumber>> phoneNumbersByLocation =
* BiStream.from(phoneBook)
* .collect(groupingBy(Address::state, groupingBy(Address::city, toImmutableSet())))
* .collect(toImmutableTable());
* }</pre>
*
* <p>Cells are collected in encounter order.
*
* <p>The returned {@code BiCollector} is not optimized for parallel reduction.
*/
public static <R, C, V>
BiCollector<R, BiStream<? extends C, ? extends V>, ImmutableTable<R, C, V>>
toImmutableTable() {
return BiCollectors.flatMapping(
(R r, BiStream<? extends C, ? extends V> columns) ->
columns.mapToObj((c, v) -> Tables.immutableCell(r, c, v)),
Collector.of(
ImmutableTable.Builder<R, C, V>::new,
ImmutableTable.Builder::put,
(builder, that) -> builder.putAll(that.build()),
ImmutableTable.Builder::build));
}
/**
* Returns a collector that first maps each input into a key-value pair, and then collects them
* into a {@link ImmutableMap}.
*
* @since 5.1
*/
public static <T, K, V> Collector<T, ?, ImmutableMap<K, V>> toImmutableMap( | Function<? super T, ? extends Both<? extends K, ? extends V>> mapper) { |
google/mug | mug/src/test/java/com/google/mu/util/SelectionTest.java | // Path: mug/src/main/java/com/google/mu/util/Selection.java
// @SuppressWarnings("unchecked")
// static <T> Selection<T> all() {
// return (Selection<T>) Selections.ALL;
// }
//
// Path: mug/src/main/java/com/google/mu/util/Selection.java
// static <T> Selection<T> nonEmptyOrAll(Collection<? extends T> choices) {
// return choices.isEmpty() ? all() : choices.stream().collect(toSelection());
// }
//
// Path: mug/src/main/java/com/google/mu/util/Selection.java
// @SuppressWarnings("unchecked")
// static <T> Selection<T> none() {
// return (Selection<T>) Selections.NONE;
// }
//
// Path: mug/src/main/java/com/google/mu/util/Selection.java
// @SafeVarargs
// static <T> Selection<T> only(T... choices) {
// return Arrays.stream(choices).collect(toSelection());
// }
//
// Path: mug/src/main/java/com/google/mu/util/Selection.java
// static <T> Collector<Selection<T>, ?, Selection<T>> toIntersection() {
// return reducing(all(), Selection::intersect);
// }
//
// Path: mug/src/main/java/com/google/mu/util/Selection.java
// static <T> Collector<T, ?, Selection<T>> toSelection() {
// return collectingAndThen(toImmutableSet(), Selections::explicit);
// }
//
// Path: mug/src/main/java/com/google/mu/util/Selection.java
// static <T> Collector<Selection<T>, ?, Selection<T>> toUnion() {
// return reducing(none(), Selection::union);
// }
| import org.junit.runners.JUnit4;
import com.google.common.collect.ImmutableSet;
import com.google.common.testing.EqualsTester;
import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth8.assertThat;
import static com.google.mu.util.Selection.all;
import static com.google.mu.util.Selection.nonEmptyOrAll;
import static com.google.mu.util.Selection.none;
import static com.google.mu.util.Selection.only;
import static com.google.mu.util.Selection.toIntersection;
import static com.google.mu.util.Selection.toSelection;
import static com.google.mu.util.Selection.toUnion;
import static java.util.Arrays.asList;
import static org.junit.jupiter.api.Assertions.assertThrows;
import java.util.stream.Stream;
import org.junit.Test;
import org.junit.runner.RunWith; | /*****************************************************************************
* ------------------------------------------------------------------------- *
* Licensed under the Apache License, Version 2.0 (the "License"); *
* you may not use this file except in compliance with the License. *
* You may obtain a copy of the License at *
* *
* http://www.apache.org/licenses/LICENSE-2.0 *
* *
* Unless required by applicable law or agreed to in writing, software *
* distributed under the License is distributed on an "AS IS" BASIS, *
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
* See the License for the specific language governing permissions and *
* limitations under the License. *
*****************************************************************************/
package com.google.mu.util;
@RunWith(JUnit4.class)
public class SelectionTest {
@Test public void all_limit() { | // Path: mug/src/main/java/com/google/mu/util/Selection.java
// @SuppressWarnings("unchecked")
// static <T> Selection<T> all() {
// return (Selection<T>) Selections.ALL;
// }
//
// Path: mug/src/main/java/com/google/mu/util/Selection.java
// static <T> Selection<T> nonEmptyOrAll(Collection<? extends T> choices) {
// return choices.isEmpty() ? all() : choices.stream().collect(toSelection());
// }
//
// Path: mug/src/main/java/com/google/mu/util/Selection.java
// @SuppressWarnings("unchecked")
// static <T> Selection<T> none() {
// return (Selection<T>) Selections.NONE;
// }
//
// Path: mug/src/main/java/com/google/mu/util/Selection.java
// @SafeVarargs
// static <T> Selection<T> only(T... choices) {
// return Arrays.stream(choices).collect(toSelection());
// }
//
// Path: mug/src/main/java/com/google/mu/util/Selection.java
// static <T> Collector<Selection<T>, ?, Selection<T>> toIntersection() {
// return reducing(all(), Selection::intersect);
// }
//
// Path: mug/src/main/java/com/google/mu/util/Selection.java
// static <T> Collector<T, ?, Selection<T>> toSelection() {
// return collectingAndThen(toImmutableSet(), Selections::explicit);
// }
//
// Path: mug/src/main/java/com/google/mu/util/Selection.java
// static <T> Collector<Selection<T>, ?, Selection<T>> toUnion() {
// return reducing(none(), Selection::union);
// }
// Path: mug/src/test/java/com/google/mu/util/SelectionTest.java
import org.junit.runners.JUnit4;
import com.google.common.collect.ImmutableSet;
import com.google.common.testing.EqualsTester;
import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth8.assertThat;
import static com.google.mu.util.Selection.all;
import static com.google.mu.util.Selection.nonEmptyOrAll;
import static com.google.mu.util.Selection.none;
import static com.google.mu.util.Selection.only;
import static com.google.mu.util.Selection.toIntersection;
import static com.google.mu.util.Selection.toSelection;
import static com.google.mu.util.Selection.toUnion;
import static java.util.Arrays.asList;
import static org.junit.jupiter.api.Assertions.assertThrows;
import java.util.stream.Stream;
import org.junit.Test;
import org.junit.runner.RunWith;
/*****************************************************************************
* ------------------------------------------------------------------------- *
* Licensed under the Apache License, Version 2.0 (the "License"); *
* you may not use this file except in compliance with the License. *
* You may obtain a copy of the License at *
* *
* http://www.apache.org/licenses/LICENSE-2.0 *
* *
* Unless required by applicable law or agreed to in writing, software *
* distributed under the License is distributed on an "AS IS" BASIS, *
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
* See the License for the specific language governing permissions and *
* limitations under the License. *
*****************************************************************************/
package com.google.mu.util;
@RunWith(JUnit4.class)
public class SelectionTest {
@Test public void all_limit() { | assertThat(all().limited()).isEmpty(); |
google/mug | mug/src/test/java/com/google/mu/util/SelectionTest.java | // Path: mug/src/main/java/com/google/mu/util/Selection.java
// @SuppressWarnings("unchecked")
// static <T> Selection<T> all() {
// return (Selection<T>) Selections.ALL;
// }
//
// Path: mug/src/main/java/com/google/mu/util/Selection.java
// static <T> Selection<T> nonEmptyOrAll(Collection<? extends T> choices) {
// return choices.isEmpty() ? all() : choices.stream().collect(toSelection());
// }
//
// Path: mug/src/main/java/com/google/mu/util/Selection.java
// @SuppressWarnings("unchecked")
// static <T> Selection<T> none() {
// return (Selection<T>) Selections.NONE;
// }
//
// Path: mug/src/main/java/com/google/mu/util/Selection.java
// @SafeVarargs
// static <T> Selection<T> only(T... choices) {
// return Arrays.stream(choices).collect(toSelection());
// }
//
// Path: mug/src/main/java/com/google/mu/util/Selection.java
// static <T> Collector<Selection<T>, ?, Selection<T>> toIntersection() {
// return reducing(all(), Selection::intersect);
// }
//
// Path: mug/src/main/java/com/google/mu/util/Selection.java
// static <T> Collector<T, ?, Selection<T>> toSelection() {
// return collectingAndThen(toImmutableSet(), Selections::explicit);
// }
//
// Path: mug/src/main/java/com/google/mu/util/Selection.java
// static <T> Collector<Selection<T>, ?, Selection<T>> toUnion() {
// return reducing(none(), Selection::union);
// }
| import org.junit.runners.JUnit4;
import com.google.common.collect.ImmutableSet;
import com.google.common.testing.EqualsTester;
import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth8.assertThat;
import static com.google.mu.util.Selection.all;
import static com.google.mu.util.Selection.nonEmptyOrAll;
import static com.google.mu.util.Selection.none;
import static com.google.mu.util.Selection.only;
import static com.google.mu.util.Selection.toIntersection;
import static com.google.mu.util.Selection.toSelection;
import static com.google.mu.util.Selection.toUnion;
import static java.util.Arrays.asList;
import static org.junit.jupiter.api.Assertions.assertThrows;
import java.util.stream.Stream;
import org.junit.Test;
import org.junit.runner.RunWith; | /*****************************************************************************
* ------------------------------------------------------------------------- *
* Licensed under the Apache License, Version 2.0 (the "License"); *
* you may not use this file except in compliance with the License. *
* You may obtain a copy of the License at *
* *
* http://www.apache.org/licenses/LICENSE-2.0 *
* *
* Unless required by applicable law or agreed to in writing, software *
* distributed under the License is distributed on an "AS IS" BASIS, *
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
* See the License for the specific language governing permissions and *
* limitations under the License. *
*****************************************************************************/
package com.google.mu.util;
@RunWith(JUnit4.class)
public class SelectionTest {
@Test public void all_limit() {
assertThat(all().limited()).isEmpty();
}
@Test public void all_has() {
assertThat(all().has("foo")).isTrue();
assertThat(all().has(null)).isTrue();
}
@Test public void all_isEmpty() {
assertThat(all().isEmpty()).isFalse();
}
@Test public void none_limit() { | // Path: mug/src/main/java/com/google/mu/util/Selection.java
// @SuppressWarnings("unchecked")
// static <T> Selection<T> all() {
// return (Selection<T>) Selections.ALL;
// }
//
// Path: mug/src/main/java/com/google/mu/util/Selection.java
// static <T> Selection<T> nonEmptyOrAll(Collection<? extends T> choices) {
// return choices.isEmpty() ? all() : choices.stream().collect(toSelection());
// }
//
// Path: mug/src/main/java/com/google/mu/util/Selection.java
// @SuppressWarnings("unchecked")
// static <T> Selection<T> none() {
// return (Selection<T>) Selections.NONE;
// }
//
// Path: mug/src/main/java/com/google/mu/util/Selection.java
// @SafeVarargs
// static <T> Selection<T> only(T... choices) {
// return Arrays.stream(choices).collect(toSelection());
// }
//
// Path: mug/src/main/java/com/google/mu/util/Selection.java
// static <T> Collector<Selection<T>, ?, Selection<T>> toIntersection() {
// return reducing(all(), Selection::intersect);
// }
//
// Path: mug/src/main/java/com/google/mu/util/Selection.java
// static <T> Collector<T, ?, Selection<T>> toSelection() {
// return collectingAndThen(toImmutableSet(), Selections::explicit);
// }
//
// Path: mug/src/main/java/com/google/mu/util/Selection.java
// static <T> Collector<Selection<T>, ?, Selection<T>> toUnion() {
// return reducing(none(), Selection::union);
// }
// Path: mug/src/test/java/com/google/mu/util/SelectionTest.java
import org.junit.runners.JUnit4;
import com.google.common.collect.ImmutableSet;
import com.google.common.testing.EqualsTester;
import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth8.assertThat;
import static com.google.mu.util.Selection.all;
import static com.google.mu.util.Selection.nonEmptyOrAll;
import static com.google.mu.util.Selection.none;
import static com.google.mu.util.Selection.only;
import static com.google.mu.util.Selection.toIntersection;
import static com.google.mu.util.Selection.toSelection;
import static com.google.mu.util.Selection.toUnion;
import static java.util.Arrays.asList;
import static org.junit.jupiter.api.Assertions.assertThrows;
import java.util.stream.Stream;
import org.junit.Test;
import org.junit.runner.RunWith;
/*****************************************************************************
* ------------------------------------------------------------------------- *
* Licensed under the Apache License, Version 2.0 (the "License"); *
* you may not use this file except in compliance with the License. *
* You may obtain a copy of the License at *
* *
* http://www.apache.org/licenses/LICENSE-2.0 *
* *
* Unless required by applicable law or agreed to in writing, software *
* distributed under the License is distributed on an "AS IS" BASIS, *
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
* See the License for the specific language governing permissions and *
* limitations under the License. *
*****************************************************************************/
package com.google.mu.util;
@RunWith(JUnit4.class)
public class SelectionTest {
@Test public void all_limit() {
assertThat(all().limited()).isEmpty();
}
@Test public void all_has() {
assertThat(all().has("foo")).isTrue();
assertThat(all().has(null)).isTrue();
}
@Test public void all_isEmpty() {
assertThat(all().isEmpty()).isFalse();
}
@Test public void none_limit() { | assertThat(none().limited()).hasValue(ImmutableSet.of()); |
google/mug | mug/src/test/java/com/google/mu/util/SelectionTest.java | // Path: mug/src/main/java/com/google/mu/util/Selection.java
// @SuppressWarnings("unchecked")
// static <T> Selection<T> all() {
// return (Selection<T>) Selections.ALL;
// }
//
// Path: mug/src/main/java/com/google/mu/util/Selection.java
// static <T> Selection<T> nonEmptyOrAll(Collection<? extends T> choices) {
// return choices.isEmpty() ? all() : choices.stream().collect(toSelection());
// }
//
// Path: mug/src/main/java/com/google/mu/util/Selection.java
// @SuppressWarnings("unchecked")
// static <T> Selection<T> none() {
// return (Selection<T>) Selections.NONE;
// }
//
// Path: mug/src/main/java/com/google/mu/util/Selection.java
// @SafeVarargs
// static <T> Selection<T> only(T... choices) {
// return Arrays.stream(choices).collect(toSelection());
// }
//
// Path: mug/src/main/java/com/google/mu/util/Selection.java
// static <T> Collector<Selection<T>, ?, Selection<T>> toIntersection() {
// return reducing(all(), Selection::intersect);
// }
//
// Path: mug/src/main/java/com/google/mu/util/Selection.java
// static <T> Collector<T, ?, Selection<T>> toSelection() {
// return collectingAndThen(toImmutableSet(), Selections::explicit);
// }
//
// Path: mug/src/main/java/com/google/mu/util/Selection.java
// static <T> Collector<Selection<T>, ?, Selection<T>> toUnion() {
// return reducing(none(), Selection::union);
// }
| import org.junit.runners.JUnit4;
import com.google.common.collect.ImmutableSet;
import com.google.common.testing.EqualsTester;
import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth8.assertThat;
import static com.google.mu.util.Selection.all;
import static com.google.mu.util.Selection.nonEmptyOrAll;
import static com.google.mu.util.Selection.none;
import static com.google.mu.util.Selection.only;
import static com.google.mu.util.Selection.toIntersection;
import static com.google.mu.util.Selection.toSelection;
import static com.google.mu.util.Selection.toUnion;
import static java.util.Arrays.asList;
import static org.junit.jupiter.api.Assertions.assertThrows;
import java.util.stream.Stream;
import org.junit.Test;
import org.junit.runner.RunWith; | /*****************************************************************************
* ------------------------------------------------------------------------- *
* Licensed under the Apache License, Version 2.0 (the "License"); *
* you may not use this file except in compliance with the License. *
* You may obtain a copy of the License at *
* *
* http://www.apache.org/licenses/LICENSE-2.0 *
* *
* Unless required by applicable law or agreed to in writing, software *
* distributed under the License is distributed on an "AS IS" BASIS, *
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
* See the License for the specific language governing permissions and *
* limitations under the License. *
*****************************************************************************/
package com.google.mu.util;
@RunWith(JUnit4.class)
public class SelectionTest {
@Test public void all_limit() {
assertThat(all().limited()).isEmpty();
}
@Test public void all_has() {
assertThat(all().has("foo")).isTrue();
assertThat(all().has(null)).isTrue();
}
@Test public void all_isEmpty() {
assertThat(all().isEmpty()).isFalse();
}
@Test public void none_limit() {
assertThat(none().limited()).hasValue(ImmutableSet.of());
}
@Test public void none_has() {
assertThat(none().has("foo")).isFalse();
assertThat(none().has(null)).isFalse();
}
@Test public void none_isEmpty() {
assertThat(none().isEmpty()).isTrue();
}
@Test public void only_limit() { | // Path: mug/src/main/java/com/google/mu/util/Selection.java
// @SuppressWarnings("unchecked")
// static <T> Selection<T> all() {
// return (Selection<T>) Selections.ALL;
// }
//
// Path: mug/src/main/java/com/google/mu/util/Selection.java
// static <T> Selection<T> nonEmptyOrAll(Collection<? extends T> choices) {
// return choices.isEmpty() ? all() : choices.stream().collect(toSelection());
// }
//
// Path: mug/src/main/java/com/google/mu/util/Selection.java
// @SuppressWarnings("unchecked")
// static <T> Selection<T> none() {
// return (Selection<T>) Selections.NONE;
// }
//
// Path: mug/src/main/java/com/google/mu/util/Selection.java
// @SafeVarargs
// static <T> Selection<T> only(T... choices) {
// return Arrays.stream(choices).collect(toSelection());
// }
//
// Path: mug/src/main/java/com/google/mu/util/Selection.java
// static <T> Collector<Selection<T>, ?, Selection<T>> toIntersection() {
// return reducing(all(), Selection::intersect);
// }
//
// Path: mug/src/main/java/com/google/mu/util/Selection.java
// static <T> Collector<T, ?, Selection<T>> toSelection() {
// return collectingAndThen(toImmutableSet(), Selections::explicit);
// }
//
// Path: mug/src/main/java/com/google/mu/util/Selection.java
// static <T> Collector<Selection<T>, ?, Selection<T>> toUnion() {
// return reducing(none(), Selection::union);
// }
// Path: mug/src/test/java/com/google/mu/util/SelectionTest.java
import org.junit.runners.JUnit4;
import com.google.common.collect.ImmutableSet;
import com.google.common.testing.EqualsTester;
import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth8.assertThat;
import static com.google.mu.util.Selection.all;
import static com.google.mu.util.Selection.nonEmptyOrAll;
import static com.google.mu.util.Selection.none;
import static com.google.mu.util.Selection.only;
import static com.google.mu.util.Selection.toIntersection;
import static com.google.mu.util.Selection.toSelection;
import static com.google.mu.util.Selection.toUnion;
import static java.util.Arrays.asList;
import static org.junit.jupiter.api.Assertions.assertThrows;
import java.util.stream.Stream;
import org.junit.Test;
import org.junit.runner.RunWith;
/*****************************************************************************
* ------------------------------------------------------------------------- *
* Licensed under the Apache License, Version 2.0 (the "License"); *
* you may not use this file except in compliance with the License. *
* You may obtain a copy of the License at *
* *
* http://www.apache.org/licenses/LICENSE-2.0 *
* *
* Unless required by applicable law or agreed to in writing, software *
* distributed under the License is distributed on an "AS IS" BASIS, *
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
* See the License for the specific language governing permissions and *
* limitations under the License. *
*****************************************************************************/
package com.google.mu.util;
@RunWith(JUnit4.class)
public class SelectionTest {
@Test public void all_limit() {
assertThat(all().limited()).isEmpty();
}
@Test public void all_has() {
assertThat(all().has("foo")).isTrue();
assertThat(all().has(null)).isTrue();
}
@Test public void all_isEmpty() {
assertThat(all().isEmpty()).isFalse();
}
@Test public void none_limit() {
assertThat(none().limited()).hasValue(ImmutableSet.of());
}
@Test public void none_has() {
assertThat(none().has("foo")).isFalse();
assertThat(none().has(null)).isFalse();
}
@Test public void none_isEmpty() {
assertThat(none().isEmpty()).isTrue();
}
@Test public void only_limit() { | assertThat(only("foo", "bar").limited()).hasValue(ImmutableSet.of("foo", "bar")); |
google/mug | mug/src/test/java/com/google/mu/util/SelectionTest.java | // Path: mug/src/main/java/com/google/mu/util/Selection.java
// @SuppressWarnings("unchecked")
// static <T> Selection<T> all() {
// return (Selection<T>) Selections.ALL;
// }
//
// Path: mug/src/main/java/com/google/mu/util/Selection.java
// static <T> Selection<T> nonEmptyOrAll(Collection<? extends T> choices) {
// return choices.isEmpty() ? all() : choices.stream().collect(toSelection());
// }
//
// Path: mug/src/main/java/com/google/mu/util/Selection.java
// @SuppressWarnings("unchecked")
// static <T> Selection<T> none() {
// return (Selection<T>) Selections.NONE;
// }
//
// Path: mug/src/main/java/com/google/mu/util/Selection.java
// @SafeVarargs
// static <T> Selection<T> only(T... choices) {
// return Arrays.stream(choices).collect(toSelection());
// }
//
// Path: mug/src/main/java/com/google/mu/util/Selection.java
// static <T> Collector<Selection<T>, ?, Selection<T>> toIntersection() {
// return reducing(all(), Selection::intersect);
// }
//
// Path: mug/src/main/java/com/google/mu/util/Selection.java
// static <T> Collector<T, ?, Selection<T>> toSelection() {
// return collectingAndThen(toImmutableSet(), Selections::explicit);
// }
//
// Path: mug/src/main/java/com/google/mu/util/Selection.java
// static <T> Collector<Selection<T>, ?, Selection<T>> toUnion() {
// return reducing(none(), Selection::union);
// }
| import org.junit.runners.JUnit4;
import com.google.common.collect.ImmutableSet;
import com.google.common.testing.EqualsTester;
import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth8.assertThat;
import static com.google.mu.util.Selection.all;
import static com.google.mu.util.Selection.nonEmptyOrAll;
import static com.google.mu.util.Selection.none;
import static com.google.mu.util.Selection.only;
import static com.google.mu.util.Selection.toIntersection;
import static com.google.mu.util.Selection.toSelection;
import static com.google.mu.util.Selection.toUnion;
import static java.util.Arrays.asList;
import static org.junit.jupiter.api.Assertions.assertThrows;
import java.util.stream.Stream;
import org.junit.Test;
import org.junit.runner.RunWith; | @Test public void only_has() {
assertThat(only("foo").has("foo")).isTrue();
assertThat(only("foo").has("bar")).isFalse();
assertThat(only("foo").has(null)).isFalse();
}
@Test public void only_isEmpty() {
assertThat(only("foo").isEmpty()).isFalse();
}
@Test public void only_union() {
assertThat(only("foo").union(only("bar"))).isEqualTo(only("foo", "bar"));
assertThat(only("foo").union(only("bar")).limited().get())
.containsExactly("foo", "bar")
.inOrder();
assertThat(only("foo", "bar").union(only("bar", "dog")).limited().get())
.containsExactly("foo", "bar", "dog")
.inOrder();
}
@Test public void only_intersect() {
assertThat(only("foo", "bar").intersect(only("dog", "bar", "foo")))
.isEqualTo(only("foo", "bar"));
assertThat(only("foo", "bar").intersect(only("bar", "dog", "foo")).limited().get())
.containsExactly("foo", "bar")
.inOrder();
assertThat(only("foo").intersect(only("bar"))).isEqualTo(none());
}
@Test public void nonEmptyOrAll_empty() { | // Path: mug/src/main/java/com/google/mu/util/Selection.java
// @SuppressWarnings("unchecked")
// static <T> Selection<T> all() {
// return (Selection<T>) Selections.ALL;
// }
//
// Path: mug/src/main/java/com/google/mu/util/Selection.java
// static <T> Selection<T> nonEmptyOrAll(Collection<? extends T> choices) {
// return choices.isEmpty() ? all() : choices.stream().collect(toSelection());
// }
//
// Path: mug/src/main/java/com/google/mu/util/Selection.java
// @SuppressWarnings("unchecked")
// static <T> Selection<T> none() {
// return (Selection<T>) Selections.NONE;
// }
//
// Path: mug/src/main/java/com/google/mu/util/Selection.java
// @SafeVarargs
// static <T> Selection<T> only(T... choices) {
// return Arrays.stream(choices).collect(toSelection());
// }
//
// Path: mug/src/main/java/com/google/mu/util/Selection.java
// static <T> Collector<Selection<T>, ?, Selection<T>> toIntersection() {
// return reducing(all(), Selection::intersect);
// }
//
// Path: mug/src/main/java/com/google/mu/util/Selection.java
// static <T> Collector<T, ?, Selection<T>> toSelection() {
// return collectingAndThen(toImmutableSet(), Selections::explicit);
// }
//
// Path: mug/src/main/java/com/google/mu/util/Selection.java
// static <T> Collector<Selection<T>, ?, Selection<T>> toUnion() {
// return reducing(none(), Selection::union);
// }
// Path: mug/src/test/java/com/google/mu/util/SelectionTest.java
import org.junit.runners.JUnit4;
import com.google.common.collect.ImmutableSet;
import com.google.common.testing.EqualsTester;
import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth8.assertThat;
import static com.google.mu.util.Selection.all;
import static com.google.mu.util.Selection.nonEmptyOrAll;
import static com.google.mu.util.Selection.none;
import static com.google.mu.util.Selection.only;
import static com.google.mu.util.Selection.toIntersection;
import static com.google.mu.util.Selection.toSelection;
import static com.google.mu.util.Selection.toUnion;
import static java.util.Arrays.asList;
import static org.junit.jupiter.api.Assertions.assertThrows;
import java.util.stream.Stream;
import org.junit.Test;
import org.junit.runner.RunWith;
@Test public void only_has() {
assertThat(only("foo").has("foo")).isTrue();
assertThat(only("foo").has("bar")).isFalse();
assertThat(only("foo").has(null)).isFalse();
}
@Test public void only_isEmpty() {
assertThat(only("foo").isEmpty()).isFalse();
}
@Test public void only_union() {
assertThat(only("foo").union(only("bar"))).isEqualTo(only("foo", "bar"));
assertThat(only("foo").union(only("bar")).limited().get())
.containsExactly("foo", "bar")
.inOrder();
assertThat(only("foo", "bar").union(only("bar", "dog")).limited().get())
.containsExactly("foo", "bar", "dog")
.inOrder();
}
@Test public void only_intersect() {
assertThat(only("foo", "bar").intersect(only("dog", "bar", "foo")))
.isEqualTo(only("foo", "bar"));
assertThat(only("foo", "bar").intersect(only("bar", "dog", "foo")).limited().get())
.containsExactly("foo", "bar")
.inOrder();
assertThat(only("foo").intersect(only("bar"))).isEqualTo(none());
}
@Test public void nonEmptyOrAll_empty() { | assertThat(nonEmptyOrAll(asList()).limited()).isEmpty(); |
google/mug | mug/src/test/java/com/google/mu/util/SelectionTest.java | // Path: mug/src/main/java/com/google/mu/util/Selection.java
// @SuppressWarnings("unchecked")
// static <T> Selection<T> all() {
// return (Selection<T>) Selections.ALL;
// }
//
// Path: mug/src/main/java/com/google/mu/util/Selection.java
// static <T> Selection<T> nonEmptyOrAll(Collection<? extends T> choices) {
// return choices.isEmpty() ? all() : choices.stream().collect(toSelection());
// }
//
// Path: mug/src/main/java/com/google/mu/util/Selection.java
// @SuppressWarnings("unchecked")
// static <T> Selection<T> none() {
// return (Selection<T>) Selections.NONE;
// }
//
// Path: mug/src/main/java/com/google/mu/util/Selection.java
// @SafeVarargs
// static <T> Selection<T> only(T... choices) {
// return Arrays.stream(choices).collect(toSelection());
// }
//
// Path: mug/src/main/java/com/google/mu/util/Selection.java
// static <T> Collector<Selection<T>, ?, Selection<T>> toIntersection() {
// return reducing(all(), Selection::intersect);
// }
//
// Path: mug/src/main/java/com/google/mu/util/Selection.java
// static <T> Collector<T, ?, Selection<T>> toSelection() {
// return collectingAndThen(toImmutableSet(), Selections::explicit);
// }
//
// Path: mug/src/main/java/com/google/mu/util/Selection.java
// static <T> Collector<Selection<T>, ?, Selection<T>> toUnion() {
// return reducing(none(), Selection::union);
// }
| import org.junit.runners.JUnit4;
import com.google.common.collect.ImmutableSet;
import com.google.common.testing.EqualsTester;
import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth8.assertThat;
import static com.google.mu.util.Selection.all;
import static com.google.mu.util.Selection.nonEmptyOrAll;
import static com.google.mu.util.Selection.none;
import static com.google.mu.util.Selection.only;
import static com.google.mu.util.Selection.toIntersection;
import static com.google.mu.util.Selection.toSelection;
import static com.google.mu.util.Selection.toUnion;
import static java.util.Arrays.asList;
import static org.junit.jupiter.api.Assertions.assertThrows;
import java.util.stream.Stream;
import org.junit.Test;
import org.junit.runner.RunWith; | () -> Selection.delimitedBy(Substring.first('*').or(Substring.last('/'))));
}
@Test public void testEquals() throws Exception {
new EqualsTester()
.addEqualityGroup(
all(),
all().union(all()),
all().union(none()),
none().union(all()),
all().union(only("foo")),
only("foo").union(all()),
all().intersect(all()),
nonEmptyOrAll(asList()))
.addEqualityGroup(
none(),
only(),
none().intersect(none()),
none().intersect(all()),
all().intersect(none()),
none().intersect(only("foo")),
only("foo").intersect(none()))
.addEqualityGroup(
only("foo"),
only("foo", "foo"),
all().intersect(only("foo")),
none().union(only("foo")),
only("foo").intersect(all()),
only("foo").union(none()),
only("foo", "bar").intersect(only("baz", "foo")), | // Path: mug/src/main/java/com/google/mu/util/Selection.java
// @SuppressWarnings("unchecked")
// static <T> Selection<T> all() {
// return (Selection<T>) Selections.ALL;
// }
//
// Path: mug/src/main/java/com/google/mu/util/Selection.java
// static <T> Selection<T> nonEmptyOrAll(Collection<? extends T> choices) {
// return choices.isEmpty() ? all() : choices.stream().collect(toSelection());
// }
//
// Path: mug/src/main/java/com/google/mu/util/Selection.java
// @SuppressWarnings("unchecked")
// static <T> Selection<T> none() {
// return (Selection<T>) Selections.NONE;
// }
//
// Path: mug/src/main/java/com/google/mu/util/Selection.java
// @SafeVarargs
// static <T> Selection<T> only(T... choices) {
// return Arrays.stream(choices).collect(toSelection());
// }
//
// Path: mug/src/main/java/com/google/mu/util/Selection.java
// static <T> Collector<Selection<T>, ?, Selection<T>> toIntersection() {
// return reducing(all(), Selection::intersect);
// }
//
// Path: mug/src/main/java/com/google/mu/util/Selection.java
// static <T> Collector<T, ?, Selection<T>> toSelection() {
// return collectingAndThen(toImmutableSet(), Selections::explicit);
// }
//
// Path: mug/src/main/java/com/google/mu/util/Selection.java
// static <T> Collector<Selection<T>, ?, Selection<T>> toUnion() {
// return reducing(none(), Selection::union);
// }
// Path: mug/src/test/java/com/google/mu/util/SelectionTest.java
import org.junit.runners.JUnit4;
import com.google.common.collect.ImmutableSet;
import com.google.common.testing.EqualsTester;
import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth8.assertThat;
import static com.google.mu.util.Selection.all;
import static com.google.mu.util.Selection.nonEmptyOrAll;
import static com.google.mu.util.Selection.none;
import static com.google.mu.util.Selection.only;
import static com.google.mu.util.Selection.toIntersection;
import static com.google.mu.util.Selection.toSelection;
import static com.google.mu.util.Selection.toUnion;
import static java.util.Arrays.asList;
import static org.junit.jupiter.api.Assertions.assertThrows;
import java.util.stream.Stream;
import org.junit.Test;
import org.junit.runner.RunWith;
() -> Selection.delimitedBy(Substring.first('*').or(Substring.last('/'))));
}
@Test public void testEquals() throws Exception {
new EqualsTester()
.addEqualityGroup(
all(),
all().union(all()),
all().union(none()),
none().union(all()),
all().union(only("foo")),
only("foo").union(all()),
all().intersect(all()),
nonEmptyOrAll(asList()))
.addEqualityGroup(
none(),
only(),
none().intersect(none()),
none().intersect(all()),
all().intersect(none()),
none().intersect(only("foo")),
only("foo").intersect(none()))
.addEqualityGroup(
only("foo"),
only("foo", "foo"),
all().intersect(only("foo")),
none().union(only("foo")),
only("foo").intersect(all()),
only("foo").union(none()),
only("foo", "bar").intersect(only("baz", "foo")), | Stream.of("foo", "foo").collect(toSelection()), |
google/mug | mug/src/test/java/com/google/mu/util/SelectionTest.java | // Path: mug/src/main/java/com/google/mu/util/Selection.java
// @SuppressWarnings("unchecked")
// static <T> Selection<T> all() {
// return (Selection<T>) Selections.ALL;
// }
//
// Path: mug/src/main/java/com/google/mu/util/Selection.java
// static <T> Selection<T> nonEmptyOrAll(Collection<? extends T> choices) {
// return choices.isEmpty() ? all() : choices.stream().collect(toSelection());
// }
//
// Path: mug/src/main/java/com/google/mu/util/Selection.java
// @SuppressWarnings("unchecked")
// static <T> Selection<T> none() {
// return (Selection<T>) Selections.NONE;
// }
//
// Path: mug/src/main/java/com/google/mu/util/Selection.java
// @SafeVarargs
// static <T> Selection<T> only(T... choices) {
// return Arrays.stream(choices).collect(toSelection());
// }
//
// Path: mug/src/main/java/com/google/mu/util/Selection.java
// static <T> Collector<Selection<T>, ?, Selection<T>> toIntersection() {
// return reducing(all(), Selection::intersect);
// }
//
// Path: mug/src/main/java/com/google/mu/util/Selection.java
// static <T> Collector<T, ?, Selection<T>> toSelection() {
// return collectingAndThen(toImmutableSet(), Selections::explicit);
// }
//
// Path: mug/src/main/java/com/google/mu/util/Selection.java
// static <T> Collector<Selection<T>, ?, Selection<T>> toUnion() {
// return reducing(none(), Selection::union);
// }
| import org.junit.runners.JUnit4;
import com.google.common.collect.ImmutableSet;
import com.google.common.testing.EqualsTester;
import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth8.assertThat;
import static com.google.mu.util.Selection.all;
import static com.google.mu.util.Selection.nonEmptyOrAll;
import static com.google.mu.util.Selection.none;
import static com.google.mu.util.Selection.only;
import static com.google.mu.util.Selection.toIntersection;
import static com.google.mu.util.Selection.toSelection;
import static com.google.mu.util.Selection.toUnion;
import static java.util.Arrays.asList;
import static org.junit.jupiter.api.Assertions.assertThrows;
import java.util.stream.Stream;
import org.junit.Test;
import org.junit.runner.RunWith; | }
@Test public void testEquals() throws Exception {
new EqualsTester()
.addEqualityGroup(
all(),
all().union(all()),
all().union(none()),
none().union(all()),
all().union(only("foo")),
only("foo").union(all()),
all().intersect(all()),
nonEmptyOrAll(asList()))
.addEqualityGroup(
none(),
only(),
none().intersect(none()),
none().intersect(all()),
all().intersect(none()),
none().intersect(only("foo")),
only("foo").intersect(none()))
.addEqualityGroup(
only("foo"),
only("foo", "foo"),
all().intersect(only("foo")),
none().union(only("foo")),
only("foo").intersect(all()),
only("foo").union(none()),
only("foo", "bar").intersect(only("baz", "foo")),
Stream.of("foo", "foo").collect(toSelection()), | // Path: mug/src/main/java/com/google/mu/util/Selection.java
// @SuppressWarnings("unchecked")
// static <T> Selection<T> all() {
// return (Selection<T>) Selections.ALL;
// }
//
// Path: mug/src/main/java/com/google/mu/util/Selection.java
// static <T> Selection<T> nonEmptyOrAll(Collection<? extends T> choices) {
// return choices.isEmpty() ? all() : choices.stream().collect(toSelection());
// }
//
// Path: mug/src/main/java/com/google/mu/util/Selection.java
// @SuppressWarnings("unchecked")
// static <T> Selection<T> none() {
// return (Selection<T>) Selections.NONE;
// }
//
// Path: mug/src/main/java/com/google/mu/util/Selection.java
// @SafeVarargs
// static <T> Selection<T> only(T... choices) {
// return Arrays.stream(choices).collect(toSelection());
// }
//
// Path: mug/src/main/java/com/google/mu/util/Selection.java
// static <T> Collector<Selection<T>, ?, Selection<T>> toIntersection() {
// return reducing(all(), Selection::intersect);
// }
//
// Path: mug/src/main/java/com/google/mu/util/Selection.java
// static <T> Collector<T, ?, Selection<T>> toSelection() {
// return collectingAndThen(toImmutableSet(), Selections::explicit);
// }
//
// Path: mug/src/main/java/com/google/mu/util/Selection.java
// static <T> Collector<Selection<T>, ?, Selection<T>> toUnion() {
// return reducing(none(), Selection::union);
// }
// Path: mug/src/test/java/com/google/mu/util/SelectionTest.java
import org.junit.runners.JUnit4;
import com.google.common.collect.ImmutableSet;
import com.google.common.testing.EqualsTester;
import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth8.assertThat;
import static com.google.mu.util.Selection.all;
import static com.google.mu.util.Selection.nonEmptyOrAll;
import static com.google.mu.util.Selection.none;
import static com.google.mu.util.Selection.only;
import static com.google.mu.util.Selection.toIntersection;
import static com.google.mu.util.Selection.toSelection;
import static com.google.mu.util.Selection.toUnion;
import static java.util.Arrays.asList;
import static org.junit.jupiter.api.Assertions.assertThrows;
import java.util.stream.Stream;
import org.junit.Test;
import org.junit.runner.RunWith;
}
@Test public void testEquals() throws Exception {
new EqualsTester()
.addEqualityGroup(
all(),
all().union(all()),
all().union(none()),
none().union(all()),
all().union(only("foo")),
only("foo").union(all()),
all().intersect(all()),
nonEmptyOrAll(asList()))
.addEqualityGroup(
none(),
only(),
none().intersect(none()),
none().intersect(all()),
all().intersect(none()),
none().intersect(only("foo")),
only("foo").intersect(none()))
.addEqualityGroup(
only("foo"),
only("foo", "foo"),
all().intersect(only("foo")),
none().union(only("foo")),
only("foo").intersect(all()),
only("foo").union(none()),
only("foo", "bar").intersect(only("baz", "foo")),
Stream.of("foo", "foo").collect(toSelection()), | Stream.of(only("foo", "bar"), only("foo")).collect(toIntersection()), |
google/mug | mug/src/test/java/com/google/mu/util/SelectionTest.java | // Path: mug/src/main/java/com/google/mu/util/Selection.java
// @SuppressWarnings("unchecked")
// static <T> Selection<T> all() {
// return (Selection<T>) Selections.ALL;
// }
//
// Path: mug/src/main/java/com/google/mu/util/Selection.java
// static <T> Selection<T> nonEmptyOrAll(Collection<? extends T> choices) {
// return choices.isEmpty() ? all() : choices.stream().collect(toSelection());
// }
//
// Path: mug/src/main/java/com/google/mu/util/Selection.java
// @SuppressWarnings("unchecked")
// static <T> Selection<T> none() {
// return (Selection<T>) Selections.NONE;
// }
//
// Path: mug/src/main/java/com/google/mu/util/Selection.java
// @SafeVarargs
// static <T> Selection<T> only(T... choices) {
// return Arrays.stream(choices).collect(toSelection());
// }
//
// Path: mug/src/main/java/com/google/mu/util/Selection.java
// static <T> Collector<Selection<T>, ?, Selection<T>> toIntersection() {
// return reducing(all(), Selection::intersect);
// }
//
// Path: mug/src/main/java/com/google/mu/util/Selection.java
// static <T> Collector<T, ?, Selection<T>> toSelection() {
// return collectingAndThen(toImmutableSet(), Selections::explicit);
// }
//
// Path: mug/src/main/java/com/google/mu/util/Selection.java
// static <T> Collector<Selection<T>, ?, Selection<T>> toUnion() {
// return reducing(none(), Selection::union);
// }
| import org.junit.runners.JUnit4;
import com.google.common.collect.ImmutableSet;
import com.google.common.testing.EqualsTester;
import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth8.assertThat;
import static com.google.mu.util.Selection.all;
import static com.google.mu.util.Selection.nonEmptyOrAll;
import static com.google.mu.util.Selection.none;
import static com.google.mu.util.Selection.only;
import static com.google.mu.util.Selection.toIntersection;
import static com.google.mu.util.Selection.toSelection;
import static com.google.mu.util.Selection.toUnion;
import static java.util.Arrays.asList;
import static org.junit.jupiter.api.Assertions.assertThrows;
import java.util.stream.Stream;
import org.junit.Test;
import org.junit.runner.RunWith; |
@Test public void testEquals() throws Exception {
new EqualsTester()
.addEqualityGroup(
all(),
all().union(all()),
all().union(none()),
none().union(all()),
all().union(only("foo")),
only("foo").union(all()),
all().intersect(all()),
nonEmptyOrAll(asList()))
.addEqualityGroup(
none(),
only(),
none().intersect(none()),
none().intersect(all()),
all().intersect(none()),
none().intersect(only("foo")),
only("foo").intersect(none()))
.addEqualityGroup(
only("foo"),
only("foo", "foo"),
all().intersect(only("foo")),
none().union(only("foo")),
only("foo").intersect(all()),
only("foo").union(none()),
only("foo", "bar").intersect(only("baz", "foo")),
Stream.of("foo", "foo").collect(toSelection()),
Stream.of(only("foo", "bar"), only("foo")).collect(toIntersection()), | // Path: mug/src/main/java/com/google/mu/util/Selection.java
// @SuppressWarnings("unchecked")
// static <T> Selection<T> all() {
// return (Selection<T>) Selections.ALL;
// }
//
// Path: mug/src/main/java/com/google/mu/util/Selection.java
// static <T> Selection<T> nonEmptyOrAll(Collection<? extends T> choices) {
// return choices.isEmpty() ? all() : choices.stream().collect(toSelection());
// }
//
// Path: mug/src/main/java/com/google/mu/util/Selection.java
// @SuppressWarnings("unchecked")
// static <T> Selection<T> none() {
// return (Selection<T>) Selections.NONE;
// }
//
// Path: mug/src/main/java/com/google/mu/util/Selection.java
// @SafeVarargs
// static <T> Selection<T> only(T... choices) {
// return Arrays.stream(choices).collect(toSelection());
// }
//
// Path: mug/src/main/java/com/google/mu/util/Selection.java
// static <T> Collector<Selection<T>, ?, Selection<T>> toIntersection() {
// return reducing(all(), Selection::intersect);
// }
//
// Path: mug/src/main/java/com/google/mu/util/Selection.java
// static <T> Collector<T, ?, Selection<T>> toSelection() {
// return collectingAndThen(toImmutableSet(), Selections::explicit);
// }
//
// Path: mug/src/main/java/com/google/mu/util/Selection.java
// static <T> Collector<Selection<T>, ?, Selection<T>> toUnion() {
// return reducing(none(), Selection::union);
// }
// Path: mug/src/test/java/com/google/mu/util/SelectionTest.java
import org.junit.runners.JUnit4;
import com.google.common.collect.ImmutableSet;
import com.google.common.testing.EqualsTester;
import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth8.assertThat;
import static com.google.mu.util.Selection.all;
import static com.google.mu.util.Selection.nonEmptyOrAll;
import static com.google.mu.util.Selection.none;
import static com.google.mu.util.Selection.only;
import static com.google.mu.util.Selection.toIntersection;
import static com.google.mu.util.Selection.toSelection;
import static com.google.mu.util.Selection.toUnion;
import static java.util.Arrays.asList;
import static org.junit.jupiter.api.Assertions.assertThrows;
import java.util.stream.Stream;
import org.junit.Test;
import org.junit.runner.RunWith;
@Test public void testEquals() throws Exception {
new EqualsTester()
.addEqualityGroup(
all(),
all().union(all()),
all().union(none()),
none().union(all()),
all().union(only("foo")),
only("foo").union(all()),
all().intersect(all()),
nonEmptyOrAll(asList()))
.addEqualityGroup(
none(),
only(),
none().intersect(none()),
none().intersect(all()),
all().intersect(none()),
none().intersect(only("foo")),
only("foo").intersect(none()))
.addEqualityGroup(
only("foo"),
only("foo", "foo"),
all().intersect(only("foo")),
none().union(only("foo")),
only("foo").intersect(all()),
only("foo").union(none()),
only("foo", "bar").intersect(only("baz", "foo")),
Stream.of("foo", "foo").collect(toSelection()),
Stream.of(only("foo", "bar"), only("foo")).collect(toIntersection()), | Stream.of(only("foo"), Selection.<String>none()).collect(toUnion()), |
google/mug | mug/src/main/java/com/google/mu/util/stream/MoreStreams.java | // Path: mug/src/main/java/com/google/mu/util/stream/BiStream.java
// public static <T> BiStream<T, T> biStream(Collection<T> elements) {
// return from(elements, identity(), identity());
// }
//
// Path: mug/src/main/java/com/google/mu/function/CheckedConsumer.java
// @FunctionalInterface
// public interface CheckedConsumer<T, E extends Throwable> {
// void accept(T input) throws E;
//
// /**
// * Returns a new {@code CheckedConsumer} that also passes the input to {@code that}.
// * For example: {@code out::writeObject.andThen(logger::info).accept("message")}.
// */
// default CheckedConsumer<T, E> andThen(CheckedConsumer<? super T, E> that) {
// requireNonNull(that);
// return input -> {
// accept(input);
// that.accept(input);
// };
// }
// }
| import static com.google.mu.util.stream.BiStream.biStream;
import static java.util.Objects.requireNonNull;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.Queue;
import java.util.Spliterator;
import java.util.Spliterators.AbstractSpliterator;
import java.util.function.BiPredicate;
import java.util.function.BinaryOperator;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.stream.Collector;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.LongStream;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;
import com.google.mu.function.CheckedConsumer; | * The above is equivalent to manually doing:
*
* <pre>{@code
* Iterable<Foo> foos = stream::iterator;
* for (Foo foo : foos) {
* ...
* }
* }</pre>
* except using this API eliminates the need for a named variable that escapes the scope of the
* for-each loop. And code is more readable too.
*
* <p>Note that {@link #iterateThrough iterateThrough()} should be preferred whenever possible
* due to the caveats mentioned above. This method is still useful when the loop body needs to
* use control flows such as {@code break} or {@code return}.
*/
public static <T> Iterable<T> iterateOnce(Stream<T> stream) {
return stream::iterator;
}
/**
* Iterates through {@code stream} sequentially and passes each element to {@code consumer}
* with exceptions propagated. For example:
*
* <pre>{@code
* void writeAll(Stream<?> stream, ObjectOutput out) throws IOException {
* iterateThrough(stream, out::writeObject);
* }
* }</pre>
*/
public static <T, E extends Throwable> void iterateThrough( | // Path: mug/src/main/java/com/google/mu/util/stream/BiStream.java
// public static <T> BiStream<T, T> biStream(Collection<T> elements) {
// return from(elements, identity(), identity());
// }
//
// Path: mug/src/main/java/com/google/mu/function/CheckedConsumer.java
// @FunctionalInterface
// public interface CheckedConsumer<T, E extends Throwable> {
// void accept(T input) throws E;
//
// /**
// * Returns a new {@code CheckedConsumer} that also passes the input to {@code that}.
// * For example: {@code out::writeObject.andThen(logger::info).accept("message")}.
// */
// default CheckedConsumer<T, E> andThen(CheckedConsumer<? super T, E> that) {
// requireNonNull(that);
// return input -> {
// accept(input);
// that.accept(input);
// };
// }
// }
// Path: mug/src/main/java/com/google/mu/util/stream/MoreStreams.java
import static com.google.mu.util.stream.BiStream.biStream;
import static java.util.Objects.requireNonNull;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.Queue;
import java.util.Spliterator;
import java.util.Spliterators.AbstractSpliterator;
import java.util.function.BiPredicate;
import java.util.function.BinaryOperator;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.stream.Collector;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.LongStream;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;
import com.google.mu.function.CheckedConsumer;
* The above is equivalent to manually doing:
*
* <pre>{@code
* Iterable<Foo> foos = stream::iterator;
* for (Foo foo : foos) {
* ...
* }
* }</pre>
* except using this API eliminates the need for a named variable that escapes the scope of the
* for-each loop. And code is more readable too.
*
* <p>Note that {@link #iterateThrough iterateThrough()} should be preferred whenever possible
* due to the caveats mentioned above. This method is still useful when the loop body needs to
* use control flows such as {@code break} or {@code return}.
*/
public static <T> Iterable<T> iterateOnce(Stream<T> stream) {
return stream::iterator;
}
/**
* Iterates through {@code stream} sequentially and passes each element to {@code consumer}
* with exceptions propagated. For example:
*
* <pre>{@code
* void writeAll(Stream<?> stream, ObjectOutput out) throws IOException {
* iterateThrough(stream, out::writeObject);
* }
* }</pre>
*/
public static <T, E extends Throwable> void iterateThrough( | Stream<? extends T> stream, CheckedConsumer<? super T, E> consumer) throws E { |
google/mug | mug/src/test/java/com/google/mu/util/stream/IterationTest.java | // Path: mug/src/test/java/com/google/mu/util/stream/IterationTest.java
// static <T> Node<T> tree(T value) {
// return new Node<>(value);
// }
| import static com.google.common.truth.Truth8.assertThat;
import static com.google.mu.util.stream.IterationTest.Tree.tree;
import static org.junit.jupiter.api.Assertions.assertThrows;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Stream;
import org.junit.Test;
import com.google.common.testing.ClassSanityTester; | /*****************************************************************************
* ------------------------------------------------------------------------- *
* Licensed under the Apache License, Version 2.0 (the "License"); *
* you may not use this file except in compliance with the License. *
* You may obtain a copy of the License at *
* *
* http://www.apache.org/licenses/LICENSE-2.0 *
* *
* Unless required by applicable law or agreed to in writing, software *
* distributed under the License is distributed on an "AS IS" BASIS, *
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
* See the License for the specific language governing permissions and *
* limitations under the License. *
*****************************************************************************/
package com.google.mu.util.stream;
public class IterationTest {
@Test public void iteration_empty() {
assertThat(new Iteration<Object>().iterate()).isEmpty();
}
@Test public void yield_eagerElements() {
assertThat(new Iteration<>().yield(1).yield(2).iterate()).containsExactly(1, 2).inOrder();
}
@Test public void preOrder_deep() { | // Path: mug/src/test/java/com/google/mu/util/stream/IterationTest.java
// static <T> Node<T> tree(T value) {
// return new Node<>(value);
// }
// Path: mug/src/test/java/com/google/mu/util/stream/IterationTest.java
import static com.google.common.truth.Truth8.assertThat;
import static com.google.mu.util.stream.IterationTest.Tree.tree;
import static org.junit.jupiter.api.Assertions.assertThrows;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Stream;
import org.junit.Test;
import com.google.common.testing.ClassSanityTester;
/*****************************************************************************
* ------------------------------------------------------------------------- *
* Licensed under the Apache License, Version 2.0 (the "License"); *
* you may not use this file except in compliance with the License. *
* You may obtain a copy of the License at *
* *
* http://www.apache.org/licenses/LICENSE-2.0 *
* *
* Unless required by applicable law or agreed to in writing, software *
* distributed under the License is distributed on an "AS IS" BASIS, *
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
* See the License for the specific language governing permissions and *
* limitations under the License. *
*****************************************************************************/
package com.google.mu.util.stream;
public class IterationTest {
@Test public void iteration_empty() {
assertThat(new Iteration<Object>().iterate()).isEmpty();
}
@Test public void yield_eagerElements() {
assertThat(new Iteration<>().yield(1).yield(2).iterate()).containsExactly(1, 2).inOrder();
}
@Test public void preOrder_deep() { | Tree<String> tree = tree("a") |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.