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 |
|---|---|---|---|---|---|---|
chirino/hawtbuf | hawtbuf-protoc/src/main/java/org/fusesource/hawtbuf/proto/compiler/AltJavaGenerator.java | // Path: hawtbuf-proto/src/main/java/org/fusesource/hawtbuf/proto/WireFormat.java
// public static final int WIRETYPE_FIXED32 = 5;
//
// Path: hawtbuf-proto/src/main/java/org/fusesource/hawtbuf/proto/WireFormat.java
// public static final int WIRETYPE_FIXED64 = 1;
//
// Path: hawtbuf-proto/src/main/java/org/fusesource/hawtbuf/proto/WireFormat.java
// public static final int WIRETYPE_LENGTH_DELIMITED = 2;
//
// Path: hawtbuf-proto/src/main/java/org/fusesource/hawtbuf/proto/WireFormat.java
// public static final int WIRETYPE_VARINT = 0;
//
// Path: hawtbuf-proto/src/main/java/org/fusesource/hawtbuf/proto/WireFormat.java
// public static int makeTag(int fieldNumber, int wireType) {
// return (fieldNumber << TAG_TYPE_BITS) | wireType;
// }
| import java.util.Map;
import java.util.StringTokenizer;
import org.fusesource.hawtbuf.proto.compiler.parser.ParseException;
import org.fusesource.hawtbuf.proto.compiler.parser.ProtoParser;
import static org.fusesource.hawtbuf.proto.WireFormat.WIRETYPE_FIXED32;
import static org.fusesource.hawtbuf.proto.WireFormat.WIRETYPE_FIXED64;
import static org.fusesource.hawtbuf.proto.WireFormat.WIRETYPE_LENGTH_DELIMITED;
import static org.fusesource.hawtbuf.proto.WireFormat.WIRETYPE_VARINT;
import static org.fusesource.hawtbuf.proto.WireFormat.makeTag;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.LinkedHashMap; |
for (FieldDescriptor field : m.getFields().values()) {
String uname = uCamel(field.getName());
String setter = "set" + uname;
boolean repeated = field.getRule() == FieldDescriptor.REPEATED_RULE;
if (repeated) {
setter = "create" + uname + "List().add";
}
if (field.getType() == FieldDescriptor.STRING_TYPE) {
p("case "
+ makeTag(field.getTag(),
WIRETYPE_LENGTH_DELIMITED) + ":");
indent();
p(setter + "(input.readString());");
} else if (field.getType() == FieldDescriptor.BYTES_TYPE) {
p("case " + makeTag(field.getTag(), WIRETYPE_LENGTH_DELIMITED) + ":");
indent();
String override = getOption(field.getOptions(), "java_override_type", null);
if ("AsciiBuffer".equals(override)) {
p(setter + "(new org.fusesource.hawtbuf.AsciiBuffer(input.readBytes()));");
} else if ("UTF8Buffer".equals(override)) {
p(setter + "(new org.fusesource.hawtbuf.UTF8Buffer(input.readBytes()));");
} else {
p(setter + "(input.readBytes());");
}
} else if (field.getType() == FieldDescriptor.BOOL_TYPE) {
p("case " + makeTag(field.getTag(), WIRETYPE_VARINT) + ":");
indent();
p(setter + "(input.readBool());");
} else if (field.getType() == FieldDescriptor.DOUBLE_TYPE) { | // Path: hawtbuf-proto/src/main/java/org/fusesource/hawtbuf/proto/WireFormat.java
// public static final int WIRETYPE_FIXED32 = 5;
//
// Path: hawtbuf-proto/src/main/java/org/fusesource/hawtbuf/proto/WireFormat.java
// public static final int WIRETYPE_FIXED64 = 1;
//
// Path: hawtbuf-proto/src/main/java/org/fusesource/hawtbuf/proto/WireFormat.java
// public static final int WIRETYPE_LENGTH_DELIMITED = 2;
//
// Path: hawtbuf-proto/src/main/java/org/fusesource/hawtbuf/proto/WireFormat.java
// public static final int WIRETYPE_VARINT = 0;
//
// Path: hawtbuf-proto/src/main/java/org/fusesource/hawtbuf/proto/WireFormat.java
// public static int makeTag(int fieldNumber, int wireType) {
// return (fieldNumber << TAG_TYPE_BITS) | wireType;
// }
// Path: hawtbuf-protoc/src/main/java/org/fusesource/hawtbuf/proto/compiler/AltJavaGenerator.java
import java.util.Map;
import java.util.StringTokenizer;
import org.fusesource.hawtbuf.proto.compiler.parser.ParseException;
import org.fusesource.hawtbuf.proto.compiler.parser.ProtoParser;
import static org.fusesource.hawtbuf.proto.WireFormat.WIRETYPE_FIXED32;
import static org.fusesource.hawtbuf.proto.WireFormat.WIRETYPE_FIXED64;
import static org.fusesource.hawtbuf.proto.WireFormat.WIRETYPE_LENGTH_DELIMITED;
import static org.fusesource.hawtbuf.proto.WireFormat.WIRETYPE_VARINT;
import static org.fusesource.hawtbuf.proto.WireFormat.makeTag;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.LinkedHashMap;
for (FieldDescriptor field : m.getFields().values()) {
String uname = uCamel(field.getName());
String setter = "set" + uname;
boolean repeated = field.getRule() == FieldDescriptor.REPEATED_RULE;
if (repeated) {
setter = "create" + uname + "List().add";
}
if (field.getType() == FieldDescriptor.STRING_TYPE) {
p("case "
+ makeTag(field.getTag(),
WIRETYPE_LENGTH_DELIMITED) + ":");
indent();
p(setter + "(input.readString());");
} else if (field.getType() == FieldDescriptor.BYTES_TYPE) {
p("case " + makeTag(field.getTag(), WIRETYPE_LENGTH_DELIMITED) + ":");
indent();
String override = getOption(field.getOptions(), "java_override_type", null);
if ("AsciiBuffer".equals(override)) {
p(setter + "(new org.fusesource.hawtbuf.AsciiBuffer(input.readBytes()));");
} else if ("UTF8Buffer".equals(override)) {
p(setter + "(new org.fusesource.hawtbuf.UTF8Buffer(input.readBytes()));");
} else {
p(setter + "(input.readBytes());");
}
} else if (field.getType() == FieldDescriptor.BOOL_TYPE) {
p("case " + makeTag(field.getTag(), WIRETYPE_VARINT) + ":");
indent();
p(setter + "(input.readBool());");
} else if (field.getType() == FieldDescriptor.DOUBLE_TYPE) { | p("case " + makeTag(field.getTag(), WIRETYPE_FIXED64) |
chirino/hawtbuf | hawtbuf-protoc/src/main/java/org/fusesource/hawtbuf/proto/compiler/AltJavaGenerator.java | // Path: hawtbuf-proto/src/main/java/org/fusesource/hawtbuf/proto/WireFormat.java
// public static final int WIRETYPE_FIXED32 = 5;
//
// Path: hawtbuf-proto/src/main/java/org/fusesource/hawtbuf/proto/WireFormat.java
// public static final int WIRETYPE_FIXED64 = 1;
//
// Path: hawtbuf-proto/src/main/java/org/fusesource/hawtbuf/proto/WireFormat.java
// public static final int WIRETYPE_LENGTH_DELIMITED = 2;
//
// Path: hawtbuf-proto/src/main/java/org/fusesource/hawtbuf/proto/WireFormat.java
// public static final int WIRETYPE_VARINT = 0;
//
// Path: hawtbuf-proto/src/main/java/org/fusesource/hawtbuf/proto/WireFormat.java
// public static int makeTag(int fieldNumber, int wireType) {
// return (fieldNumber << TAG_TYPE_BITS) | wireType;
// }
| import java.util.Map;
import java.util.StringTokenizer;
import org.fusesource.hawtbuf.proto.compiler.parser.ParseException;
import org.fusesource.hawtbuf.proto.compiler.parser.ProtoParser;
import static org.fusesource.hawtbuf.proto.WireFormat.WIRETYPE_FIXED32;
import static org.fusesource.hawtbuf.proto.WireFormat.WIRETYPE_FIXED64;
import static org.fusesource.hawtbuf.proto.WireFormat.WIRETYPE_LENGTH_DELIMITED;
import static org.fusesource.hawtbuf.proto.WireFormat.WIRETYPE_VARINT;
import static org.fusesource.hawtbuf.proto.WireFormat.makeTag;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.LinkedHashMap; | if (repeated) {
setter = "create" + uname + "List().add";
}
if (field.getType() == FieldDescriptor.STRING_TYPE) {
p("case "
+ makeTag(field.getTag(),
WIRETYPE_LENGTH_DELIMITED) + ":");
indent();
p(setter + "(input.readString());");
} else if (field.getType() == FieldDescriptor.BYTES_TYPE) {
p("case " + makeTag(field.getTag(), WIRETYPE_LENGTH_DELIMITED) + ":");
indent();
String override = getOption(field.getOptions(), "java_override_type", null);
if ("AsciiBuffer".equals(override)) {
p(setter + "(new org.fusesource.hawtbuf.AsciiBuffer(input.readBytes()));");
} else if ("UTF8Buffer".equals(override)) {
p(setter + "(new org.fusesource.hawtbuf.UTF8Buffer(input.readBytes()));");
} else {
p(setter + "(input.readBytes());");
}
} else if (field.getType() == FieldDescriptor.BOOL_TYPE) {
p("case " + makeTag(field.getTag(), WIRETYPE_VARINT) + ":");
indent();
p(setter + "(input.readBool());");
} else if (field.getType() == FieldDescriptor.DOUBLE_TYPE) {
p("case " + makeTag(field.getTag(), WIRETYPE_FIXED64)
+ ":");
indent();
p(setter + "(input.readDouble());");
} else if (field.getType() == FieldDescriptor.FLOAT_TYPE) { | // Path: hawtbuf-proto/src/main/java/org/fusesource/hawtbuf/proto/WireFormat.java
// public static final int WIRETYPE_FIXED32 = 5;
//
// Path: hawtbuf-proto/src/main/java/org/fusesource/hawtbuf/proto/WireFormat.java
// public static final int WIRETYPE_FIXED64 = 1;
//
// Path: hawtbuf-proto/src/main/java/org/fusesource/hawtbuf/proto/WireFormat.java
// public static final int WIRETYPE_LENGTH_DELIMITED = 2;
//
// Path: hawtbuf-proto/src/main/java/org/fusesource/hawtbuf/proto/WireFormat.java
// public static final int WIRETYPE_VARINT = 0;
//
// Path: hawtbuf-proto/src/main/java/org/fusesource/hawtbuf/proto/WireFormat.java
// public static int makeTag(int fieldNumber, int wireType) {
// return (fieldNumber << TAG_TYPE_BITS) | wireType;
// }
// Path: hawtbuf-protoc/src/main/java/org/fusesource/hawtbuf/proto/compiler/AltJavaGenerator.java
import java.util.Map;
import java.util.StringTokenizer;
import org.fusesource.hawtbuf.proto.compiler.parser.ParseException;
import org.fusesource.hawtbuf.proto.compiler.parser.ProtoParser;
import static org.fusesource.hawtbuf.proto.WireFormat.WIRETYPE_FIXED32;
import static org.fusesource.hawtbuf.proto.WireFormat.WIRETYPE_FIXED64;
import static org.fusesource.hawtbuf.proto.WireFormat.WIRETYPE_LENGTH_DELIMITED;
import static org.fusesource.hawtbuf.proto.WireFormat.WIRETYPE_VARINT;
import static org.fusesource.hawtbuf.proto.WireFormat.makeTag;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.LinkedHashMap;
if (repeated) {
setter = "create" + uname + "List().add";
}
if (field.getType() == FieldDescriptor.STRING_TYPE) {
p("case "
+ makeTag(field.getTag(),
WIRETYPE_LENGTH_DELIMITED) + ":");
indent();
p(setter + "(input.readString());");
} else if (field.getType() == FieldDescriptor.BYTES_TYPE) {
p("case " + makeTag(field.getTag(), WIRETYPE_LENGTH_DELIMITED) + ":");
indent();
String override = getOption(field.getOptions(), "java_override_type", null);
if ("AsciiBuffer".equals(override)) {
p(setter + "(new org.fusesource.hawtbuf.AsciiBuffer(input.readBytes()));");
} else if ("UTF8Buffer".equals(override)) {
p(setter + "(new org.fusesource.hawtbuf.UTF8Buffer(input.readBytes()));");
} else {
p(setter + "(input.readBytes());");
}
} else if (field.getType() == FieldDescriptor.BOOL_TYPE) {
p("case " + makeTag(field.getTag(), WIRETYPE_VARINT) + ":");
indent();
p(setter + "(input.readBool());");
} else if (field.getType() == FieldDescriptor.DOUBLE_TYPE) {
p("case " + makeTag(field.getTag(), WIRETYPE_FIXED64)
+ ":");
indent();
p(setter + "(input.readDouble());");
} else if (field.getType() == FieldDescriptor.FLOAT_TYPE) { | p("case " + makeTag(field.getTag(), WIRETYPE_FIXED32) |
njustesen/hero-aicademy | src/ai/mcts/MctsNode.java | // Path: src/action/Action.java
// public abstract class Action {
//
// }
| import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import action.Action; | package ai.mcts;
public class MctsNode {
public List<MctsEdge> in;
public List<MctsEdge> out; | // Path: src/action/Action.java
// public abstract class Action {
//
// }
// Path: src/ai/mcts/MctsNode.java
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import action.Action;
package ai.mcts;
public class MctsNode {
public List<MctsEdge> in;
public List<MctsEdge> out; | List<Action> possible; |
njustesen/hero-aicademy | src/ai/evolution/MinGenome.java | // Path: src/action/Action.java
// public abstract class Action {
//
// }
| import java.util.ArrayList;
import action.Action; | package ai.evolution;
public class MinGenome extends Genome {
public MinGenome() {
super(); | // Path: src/action/Action.java
// public abstract class Action {
//
// }
// Path: src/ai/evolution/MinGenome.java
import java.util.ArrayList;
import action.Action;
package ai.evolution;
public class MinGenome extends Genome {
public MinGenome() {
super(); | actions = new ArrayList<Action>(); |
njustesen/hero-aicademy | src/ai/evolution/WeakGenome.java | // Path: src/action/Action.java
// public abstract class Action {
//
// }
| import java.util.ArrayList;
import action.Action; | package ai.evolution;
public class WeakGenome extends Genome {
public WeakGenome() {
super(); | // Path: src/action/Action.java
// public abstract class Action {
//
// }
// Path: src/ai/evolution/WeakGenome.java
import java.util.ArrayList;
import action.Action;
package ai.evolution;
public class WeakGenome extends Genome {
public WeakGenome() {
super(); | actions = new ArrayList<Action>(); |
njustesen/hero-aicademy | src/action/DropAction.java | // Path: src/model/Card.java
// public enum Card {
//
// KNIGHT(CardType.UNIT),
// ARCHER(CardType.UNIT),
// CLERIC(CardType.UNIT),
// WIZARD(CardType.UNIT),
// NINJA(CardType.UNIT),
// INFERNO(CardType.SPELL),
// REVIVE_POTION(CardType.ITEM),
// RUNEMETAL(CardType.ITEM),
// SCROLL(CardType.ITEM),
// DRAGONSCALE(CardType.ITEM),
// SHINING_HELM(CardType.ITEM),
// CRYSTAL(CardType.UNIT);
//
// public final CardType type;
//
// Card(CardType type) {
// this.type = type;
// }
//
// }
//
// Path: src/model/Position.java
// public class Position {
//
// public int x;
// public int y;
//
// public Position(int x, int y) {
// super();
// this.x = x;
// this.y = y;
// }
//
// public Position() {
// super();
// x = 0;
// y = 0;
// }
//
// public Direction getDirection(Position pos) {
// if (pos == null)
// return null;
// return Direction.direction(pos.x - x, pos.y - y);
// }
//
// public int hashCode() {
// int result = 1;
// result = 5 * result + x;
// result = 5 * result + y;
// return result;
// }
//
// @Override
// public String toString() {
// return "(" + x + "," + y + ")";
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj)
// return true;
// if (obj == null)
// return false;
// if (getClass() != obj.getClass())
// return false;
// final Position other = (Position) obj;
// if (x != other.x)
// return false;
// if (y != other.y)
// return false;
// return true;
// }
//
// public int distance(Position to) {
// int xx = x - to.x;
// if (xx < 0)
// xx = xx * (-1);
// int yy = y - to.y;
// if (yy < 0)
// yy = yy * (-1);
// return xx + yy;
// }
//
// }
| import model.Card;
import model.Position; | package action;
public class DropAction extends Action {
public Card type; | // Path: src/model/Card.java
// public enum Card {
//
// KNIGHT(CardType.UNIT),
// ARCHER(CardType.UNIT),
// CLERIC(CardType.UNIT),
// WIZARD(CardType.UNIT),
// NINJA(CardType.UNIT),
// INFERNO(CardType.SPELL),
// REVIVE_POTION(CardType.ITEM),
// RUNEMETAL(CardType.ITEM),
// SCROLL(CardType.ITEM),
// DRAGONSCALE(CardType.ITEM),
// SHINING_HELM(CardType.ITEM),
// CRYSTAL(CardType.UNIT);
//
// public final CardType type;
//
// Card(CardType type) {
// this.type = type;
// }
//
// }
//
// Path: src/model/Position.java
// public class Position {
//
// public int x;
// public int y;
//
// public Position(int x, int y) {
// super();
// this.x = x;
// this.y = y;
// }
//
// public Position() {
// super();
// x = 0;
// y = 0;
// }
//
// public Direction getDirection(Position pos) {
// if (pos == null)
// return null;
// return Direction.direction(pos.x - x, pos.y - y);
// }
//
// public int hashCode() {
// int result = 1;
// result = 5 * result + x;
// result = 5 * result + y;
// return result;
// }
//
// @Override
// public String toString() {
// return "(" + x + "," + y + ")";
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj)
// return true;
// if (obj == null)
// return false;
// if (getClass() != obj.getClass())
// return false;
// final Position other = (Position) obj;
// if (x != other.x)
// return false;
// if (y != other.y)
// return false;
// return true;
// }
//
// public int distance(Position to) {
// int xx = x - to.x;
// if (xx < 0)
// xx = xx * (-1);
// int yy = y - to.y;
// if (yy < 0)
// yy = yy * (-1);
// return xx + yy;
// }
//
// }
// Path: src/action/DropAction.java
import model.Card;
import model.Position;
package action;
public class DropAction extends Action {
public Card type; | public Position to; |
njustesen/hero-aicademy | src/util/MapLoader.java | // Path: src/model/HaMap.java
// public class HaMap {
//
// public String name;
// public int width;
// public int height;
// public SquareType[][] squares;
// public List<Position> assaultSquares;
// public List<Position> p1DeploySquares;
// public List<Position> p2DeploySquares;
// public List<Position> p1Crystals;
// public List<Position> p2Crystals;
//
// public HaMap(int width, int height, SquareType[][] squares, String name) {
// super();
// this.name = name;
// this.width = width;
// this.height = height;
// this.squares = squares;
// assaultSquares = new ArrayList<Position>();
// p1DeploySquares = new ArrayList<Position>();
// p2DeploySquares = new ArrayList<Position>();
// p1Crystals = new ArrayList<Position>();
// p2Crystals = new ArrayList<Position>();
// for (int x = 0; x < squares.length; x++)
// for (int y = 0; y < squares[0].length; y++) {
// if (squares[x][y] == SquareType.DEPLOY_1)
// p1DeploySquares.add(new Position(x, y));
// if (squares[x][y] == SquareType.DEPLOY_2)
// p2DeploySquares.add(new Position(x, y));
// if (squares[x][y] == SquareType.ASSAULT)
// assaultSquares.add(new Position(x, y));
// }
// }
//
// public SquareType squareAt(int x, int y) {
//
// return squares[x][y];
//
// }
//
// public SquareType squareAt(Position position) {
// return squareAt(position.x, position.y);
// }
//
// }
//
// Path: src/model/Position.java
// public class Position {
//
// public int x;
// public int y;
//
// public Position(int x, int y) {
// super();
// this.x = x;
// this.y = y;
// }
//
// public Position() {
// super();
// x = 0;
// y = 0;
// }
//
// public Direction getDirection(Position pos) {
// if (pos == null)
// return null;
// return Direction.direction(pos.x - x, pos.y - y);
// }
//
// public int hashCode() {
// int result = 1;
// result = 5 * result + x;
// result = 5 * result + y;
// return result;
// }
//
// @Override
// public String toString() {
// return "(" + x + "," + y + ")";
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj)
// return true;
// if (obj == null)
// return false;
// if (getClass() != obj.getClass())
// return false;
// final Position other = (Position) obj;
// if (x != other.x)
// return false;
// if (y != other.y)
// return false;
// return true;
// }
//
// public int distance(Position to) {
// int xx = x - to.x;
// if (xx < 0)
// xx = xx * (-1);
// int yy = y - to.y;
// if (yy < 0)
// yy = yy * (-1);
// return xx + yy;
// }
//
// }
//
// Path: src/model/SquareType.java
// public enum SquareType {
//
// NONE, ASSAULT, DEFENSE, POWER, DEPLOY_1, DEPLOY_2;
//
// }
| import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import model.HaMap;
import model.Position;
import model.SquareType; | package util;
public class MapLoader {
private static final char P1CRYSTAL = 'c';
private static final char P2CRYSTAL = 'C'; | // Path: src/model/HaMap.java
// public class HaMap {
//
// public String name;
// public int width;
// public int height;
// public SquareType[][] squares;
// public List<Position> assaultSquares;
// public List<Position> p1DeploySquares;
// public List<Position> p2DeploySquares;
// public List<Position> p1Crystals;
// public List<Position> p2Crystals;
//
// public HaMap(int width, int height, SquareType[][] squares, String name) {
// super();
// this.name = name;
// this.width = width;
// this.height = height;
// this.squares = squares;
// assaultSquares = new ArrayList<Position>();
// p1DeploySquares = new ArrayList<Position>();
// p2DeploySquares = new ArrayList<Position>();
// p1Crystals = new ArrayList<Position>();
// p2Crystals = new ArrayList<Position>();
// for (int x = 0; x < squares.length; x++)
// for (int y = 0; y < squares[0].length; y++) {
// if (squares[x][y] == SquareType.DEPLOY_1)
// p1DeploySquares.add(new Position(x, y));
// if (squares[x][y] == SquareType.DEPLOY_2)
// p2DeploySquares.add(new Position(x, y));
// if (squares[x][y] == SquareType.ASSAULT)
// assaultSquares.add(new Position(x, y));
// }
// }
//
// public SquareType squareAt(int x, int y) {
//
// return squares[x][y];
//
// }
//
// public SquareType squareAt(Position position) {
// return squareAt(position.x, position.y);
// }
//
// }
//
// Path: src/model/Position.java
// public class Position {
//
// public int x;
// public int y;
//
// public Position(int x, int y) {
// super();
// this.x = x;
// this.y = y;
// }
//
// public Position() {
// super();
// x = 0;
// y = 0;
// }
//
// public Direction getDirection(Position pos) {
// if (pos == null)
// return null;
// return Direction.direction(pos.x - x, pos.y - y);
// }
//
// public int hashCode() {
// int result = 1;
// result = 5 * result + x;
// result = 5 * result + y;
// return result;
// }
//
// @Override
// public String toString() {
// return "(" + x + "," + y + ")";
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj)
// return true;
// if (obj == null)
// return false;
// if (getClass() != obj.getClass())
// return false;
// final Position other = (Position) obj;
// if (x != other.x)
// return false;
// if (y != other.y)
// return false;
// return true;
// }
//
// public int distance(Position to) {
// int xx = x - to.x;
// if (xx < 0)
// xx = xx * (-1);
// int yy = y - to.y;
// if (yy < 0)
// yy = yy * (-1);
// return xx + yy;
// }
//
// }
//
// Path: src/model/SquareType.java
// public enum SquareType {
//
// NONE, ASSAULT, DEFENSE, POWER, DEPLOY_1, DEPLOY_2;
//
// }
// Path: src/util/MapLoader.java
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import model.HaMap;
import model.Position;
import model.SquareType;
package util;
public class MapLoader {
private static final char P1CRYSTAL = 'c';
private static final char P2CRYSTAL = 'C'; | static Map<Character, SquareType> codes = new HashMap<Character, SquareType>(); |
njustesen/hero-aicademy | src/util/MapLoader.java | // Path: src/model/HaMap.java
// public class HaMap {
//
// public String name;
// public int width;
// public int height;
// public SquareType[][] squares;
// public List<Position> assaultSquares;
// public List<Position> p1DeploySquares;
// public List<Position> p2DeploySquares;
// public List<Position> p1Crystals;
// public List<Position> p2Crystals;
//
// public HaMap(int width, int height, SquareType[][] squares, String name) {
// super();
// this.name = name;
// this.width = width;
// this.height = height;
// this.squares = squares;
// assaultSquares = new ArrayList<Position>();
// p1DeploySquares = new ArrayList<Position>();
// p2DeploySquares = new ArrayList<Position>();
// p1Crystals = new ArrayList<Position>();
// p2Crystals = new ArrayList<Position>();
// for (int x = 0; x < squares.length; x++)
// for (int y = 0; y < squares[0].length; y++) {
// if (squares[x][y] == SquareType.DEPLOY_1)
// p1DeploySquares.add(new Position(x, y));
// if (squares[x][y] == SquareType.DEPLOY_2)
// p2DeploySquares.add(new Position(x, y));
// if (squares[x][y] == SquareType.ASSAULT)
// assaultSquares.add(new Position(x, y));
// }
// }
//
// public SquareType squareAt(int x, int y) {
//
// return squares[x][y];
//
// }
//
// public SquareType squareAt(Position position) {
// return squareAt(position.x, position.y);
// }
//
// }
//
// Path: src/model/Position.java
// public class Position {
//
// public int x;
// public int y;
//
// public Position(int x, int y) {
// super();
// this.x = x;
// this.y = y;
// }
//
// public Position() {
// super();
// x = 0;
// y = 0;
// }
//
// public Direction getDirection(Position pos) {
// if (pos == null)
// return null;
// return Direction.direction(pos.x - x, pos.y - y);
// }
//
// public int hashCode() {
// int result = 1;
// result = 5 * result + x;
// result = 5 * result + y;
// return result;
// }
//
// @Override
// public String toString() {
// return "(" + x + "," + y + ")";
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj)
// return true;
// if (obj == null)
// return false;
// if (getClass() != obj.getClass())
// return false;
// final Position other = (Position) obj;
// if (x != other.x)
// return false;
// if (y != other.y)
// return false;
// return true;
// }
//
// public int distance(Position to) {
// int xx = x - to.x;
// if (xx < 0)
// xx = xx * (-1);
// int yy = y - to.y;
// if (yy < 0)
// yy = yy * (-1);
// return xx + yy;
// }
//
// }
//
// Path: src/model/SquareType.java
// public enum SquareType {
//
// NONE, ASSAULT, DEFENSE, POWER, DEPLOY_1, DEPLOY_2;
//
// }
| import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import model.HaMap;
import model.Position;
import model.SquareType; | package util;
public class MapLoader {
private static final char P1CRYSTAL = 'c';
private static final char P2CRYSTAL = 'C';
static Map<Character, SquareType> codes = new HashMap<Character, SquareType>();
static {
codes.put('0', SquareType.NONE);
codes.put('d', SquareType.DEPLOY_1);
codes.put('D', SquareType.DEPLOY_2);
codes.put('S', SquareType.DEFENSE);
codes.put('A', SquareType.ASSAULT);
codes.put('P', SquareType.POWER);
codes.put('c', SquareType.NONE);
codes.put('C', SquareType.NONE);
//codes.put('H', SquareType.);
} | // Path: src/model/HaMap.java
// public class HaMap {
//
// public String name;
// public int width;
// public int height;
// public SquareType[][] squares;
// public List<Position> assaultSquares;
// public List<Position> p1DeploySquares;
// public List<Position> p2DeploySquares;
// public List<Position> p1Crystals;
// public List<Position> p2Crystals;
//
// public HaMap(int width, int height, SquareType[][] squares, String name) {
// super();
// this.name = name;
// this.width = width;
// this.height = height;
// this.squares = squares;
// assaultSquares = new ArrayList<Position>();
// p1DeploySquares = new ArrayList<Position>();
// p2DeploySquares = new ArrayList<Position>();
// p1Crystals = new ArrayList<Position>();
// p2Crystals = new ArrayList<Position>();
// for (int x = 0; x < squares.length; x++)
// for (int y = 0; y < squares[0].length; y++) {
// if (squares[x][y] == SquareType.DEPLOY_1)
// p1DeploySquares.add(new Position(x, y));
// if (squares[x][y] == SquareType.DEPLOY_2)
// p2DeploySquares.add(new Position(x, y));
// if (squares[x][y] == SquareType.ASSAULT)
// assaultSquares.add(new Position(x, y));
// }
// }
//
// public SquareType squareAt(int x, int y) {
//
// return squares[x][y];
//
// }
//
// public SquareType squareAt(Position position) {
// return squareAt(position.x, position.y);
// }
//
// }
//
// Path: src/model/Position.java
// public class Position {
//
// public int x;
// public int y;
//
// public Position(int x, int y) {
// super();
// this.x = x;
// this.y = y;
// }
//
// public Position() {
// super();
// x = 0;
// y = 0;
// }
//
// public Direction getDirection(Position pos) {
// if (pos == null)
// return null;
// return Direction.direction(pos.x - x, pos.y - y);
// }
//
// public int hashCode() {
// int result = 1;
// result = 5 * result + x;
// result = 5 * result + y;
// return result;
// }
//
// @Override
// public String toString() {
// return "(" + x + "," + y + ")";
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj)
// return true;
// if (obj == null)
// return false;
// if (getClass() != obj.getClass())
// return false;
// final Position other = (Position) obj;
// if (x != other.x)
// return false;
// if (y != other.y)
// return false;
// return true;
// }
//
// public int distance(Position to) {
// int xx = x - to.x;
// if (xx < 0)
// xx = xx * (-1);
// int yy = y - to.y;
// if (yy < 0)
// yy = yy * (-1);
// return xx + yy;
// }
//
// }
//
// Path: src/model/SquareType.java
// public enum SquareType {
//
// NONE, ASSAULT, DEFENSE, POWER, DEPLOY_1, DEPLOY_2;
//
// }
// Path: src/util/MapLoader.java
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import model.HaMap;
import model.Position;
import model.SquareType;
package util;
public class MapLoader {
private static final char P1CRYSTAL = 'c';
private static final char P2CRYSTAL = 'C';
static Map<Character, SquareType> codes = new HashMap<Character, SquareType>();
static {
codes.put('0', SquareType.NONE);
codes.put('d', SquareType.DEPLOY_1);
codes.put('D', SquareType.DEPLOY_2);
codes.put('S', SquareType.DEFENSE);
codes.put('A', SquareType.ASSAULT);
codes.put('P', SquareType.POWER);
codes.put('c', SquareType.NONE);
codes.put('C', SquareType.NONE);
//codes.put('H', SquareType.);
} | static Map<String, HaMap> maps = new HashMap<String, HaMap>(); |
njustesen/hero-aicademy | src/util/MapLoader.java | // Path: src/model/HaMap.java
// public class HaMap {
//
// public String name;
// public int width;
// public int height;
// public SquareType[][] squares;
// public List<Position> assaultSquares;
// public List<Position> p1DeploySquares;
// public List<Position> p2DeploySquares;
// public List<Position> p1Crystals;
// public List<Position> p2Crystals;
//
// public HaMap(int width, int height, SquareType[][] squares, String name) {
// super();
// this.name = name;
// this.width = width;
// this.height = height;
// this.squares = squares;
// assaultSquares = new ArrayList<Position>();
// p1DeploySquares = new ArrayList<Position>();
// p2DeploySquares = new ArrayList<Position>();
// p1Crystals = new ArrayList<Position>();
// p2Crystals = new ArrayList<Position>();
// for (int x = 0; x < squares.length; x++)
// for (int y = 0; y < squares[0].length; y++) {
// if (squares[x][y] == SquareType.DEPLOY_1)
// p1DeploySquares.add(new Position(x, y));
// if (squares[x][y] == SquareType.DEPLOY_2)
// p2DeploySquares.add(new Position(x, y));
// if (squares[x][y] == SquareType.ASSAULT)
// assaultSquares.add(new Position(x, y));
// }
// }
//
// public SquareType squareAt(int x, int y) {
//
// return squares[x][y];
//
// }
//
// public SquareType squareAt(Position position) {
// return squareAt(position.x, position.y);
// }
//
// }
//
// Path: src/model/Position.java
// public class Position {
//
// public int x;
// public int y;
//
// public Position(int x, int y) {
// super();
// this.x = x;
// this.y = y;
// }
//
// public Position() {
// super();
// x = 0;
// y = 0;
// }
//
// public Direction getDirection(Position pos) {
// if (pos == null)
// return null;
// return Direction.direction(pos.x - x, pos.y - y);
// }
//
// public int hashCode() {
// int result = 1;
// result = 5 * result + x;
// result = 5 * result + y;
// return result;
// }
//
// @Override
// public String toString() {
// return "(" + x + "," + y + ")";
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj)
// return true;
// if (obj == null)
// return false;
// if (getClass() != obj.getClass())
// return false;
// final Position other = (Position) obj;
// if (x != other.x)
// return false;
// if (y != other.y)
// return false;
// return true;
// }
//
// public int distance(Position to) {
// int xx = x - to.x;
// if (xx < 0)
// xx = xx * (-1);
// int yy = y - to.y;
// if (yy < 0)
// yy = yy * (-1);
// return xx + yy;
// }
//
// }
//
// Path: src/model/SquareType.java
// public enum SquareType {
//
// NONE, ASSAULT, DEFENSE, POWER, DEPLOY_1, DEPLOY_2;
//
// }
| import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import model.HaMap;
import model.Position;
import model.SquareType; | package util;
public class MapLoader {
private static final char P1CRYSTAL = 'c';
private static final char P2CRYSTAL = 'C';
static Map<Character, SquareType> codes = new HashMap<Character, SquareType>();
static {
codes.put('0', SquareType.NONE);
codes.put('d', SquareType.DEPLOY_1);
codes.put('D', SquareType.DEPLOY_2);
codes.put('S', SquareType.DEFENSE);
codes.put('A', SquareType.ASSAULT);
codes.put('P', SquareType.POWER);
codes.put('c', SquareType.NONE);
codes.put('C', SquareType.NONE);
//codes.put('H', SquareType.);
}
static Map<String, HaMap> maps = new HashMap<String, HaMap>();
public static HaMap get(String name) throws IOException{
if (maps.containsKey(name))
return maps.get(name);
else
load (name);
return get(name);
}
public static void load(String name) throws IOException{
String basePath = PathHelper.basePath();
List<String> lines = readLines(basePath + "/maps/"+name+".mhap");
| // Path: src/model/HaMap.java
// public class HaMap {
//
// public String name;
// public int width;
// public int height;
// public SquareType[][] squares;
// public List<Position> assaultSquares;
// public List<Position> p1DeploySquares;
// public List<Position> p2DeploySquares;
// public List<Position> p1Crystals;
// public List<Position> p2Crystals;
//
// public HaMap(int width, int height, SquareType[][] squares, String name) {
// super();
// this.name = name;
// this.width = width;
// this.height = height;
// this.squares = squares;
// assaultSquares = new ArrayList<Position>();
// p1DeploySquares = new ArrayList<Position>();
// p2DeploySquares = new ArrayList<Position>();
// p1Crystals = new ArrayList<Position>();
// p2Crystals = new ArrayList<Position>();
// for (int x = 0; x < squares.length; x++)
// for (int y = 0; y < squares[0].length; y++) {
// if (squares[x][y] == SquareType.DEPLOY_1)
// p1DeploySquares.add(new Position(x, y));
// if (squares[x][y] == SquareType.DEPLOY_2)
// p2DeploySquares.add(new Position(x, y));
// if (squares[x][y] == SquareType.ASSAULT)
// assaultSquares.add(new Position(x, y));
// }
// }
//
// public SquareType squareAt(int x, int y) {
//
// return squares[x][y];
//
// }
//
// public SquareType squareAt(Position position) {
// return squareAt(position.x, position.y);
// }
//
// }
//
// Path: src/model/Position.java
// public class Position {
//
// public int x;
// public int y;
//
// public Position(int x, int y) {
// super();
// this.x = x;
// this.y = y;
// }
//
// public Position() {
// super();
// x = 0;
// y = 0;
// }
//
// public Direction getDirection(Position pos) {
// if (pos == null)
// return null;
// return Direction.direction(pos.x - x, pos.y - y);
// }
//
// public int hashCode() {
// int result = 1;
// result = 5 * result + x;
// result = 5 * result + y;
// return result;
// }
//
// @Override
// public String toString() {
// return "(" + x + "," + y + ")";
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj)
// return true;
// if (obj == null)
// return false;
// if (getClass() != obj.getClass())
// return false;
// final Position other = (Position) obj;
// if (x != other.x)
// return false;
// if (y != other.y)
// return false;
// return true;
// }
//
// public int distance(Position to) {
// int xx = x - to.x;
// if (xx < 0)
// xx = xx * (-1);
// int yy = y - to.y;
// if (yy < 0)
// yy = yy * (-1);
// return xx + yy;
// }
//
// }
//
// Path: src/model/SquareType.java
// public enum SquareType {
//
// NONE, ASSAULT, DEFENSE, POWER, DEPLOY_1, DEPLOY_2;
//
// }
// Path: src/util/MapLoader.java
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import model.HaMap;
import model.Position;
import model.SquareType;
package util;
public class MapLoader {
private static final char P1CRYSTAL = 'c';
private static final char P2CRYSTAL = 'C';
static Map<Character, SquareType> codes = new HashMap<Character, SquareType>();
static {
codes.put('0', SquareType.NONE);
codes.put('d', SquareType.DEPLOY_1);
codes.put('D', SquareType.DEPLOY_2);
codes.put('S', SquareType.DEFENSE);
codes.put('A', SquareType.ASSAULT);
codes.put('P', SquareType.POWER);
codes.put('c', SquareType.NONE);
codes.put('C', SquareType.NONE);
//codes.put('H', SquareType.);
}
static Map<String, HaMap> maps = new HashMap<String, HaMap>();
public static HaMap get(String name) throws IOException{
if (maps.containsKey(name))
return maps.get(name);
else
load (name);
return get(name);
}
public static void load(String name) throws IOException{
String basePath = PathHelper.basePath();
List<String> lines = readLines(basePath + "/maps/"+name+".mhap");
| List<Position> p1Crystals = new ArrayList<Position>(); |
njustesen/hero-aicademy | src/model/team/Council.java | // Path: src/model/Card.java
// public enum Card {
//
// KNIGHT(CardType.UNIT),
// ARCHER(CardType.UNIT),
// CLERIC(CardType.UNIT),
// WIZARD(CardType.UNIT),
// NINJA(CardType.UNIT),
// INFERNO(CardType.SPELL),
// REVIVE_POTION(CardType.ITEM),
// RUNEMETAL(CardType.ITEM),
// SCROLL(CardType.ITEM),
// DRAGONSCALE(CardType.ITEM),
// SHINING_HELM(CardType.ITEM),
// CRYSTAL(CardType.UNIT);
//
// public final CardType type;
//
// Card(CardType type) {
// this.type = type;
// }
//
// }
//
// Path: src/model/DECK_SIZE.java
// public enum DECK_SIZE {
// STANDARD, SMALL, TINY;
// }
| import java.util.ArrayList;
import java.util.List;
import model.Card;
import model.DECK_SIZE; |
}
public static List<Card> tinyDeck;
static {
tinyDeck = new ArrayList<Card>();
tinyDeck.add(Card.KNIGHT);
tinyDeck.add(Card.ARCHER);
tinyDeck.add(Card.CLERIC);
tinyDeck.add(Card.WIZARD);
tinyDeck.add(Card.NINJA);
tinyDeck.add(Card.INFERNO);
tinyDeck.add(Card.RUNEMETAL);
tinyDeck.add(Card.DRAGONSCALE);
tinyDeck.add(Card.SHINING_HELM);
tinyDeck.add(Card.REVIVE_POTION);
tinyDeck.add(Card.SCROLL);
} | // Path: src/model/Card.java
// public enum Card {
//
// KNIGHT(CardType.UNIT),
// ARCHER(CardType.UNIT),
// CLERIC(CardType.UNIT),
// WIZARD(CardType.UNIT),
// NINJA(CardType.UNIT),
// INFERNO(CardType.SPELL),
// REVIVE_POTION(CardType.ITEM),
// RUNEMETAL(CardType.ITEM),
// SCROLL(CardType.ITEM),
// DRAGONSCALE(CardType.ITEM),
// SHINING_HELM(CardType.ITEM),
// CRYSTAL(CardType.UNIT);
//
// public final CardType type;
//
// Card(CardType type) {
// this.type = type;
// }
//
// }
//
// Path: src/model/DECK_SIZE.java
// public enum DECK_SIZE {
// STANDARD, SMALL, TINY;
// }
// Path: src/model/team/Council.java
import java.util.ArrayList;
import java.util.List;
import model.Card;
import model.DECK_SIZE;
}
public static List<Card> tinyDeck;
static {
tinyDeck = new ArrayList<Card>();
tinyDeck.add(Card.KNIGHT);
tinyDeck.add(Card.ARCHER);
tinyDeck.add(Card.CLERIC);
tinyDeck.add(Card.WIZARD);
tinyDeck.add(Card.NINJA);
tinyDeck.add(Card.INFERNO);
tinyDeck.add(Card.RUNEMETAL);
tinyDeck.add(Card.DRAGONSCALE);
tinyDeck.add(Card.SHINING_HELM);
tinyDeck.add(Card.REVIVE_POTION);
tinyDeck.add(Card.SCROLL);
} | public static List<Card> deck(DECK_SIZE deckSize) { |
njustesen/hero-aicademy | src/ai/util/AiStatistics.java | // Path: src/util/Statistics.java
// public class Statistics {
//
// public static double avgDouble(List<Double> vals){
//
// double sum = 0;
// for(double d : vals)
// sum += d;
//
// return sum / vals.size();
//
// }
//
// public static double avgInteger(List<Integer> vals){
//
// double sum = 0;
// for(int d : vals)
// sum += d;
//
// return sum / vals.size();
//
// }
//
// public static double stdDevDouble(List<Double> vals){
//
// double avg = avgDouble(vals);
//
// double sum = 0;
// for(double d : vals)
// sum += (d - avg) * (d - avg);
//
// double davg = sum / vals.size();
//
// return Math.sqrt(davg);
//
// }
//
// public static double stdDevInteger(List<Integer> vals){
//
// double avg = avgInteger(vals);
//
// double sum = 0;
// for(double d : vals)
// sum += (d - avg) * (d - avg);
//
// double davg = sum / vals.size();
//
// return Math.sqrt(davg);
//
// }
//
// public static int max(List<Integer> vals) {
//
// int min = Integer.MIN_VALUE;
//
// for(int n : vals)
// if (n > min)
// min = n;
//
// return min;
// }
//
// }
| import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import util.Statistics; | package ai.util;
public class AiStatistics {
public Map<String, Double> stats;
public Map<String, List<Double>> statsLists;
public AiStatistics() {
super();
this.stats = new HashMap<String, Double>();
this.statsLists = new HashMap<String, List<Double>>();
}
@Override
public String toString() {
String str = "";
for(String key : stats.keySet())
str += key + " = "+ stats.get(key) + "\n";
for(String key : statsLists.keySet()){
if (statsLists.get(key) == null || statsLists.get(key).isEmpty())
continue; | // Path: src/util/Statistics.java
// public class Statistics {
//
// public static double avgDouble(List<Double> vals){
//
// double sum = 0;
// for(double d : vals)
// sum += d;
//
// return sum / vals.size();
//
// }
//
// public static double avgInteger(List<Integer> vals){
//
// double sum = 0;
// for(int d : vals)
// sum += d;
//
// return sum / vals.size();
//
// }
//
// public static double stdDevDouble(List<Double> vals){
//
// double avg = avgDouble(vals);
//
// double sum = 0;
// for(double d : vals)
// sum += (d - avg) * (d - avg);
//
// double davg = sum / vals.size();
//
// return Math.sqrt(davg);
//
// }
//
// public static double stdDevInteger(List<Integer> vals){
//
// double avg = avgInteger(vals);
//
// double sum = 0;
// for(double d : vals)
// sum += (d - avg) * (d - avg);
//
// double davg = sum / vals.size();
//
// return Math.sqrt(davg);
//
// }
//
// public static int max(List<Integer> vals) {
//
// int min = Integer.MIN_VALUE;
//
// for(int n : vals)
// if (n > min)
// min = n;
//
// return min;
// }
//
// }
// Path: src/ai/util/AiStatistics.java
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import util.Statistics;
package ai.util;
public class AiStatistics {
public Map<String, Double> stats;
public Map<String, List<Double>> statsLists;
public AiStatistics() {
super();
this.stats = new HashMap<String, Double>();
this.statsLists = new HashMap<String, List<Double>>();
}
@Override
public String toString() {
String str = "";
for(String key : stats.keySet())
str += key + " = "+ stats.get(key) + "\n";
for(String key : statsLists.keySet()){
if (statsLists.get(key) == null || statsLists.get(key).isEmpty())
continue; | str += key + " (avg) = "+ Statistics.avgDouble(statsLists.get(key)) + "\n"; |
njustesen/hero-aicademy | src/ai/mcts/MctsEdge.java | // Path: src/action/Action.java
// public abstract class Action {
//
// }
| import java.util.HashSet;
import java.util.List;
import action.Action; | package ai.mcts;
public class MctsEdge {
public int visits;
public double value;
public boolean p1;
public MctsNode from;
public MctsNode to; | // Path: src/action/Action.java
// public abstract class Action {
//
// }
// Path: src/ai/mcts/MctsEdge.java
import java.util.HashSet;
import java.util.List;
import action.Action;
package ai.mcts;
public class MctsEdge {
public int visits;
public double value;
public boolean p1;
public MctsNode from;
public MctsNode to; | public Action action; |
njustesen/hero-aicademy | src/libs/ImageLib.java | // Path: src/util/PathHelper.java
// public class PathHelper {
//
// static String basePath = "";
//
// public static String basePath(){
// if (basePath != "")
// return basePath;
// try {
// final String path = PathHelper.class.getProtectionDomain()
// .getCodeSource().getLocation().toURI().getPath();
// final String[] folders = path.split("/");
// for (int i = 0; i < folders.length - 1; i++) {
// basePath += folders[i] + "/";
// }
// } catch (final URISyntaxException e1) {
// e1.printStackTrace();
// }
// basePath = basePath.substring(0, basePath.length());
// return basePath;
// }
//
// }
| import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import javax.imageio.ImageIO;
import util.PathHelper; | package libs;
public class ImageLib {
public static Map<String, BufferedImage> lib;
static {
| // Path: src/util/PathHelper.java
// public class PathHelper {
//
// static String basePath = "";
//
// public static String basePath(){
// if (basePath != "")
// return basePath;
// try {
// final String path = PathHelper.class.getProtectionDomain()
// .getCodeSource().getLocation().toURI().getPath();
// final String[] folders = path.split("/");
// for (int i = 0; i < folders.length - 1; i++) {
// basePath += folders[i] + "/";
// }
// } catch (final URISyntaxException e1) {
// e1.printStackTrace();
// }
// basePath = basePath.substring(0, basePath.length());
// return basePath;
// }
//
// }
// Path: src/libs/ImageLib.java
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import javax.imageio.ImageIO;
import util.PathHelper;
package libs;
public class ImageLib {
public static Map<String, BufferedImage> lib;
static {
| String basePath = PathHelper.basePath(); |
njustesen/hero-aicademy | src/libs/UnitClassLib.java | // Path: src/model/Attack.java
// public class Attack {
//
// public int range;
// public AttackType attackType;
// public double meleeMultiplier;
// public double rangeMultiplier;
// public boolean chain;
// public boolean push;
//
// public Attack(int range, AttackType attackType,
// int damage, double meleeMultiplier, double rangeMultiplier,
// boolean chain, boolean push) {
// super();
// this.range = range;
// this.attackType = attackType;
// this.meleeMultiplier = meleeMultiplier;
// this.rangeMultiplier = rangeMultiplier;
// this.chain = chain;
// this.push = push;
//
// }
//
//
// }
//
// Path: src/model/AttackType.java
// public enum AttackType {
//
// Physical, Magical;
//
// }
//
// Path: src/model/Card.java
// public enum Card {
//
// KNIGHT(CardType.UNIT),
// ARCHER(CardType.UNIT),
// CLERIC(CardType.UNIT),
// WIZARD(CardType.UNIT),
// NINJA(CardType.UNIT),
// INFERNO(CardType.SPELL),
// REVIVE_POTION(CardType.ITEM),
// RUNEMETAL(CardType.ITEM),
// SCROLL(CardType.ITEM),
// DRAGONSCALE(CardType.ITEM),
// SHINING_HELM(CardType.ITEM),
// CRYSTAL(CardType.UNIT);
//
// public final CardType type;
//
// Card(CardType type) {
// this.type = type;
// }
//
// }
//
// Path: src/model/Heal.java
// public class Heal {
//
// public int range;
// public int heal;
// public int revive;
//
// public Heal(int range, int heal, int revive) {
// super();
// this.range = range;
// this.heal = heal;
// this.revive = revive;
// }
//
// }
//
// Path: src/model/UnitClass.java
// public class UnitClass {
//
// public Card card;
// public int maxHP;
// public int speed;
// public int physicalResistance;
// public int magicalResistance;
// public int power;
// public Attack attack;
// public Heal heal;
// public boolean swap;
//
// public UnitClass(Card card, int maxHP, int speed, int power,
// int physicalResistance, int magicalResistance, Attack attack,
// Heal heal, boolean swap) {
// super();
//
// this.card = card;
// this.maxHP = maxHP;
// this.speed = speed;
// this.power = power;
// this.attack = attack;
// this.heal = heal;
// this.physicalResistance = physicalResistance;
// this.magicalResistance = magicalResistance;
// this.swap = swap;
// }
//
// public int hash() {
// switch(card){
// case ARCHER : return 0;
// case CRYSTAL : return 1;
// case KNIGHT : return 2;
// case NINJA : return 3;
// case CLERIC : return 4;
// case WIZARD : return 5;
// }
// return 6;
// }
// }
| import java.util.HashMap;
import model.Attack;
import model.AttackType;
import model.Card;
import model.Heal;
import model.UnitClass; | package libs;
public class UnitClassLib {
public static HashMap<Card, UnitClass> lib = new HashMap<Card, UnitClass>();
static {
// Add units
lib.put(Card.KNIGHT, new UnitClass(Card.KNIGHT, 1000, 2, 200, 20, 0,
null, null, false));
lib.put(Card.ARCHER, new UnitClass(Card.ARCHER, 800, 2, 300, 0, 0,
null, null, false));
lib.put(Card.CLERIC, new UnitClass(Card.CLERIC, 800, 2, 200, 0, 0,
null, null, false));
lib.put(Card.WIZARD, new UnitClass(Card.WIZARD, 800, 2, 200, 0, 10,
null, null, false));
lib.put(Card.NINJA, new UnitClass(Card.NINJA, 800, 3, 200, 0, 0, null,
null, false));
// Add crystal
lib.put(Card.CRYSTAL, new UnitClass(Card.CRYSTAL, 4500, 0, 0, 0, 0,
null, null, false));
// Add attacks | // Path: src/model/Attack.java
// public class Attack {
//
// public int range;
// public AttackType attackType;
// public double meleeMultiplier;
// public double rangeMultiplier;
// public boolean chain;
// public boolean push;
//
// public Attack(int range, AttackType attackType,
// int damage, double meleeMultiplier, double rangeMultiplier,
// boolean chain, boolean push) {
// super();
// this.range = range;
// this.attackType = attackType;
// this.meleeMultiplier = meleeMultiplier;
// this.rangeMultiplier = rangeMultiplier;
// this.chain = chain;
// this.push = push;
//
// }
//
//
// }
//
// Path: src/model/AttackType.java
// public enum AttackType {
//
// Physical, Magical;
//
// }
//
// Path: src/model/Card.java
// public enum Card {
//
// KNIGHT(CardType.UNIT),
// ARCHER(CardType.UNIT),
// CLERIC(CardType.UNIT),
// WIZARD(CardType.UNIT),
// NINJA(CardType.UNIT),
// INFERNO(CardType.SPELL),
// REVIVE_POTION(CardType.ITEM),
// RUNEMETAL(CardType.ITEM),
// SCROLL(CardType.ITEM),
// DRAGONSCALE(CardType.ITEM),
// SHINING_HELM(CardType.ITEM),
// CRYSTAL(CardType.UNIT);
//
// public final CardType type;
//
// Card(CardType type) {
// this.type = type;
// }
//
// }
//
// Path: src/model/Heal.java
// public class Heal {
//
// public int range;
// public int heal;
// public int revive;
//
// public Heal(int range, int heal, int revive) {
// super();
// this.range = range;
// this.heal = heal;
// this.revive = revive;
// }
//
// }
//
// Path: src/model/UnitClass.java
// public class UnitClass {
//
// public Card card;
// public int maxHP;
// public int speed;
// public int physicalResistance;
// public int magicalResistance;
// public int power;
// public Attack attack;
// public Heal heal;
// public boolean swap;
//
// public UnitClass(Card card, int maxHP, int speed, int power,
// int physicalResistance, int magicalResistance, Attack attack,
// Heal heal, boolean swap) {
// super();
//
// this.card = card;
// this.maxHP = maxHP;
// this.speed = speed;
// this.power = power;
// this.attack = attack;
// this.heal = heal;
// this.physicalResistance = physicalResistance;
// this.magicalResistance = magicalResistance;
// this.swap = swap;
// }
//
// public int hash() {
// switch(card){
// case ARCHER : return 0;
// case CRYSTAL : return 1;
// case KNIGHT : return 2;
// case NINJA : return 3;
// case CLERIC : return 4;
// case WIZARD : return 5;
// }
// return 6;
// }
// }
// Path: src/libs/UnitClassLib.java
import java.util.HashMap;
import model.Attack;
import model.AttackType;
import model.Card;
import model.Heal;
import model.UnitClass;
package libs;
public class UnitClassLib {
public static HashMap<Card, UnitClass> lib = new HashMap<Card, UnitClass>();
static {
// Add units
lib.put(Card.KNIGHT, new UnitClass(Card.KNIGHT, 1000, 2, 200, 20, 0,
null, null, false));
lib.put(Card.ARCHER, new UnitClass(Card.ARCHER, 800, 2, 300, 0, 0,
null, null, false));
lib.put(Card.CLERIC, new UnitClass(Card.CLERIC, 800, 2, 200, 0, 0,
null, null, false));
lib.put(Card.WIZARD, new UnitClass(Card.WIZARD, 800, 2, 200, 0, 10,
null, null, false));
lib.put(Card.NINJA, new UnitClass(Card.NINJA, 800, 3, 200, 0, 0, null,
null, false));
// Add crystal
lib.put(Card.CRYSTAL, new UnitClass(Card.CRYSTAL, 4500, 0, 0, 0, 0,
null, null, false));
// Add attacks | lib.get(Card.KNIGHT).attack = new Attack(1, AttackType.Physical, 200, |
njustesen/hero-aicademy | src/libs/UnitClassLib.java | // Path: src/model/Attack.java
// public class Attack {
//
// public int range;
// public AttackType attackType;
// public double meleeMultiplier;
// public double rangeMultiplier;
// public boolean chain;
// public boolean push;
//
// public Attack(int range, AttackType attackType,
// int damage, double meleeMultiplier, double rangeMultiplier,
// boolean chain, boolean push) {
// super();
// this.range = range;
// this.attackType = attackType;
// this.meleeMultiplier = meleeMultiplier;
// this.rangeMultiplier = rangeMultiplier;
// this.chain = chain;
// this.push = push;
//
// }
//
//
// }
//
// Path: src/model/AttackType.java
// public enum AttackType {
//
// Physical, Magical;
//
// }
//
// Path: src/model/Card.java
// public enum Card {
//
// KNIGHT(CardType.UNIT),
// ARCHER(CardType.UNIT),
// CLERIC(CardType.UNIT),
// WIZARD(CardType.UNIT),
// NINJA(CardType.UNIT),
// INFERNO(CardType.SPELL),
// REVIVE_POTION(CardType.ITEM),
// RUNEMETAL(CardType.ITEM),
// SCROLL(CardType.ITEM),
// DRAGONSCALE(CardType.ITEM),
// SHINING_HELM(CardType.ITEM),
// CRYSTAL(CardType.UNIT);
//
// public final CardType type;
//
// Card(CardType type) {
// this.type = type;
// }
//
// }
//
// Path: src/model/Heal.java
// public class Heal {
//
// public int range;
// public int heal;
// public int revive;
//
// public Heal(int range, int heal, int revive) {
// super();
// this.range = range;
// this.heal = heal;
// this.revive = revive;
// }
//
// }
//
// Path: src/model/UnitClass.java
// public class UnitClass {
//
// public Card card;
// public int maxHP;
// public int speed;
// public int physicalResistance;
// public int magicalResistance;
// public int power;
// public Attack attack;
// public Heal heal;
// public boolean swap;
//
// public UnitClass(Card card, int maxHP, int speed, int power,
// int physicalResistance, int magicalResistance, Attack attack,
// Heal heal, boolean swap) {
// super();
//
// this.card = card;
// this.maxHP = maxHP;
// this.speed = speed;
// this.power = power;
// this.attack = attack;
// this.heal = heal;
// this.physicalResistance = physicalResistance;
// this.magicalResistance = magicalResistance;
// this.swap = swap;
// }
//
// public int hash() {
// switch(card){
// case ARCHER : return 0;
// case CRYSTAL : return 1;
// case KNIGHT : return 2;
// case NINJA : return 3;
// case CLERIC : return 4;
// case WIZARD : return 5;
// }
// return 6;
// }
// }
| import java.util.HashMap;
import model.Attack;
import model.AttackType;
import model.Card;
import model.Heal;
import model.UnitClass; | package libs;
public class UnitClassLib {
public static HashMap<Card, UnitClass> lib = new HashMap<Card, UnitClass>();
static {
// Add units
lib.put(Card.KNIGHT, new UnitClass(Card.KNIGHT, 1000, 2, 200, 20, 0,
null, null, false));
lib.put(Card.ARCHER, new UnitClass(Card.ARCHER, 800, 2, 300, 0, 0,
null, null, false));
lib.put(Card.CLERIC, new UnitClass(Card.CLERIC, 800, 2, 200, 0, 0,
null, null, false));
lib.put(Card.WIZARD, new UnitClass(Card.WIZARD, 800, 2, 200, 0, 10,
null, null, false));
lib.put(Card.NINJA, new UnitClass(Card.NINJA, 800, 3, 200, 0, 0, null,
null, false));
// Add crystal
lib.put(Card.CRYSTAL, new UnitClass(Card.CRYSTAL, 4500, 0, 0, 0, 0,
null, null, false));
// Add attacks | // Path: src/model/Attack.java
// public class Attack {
//
// public int range;
// public AttackType attackType;
// public double meleeMultiplier;
// public double rangeMultiplier;
// public boolean chain;
// public boolean push;
//
// public Attack(int range, AttackType attackType,
// int damage, double meleeMultiplier, double rangeMultiplier,
// boolean chain, boolean push) {
// super();
// this.range = range;
// this.attackType = attackType;
// this.meleeMultiplier = meleeMultiplier;
// this.rangeMultiplier = rangeMultiplier;
// this.chain = chain;
// this.push = push;
//
// }
//
//
// }
//
// Path: src/model/AttackType.java
// public enum AttackType {
//
// Physical, Magical;
//
// }
//
// Path: src/model/Card.java
// public enum Card {
//
// KNIGHT(CardType.UNIT),
// ARCHER(CardType.UNIT),
// CLERIC(CardType.UNIT),
// WIZARD(CardType.UNIT),
// NINJA(CardType.UNIT),
// INFERNO(CardType.SPELL),
// REVIVE_POTION(CardType.ITEM),
// RUNEMETAL(CardType.ITEM),
// SCROLL(CardType.ITEM),
// DRAGONSCALE(CardType.ITEM),
// SHINING_HELM(CardType.ITEM),
// CRYSTAL(CardType.UNIT);
//
// public final CardType type;
//
// Card(CardType type) {
// this.type = type;
// }
//
// }
//
// Path: src/model/Heal.java
// public class Heal {
//
// public int range;
// public int heal;
// public int revive;
//
// public Heal(int range, int heal, int revive) {
// super();
// this.range = range;
// this.heal = heal;
// this.revive = revive;
// }
//
// }
//
// Path: src/model/UnitClass.java
// public class UnitClass {
//
// public Card card;
// public int maxHP;
// public int speed;
// public int physicalResistance;
// public int magicalResistance;
// public int power;
// public Attack attack;
// public Heal heal;
// public boolean swap;
//
// public UnitClass(Card card, int maxHP, int speed, int power,
// int physicalResistance, int magicalResistance, Attack attack,
// Heal heal, boolean swap) {
// super();
//
// this.card = card;
// this.maxHP = maxHP;
// this.speed = speed;
// this.power = power;
// this.attack = attack;
// this.heal = heal;
// this.physicalResistance = physicalResistance;
// this.magicalResistance = magicalResistance;
// this.swap = swap;
// }
//
// public int hash() {
// switch(card){
// case ARCHER : return 0;
// case CRYSTAL : return 1;
// case KNIGHT : return 2;
// case NINJA : return 3;
// case CLERIC : return 4;
// case WIZARD : return 5;
// }
// return 6;
// }
// }
// Path: src/libs/UnitClassLib.java
import java.util.HashMap;
import model.Attack;
import model.AttackType;
import model.Card;
import model.Heal;
import model.UnitClass;
package libs;
public class UnitClassLib {
public static HashMap<Card, UnitClass> lib = new HashMap<Card, UnitClass>();
static {
// Add units
lib.put(Card.KNIGHT, new UnitClass(Card.KNIGHT, 1000, 2, 200, 20, 0,
null, null, false));
lib.put(Card.ARCHER, new UnitClass(Card.ARCHER, 800, 2, 300, 0, 0,
null, null, false));
lib.put(Card.CLERIC, new UnitClass(Card.CLERIC, 800, 2, 200, 0, 0,
null, null, false));
lib.put(Card.WIZARD, new UnitClass(Card.WIZARD, 800, 2, 200, 0, 10,
null, null, false));
lib.put(Card.NINJA, new UnitClass(Card.NINJA, 800, 3, 200, 0, 0, null,
null, false));
// Add crystal
lib.put(Card.CRYSTAL, new UnitClass(Card.CRYSTAL, 4500, 0, 0, 0, 0,
null, null, false));
// Add attacks | lib.get(Card.KNIGHT).attack = new Attack(1, AttackType.Physical, 200, |
njustesen/hero-aicademy | src/libs/UnitClassLib.java | // Path: src/model/Attack.java
// public class Attack {
//
// public int range;
// public AttackType attackType;
// public double meleeMultiplier;
// public double rangeMultiplier;
// public boolean chain;
// public boolean push;
//
// public Attack(int range, AttackType attackType,
// int damage, double meleeMultiplier, double rangeMultiplier,
// boolean chain, boolean push) {
// super();
// this.range = range;
// this.attackType = attackType;
// this.meleeMultiplier = meleeMultiplier;
// this.rangeMultiplier = rangeMultiplier;
// this.chain = chain;
// this.push = push;
//
// }
//
//
// }
//
// Path: src/model/AttackType.java
// public enum AttackType {
//
// Physical, Magical;
//
// }
//
// Path: src/model/Card.java
// public enum Card {
//
// KNIGHT(CardType.UNIT),
// ARCHER(CardType.UNIT),
// CLERIC(CardType.UNIT),
// WIZARD(CardType.UNIT),
// NINJA(CardType.UNIT),
// INFERNO(CardType.SPELL),
// REVIVE_POTION(CardType.ITEM),
// RUNEMETAL(CardType.ITEM),
// SCROLL(CardType.ITEM),
// DRAGONSCALE(CardType.ITEM),
// SHINING_HELM(CardType.ITEM),
// CRYSTAL(CardType.UNIT);
//
// public final CardType type;
//
// Card(CardType type) {
// this.type = type;
// }
//
// }
//
// Path: src/model/Heal.java
// public class Heal {
//
// public int range;
// public int heal;
// public int revive;
//
// public Heal(int range, int heal, int revive) {
// super();
// this.range = range;
// this.heal = heal;
// this.revive = revive;
// }
//
// }
//
// Path: src/model/UnitClass.java
// public class UnitClass {
//
// public Card card;
// public int maxHP;
// public int speed;
// public int physicalResistance;
// public int magicalResistance;
// public int power;
// public Attack attack;
// public Heal heal;
// public boolean swap;
//
// public UnitClass(Card card, int maxHP, int speed, int power,
// int physicalResistance, int magicalResistance, Attack attack,
// Heal heal, boolean swap) {
// super();
//
// this.card = card;
// this.maxHP = maxHP;
// this.speed = speed;
// this.power = power;
// this.attack = attack;
// this.heal = heal;
// this.physicalResistance = physicalResistance;
// this.magicalResistance = magicalResistance;
// this.swap = swap;
// }
//
// public int hash() {
// switch(card){
// case ARCHER : return 0;
// case CRYSTAL : return 1;
// case KNIGHT : return 2;
// case NINJA : return 3;
// case CLERIC : return 4;
// case WIZARD : return 5;
// }
// return 6;
// }
// }
| import java.util.HashMap;
import model.Attack;
import model.AttackType;
import model.Card;
import model.Heal;
import model.UnitClass; | package libs;
public class UnitClassLib {
public static HashMap<Card, UnitClass> lib = new HashMap<Card, UnitClass>();
static {
// Add units
lib.put(Card.KNIGHT, new UnitClass(Card.KNIGHT, 1000, 2, 200, 20, 0,
null, null, false));
lib.put(Card.ARCHER, new UnitClass(Card.ARCHER, 800, 2, 300, 0, 0,
null, null, false));
lib.put(Card.CLERIC, new UnitClass(Card.CLERIC, 800, 2, 200, 0, 0,
null, null, false));
lib.put(Card.WIZARD, new UnitClass(Card.WIZARD, 800, 2, 200, 0, 10,
null, null, false));
lib.put(Card.NINJA, new UnitClass(Card.NINJA, 800, 3, 200, 0, 0, null,
null, false));
// Add crystal
lib.put(Card.CRYSTAL, new UnitClass(Card.CRYSTAL, 4500, 0, 0, 0, 0,
null, null, false));
// Add attacks
lib.get(Card.KNIGHT).attack = new Attack(1, AttackType.Physical, 200,
1, 1, false, true);
lib.get(Card.ARCHER).attack = new Attack(3, AttackType.Physical, 300,
0.5, 1, false, false);
lib.get(Card.CLERIC).attack = new Attack(2, AttackType.Magical, 200, 1,
1, false, false);
lib.get(Card.WIZARD).attack = new Attack(2, AttackType.Magical, 200, 1,
1, true, false);
lib.get(Card.NINJA).attack = new Attack(2, AttackType.Physical, 200, 2,
1, false, false);
// Add heal | // Path: src/model/Attack.java
// public class Attack {
//
// public int range;
// public AttackType attackType;
// public double meleeMultiplier;
// public double rangeMultiplier;
// public boolean chain;
// public boolean push;
//
// public Attack(int range, AttackType attackType,
// int damage, double meleeMultiplier, double rangeMultiplier,
// boolean chain, boolean push) {
// super();
// this.range = range;
// this.attackType = attackType;
// this.meleeMultiplier = meleeMultiplier;
// this.rangeMultiplier = rangeMultiplier;
// this.chain = chain;
// this.push = push;
//
// }
//
//
// }
//
// Path: src/model/AttackType.java
// public enum AttackType {
//
// Physical, Magical;
//
// }
//
// Path: src/model/Card.java
// public enum Card {
//
// KNIGHT(CardType.UNIT),
// ARCHER(CardType.UNIT),
// CLERIC(CardType.UNIT),
// WIZARD(CardType.UNIT),
// NINJA(CardType.UNIT),
// INFERNO(CardType.SPELL),
// REVIVE_POTION(CardType.ITEM),
// RUNEMETAL(CardType.ITEM),
// SCROLL(CardType.ITEM),
// DRAGONSCALE(CardType.ITEM),
// SHINING_HELM(CardType.ITEM),
// CRYSTAL(CardType.UNIT);
//
// public final CardType type;
//
// Card(CardType type) {
// this.type = type;
// }
//
// }
//
// Path: src/model/Heal.java
// public class Heal {
//
// public int range;
// public int heal;
// public int revive;
//
// public Heal(int range, int heal, int revive) {
// super();
// this.range = range;
// this.heal = heal;
// this.revive = revive;
// }
//
// }
//
// Path: src/model/UnitClass.java
// public class UnitClass {
//
// public Card card;
// public int maxHP;
// public int speed;
// public int physicalResistance;
// public int magicalResistance;
// public int power;
// public Attack attack;
// public Heal heal;
// public boolean swap;
//
// public UnitClass(Card card, int maxHP, int speed, int power,
// int physicalResistance, int magicalResistance, Attack attack,
// Heal heal, boolean swap) {
// super();
//
// this.card = card;
// this.maxHP = maxHP;
// this.speed = speed;
// this.power = power;
// this.attack = attack;
// this.heal = heal;
// this.physicalResistance = physicalResistance;
// this.magicalResistance = magicalResistance;
// this.swap = swap;
// }
//
// public int hash() {
// switch(card){
// case ARCHER : return 0;
// case CRYSTAL : return 1;
// case KNIGHT : return 2;
// case NINJA : return 3;
// case CLERIC : return 4;
// case WIZARD : return 5;
// }
// return 6;
// }
// }
// Path: src/libs/UnitClassLib.java
import java.util.HashMap;
import model.Attack;
import model.AttackType;
import model.Card;
import model.Heal;
import model.UnitClass;
package libs;
public class UnitClassLib {
public static HashMap<Card, UnitClass> lib = new HashMap<Card, UnitClass>();
static {
// Add units
lib.put(Card.KNIGHT, new UnitClass(Card.KNIGHT, 1000, 2, 200, 20, 0,
null, null, false));
lib.put(Card.ARCHER, new UnitClass(Card.ARCHER, 800, 2, 300, 0, 0,
null, null, false));
lib.put(Card.CLERIC, new UnitClass(Card.CLERIC, 800, 2, 200, 0, 0,
null, null, false));
lib.put(Card.WIZARD, new UnitClass(Card.WIZARD, 800, 2, 200, 0, 10,
null, null, false));
lib.put(Card.NINJA, new UnitClass(Card.NINJA, 800, 3, 200, 0, 0, null,
null, false));
// Add crystal
lib.put(Card.CRYSTAL, new UnitClass(Card.CRYSTAL, 4500, 0, 0, 0, 0,
null, null, false));
// Add attacks
lib.get(Card.KNIGHT).attack = new Attack(1, AttackType.Physical, 200,
1, 1, false, true);
lib.get(Card.ARCHER).attack = new Attack(3, AttackType.Physical, 300,
0.5, 1, false, false);
lib.get(Card.CLERIC).attack = new Attack(2, AttackType.Magical, 200, 1,
1, false, false);
lib.get(Card.WIZARD).attack = new Attack(2, AttackType.Magical, 200, 1,
1, true, false);
lib.get(Card.NINJA).attack = new Attack(2, AttackType.Physical, 200, 2,
1, false, false);
// Add heal | lib.get(Card.CLERIC).heal = new Heal(2, 3, 2); |
njustesen/hero-aicademy | src/ai/util/SimpleActionComparator.java | // Path: src/model/Card.java
// public enum Card {
//
// KNIGHT(CardType.UNIT),
// ARCHER(CardType.UNIT),
// CLERIC(CardType.UNIT),
// WIZARD(CardType.UNIT),
// NINJA(CardType.UNIT),
// INFERNO(CardType.SPELL),
// REVIVE_POTION(CardType.ITEM),
// RUNEMETAL(CardType.ITEM),
// SCROLL(CardType.ITEM),
// DRAGONSCALE(CardType.ITEM),
// SHINING_HELM(CardType.ITEM),
// CRYSTAL(CardType.UNIT);
//
// public final CardType type;
//
// Card(CardType type) {
// this.type = type;
// }
//
// }
//
// Path: src/model/SquareType.java
// public enum SquareType {
//
// NONE, ASSAULT, DEFENSE, POWER, DEPLOY_1, DEPLOY_2;
//
// }
//
// Path: src/action/Action.java
// public abstract class Action {
//
// }
//
// Path: src/action/DropAction.java
// public class DropAction extends Action {
//
// public Card type;
// public Position to;
//
// public DropAction(Card type, Position to) {
// super();
// this.type = type;
// this.to = to;
// }
//
// @Override
// public int hashCode() {
// final int prime = 31;
// int result = 1;
// result = prime * result + ((to == null) ? 0 : to.hashCode());
// result = prime * result + ((type == null) ? 0 : type.hashCode());
// return result;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj)
// return true;
// if (obj == null)
// return false;
// if (getClass() != obj.getClass())
// return false;
// final DropAction other = (DropAction) obj;
// if (to == null) {
// if (other.to != null)
// return false;
// } else if (!to.equals(other.to))
// return false;
// if (type != other.type)
// return false;
// return true;
// }
//
// @Override
// public String toString() {
// return "DropAction [type=" + type + ", to=" + to + "]";
// }
//
// }
//
// Path: src/action/EndTurnAction.java
// public class EndTurnAction extends Action {
//
// @Override
// public String toString() {
// return "EndTurnAction []";
// }
//
// }
//
// Path: src/action/SwapCardAction.java
// public class SwapCardAction extends Action {
//
// public Card card;
//
// public SwapCardAction(Card card) {
// super();
// this.card = card;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj)
// return true;
// if (obj == null)
// return false;
// if (getClass() != obj.getClass())
// return false;
// SwapCardAction other = (SwapCardAction) obj;
// if (card != other.card)
// return false;
// return true;
// }
//
// @Override
// public String toString() {
// return "SwapCardAction [card=" + card.name() + "]";
// }
//
// }
//
// Path: src/action/UnitAction.java
// public class UnitAction extends Action {
//
// public Position from;
// public Position to;
// public UnitActionType type;
//
// public UnitAction(Position from, Position to, UnitActionType type) {
// super();
// this.from = from;
// this.to = to;
// this.type = type;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj)
// return true;
// if (obj == null)
// return false;
// if (getClass() != obj.getClass())
// return false;
// UnitAction other = (UnitAction) obj;
// if (from == null) {
// if (other.from != null)
// return false;
// } else if (!from.equals(other.from))
// return false;
// if (to == null) {
// if (other.to != null)
// return false;
// } else if (!to.equals(other.to))
// return false;
// if (type != other.type)
// return false;
// return true;
// }
//
//
//
// @Override
// public String toString() {
// return "UnitAction [from=" + from + ", to=" + to + "]";
// }
//
// }
//
// Path: src/action/UnitActionType.java
// public enum UnitActionType {
// ATTACK, MOVE, HEAL, SWAP;
// }
| import model.Card;
import model.SquareType;
import action.Action;
import action.DropAction;
import action.EndTurnAction;
import action.SwapCardAction;
import action.UnitAction;
import action.UnitActionType; | package ai.util;
public class SimpleActionComparator extends ActionComparator {
@Override | // Path: src/model/Card.java
// public enum Card {
//
// KNIGHT(CardType.UNIT),
// ARCHER(CardType.UNIT),
// CLERIC(CardType.UNIT),
// WIZARD(CardType.UNIT),
// NINJA(CardType.UNIT),
// INFERNO(CardType.SPELL),
// REVIVE_POTION(CardType.ITEM),
// RUNEMETAL(CardType.ITEM),
// SCROLL(CardType.ITEM),
// DRAGONSCALE(CardType.ITEM),
// SHINING_HELM(CardType.ITEM),
// CRYSTAL(CardType.UNIT);
//
// public final CardType type;
//
// Card(CardType type) {
// this.type = type;
// }
//
// }
//
// Path: src/model/SquareType.java
// public enum SquareType {
//
// NONE, ASSAULT, DEFENSE, POWER, DEPLOY_1, DEPLOY_2;
//
// }
//
// Path: src/action/Action.java
// public abstract class Action {
//
// }
//
// Path: src/action/DropAction.java
// public class DropAction extends Action {
//
// public Card type;
// public Position to;
//
// public DropAction(Card type, Position to) {
// super();
// this.type = type;
// this.to = to;
// }
//
// @Override
// public int hashCode() {
// final int prime = 31;
// int result = 1;
// result = prime * result + ((to == null) ? 0 : to.hashCode());
// result = prime * result + ((type == null) ? 0 : type.hashCode());
// return result;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj)
// return true;
// if (obj == null)
// return false;
// if (getClass() != obj.getClass())
// return false;
// final DropAction other = (DropAction) obj;
// if (to == null) {
// if (other.to != null)
// return false;
// } else if (!to.equals(other.to))
// return false;
// if (type != other.type)
// return false;
// return true;
// }
//
// @Override
// public String toString() {
// return "DropAction [type=" + type + ", to=" + to + "]";
// }
//
// }
//
// Path: src/action/EndTurnAction.java
// public class EndTurnAction extends Action {
//
// @Override
// public String toString() {
// return "EndTurnAction []";
// }
//
// }
//
// Path: src/action/SwapCardAction.java
// public class SwapCardAction extends Action {
//
// public Card card;
//
// public SwapCardAction(Card card) {
// super();
// this.card = card;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj)
// return true;
// if (obj == null)
// return false;
// if (getClass() != obj.getClass())
// return false;
// SwapCardAction other = (SwapCardAction) obj;
// if (card != other.card)
// return false;
// return true;
// }
//
// @Override
// public String toString() {
// return "SwapCardAction [card=" + card.name() + "]";
// }
//
// }
//
// Path: src/action/UnitAction.java
// public class UnitAction extends Action {
//
// public Position from;
// public Position to;
// public UnitActionType type;
//
// public UnitAction(Position from, Position to, UnitActionType type) {
// super();
// this.from = from;
// this.to = to;
// this.type = type;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj)
// return true;
// if (obj == null)
// return false;
// if (getClass() != obj.getClass())
// return false;
// UnitAction other = (UnitAction) obj;
// if (from == null) {
// if (other.from != null)
// return false;
// } else if (!from.equals(other.from))
// return false;
// if (to == null) {
// if (other.to != null)
// return false;
// } else if (!to.equals(other.to))
// return false;
// if (type != other.type)
// return false;
// return true;
// }
//
//
//
// @Override
// public String toString() {
// return "UnitAction [from=" + from + ", to=" + to + "]";
// }
//
// }
//
// Path: src/action/UnitActionType.java
// public enum UnitActionType {
// ATTACK, MOVE, HEAL, SWAP;
// }
// Path: src/ai/util/SimpleActionComparator.java
import model.Card;
import model.SquareType;
import action.Action;
import action.DropAction;
import action.EndTurnAction;
import action.SwapCardAction;
import action.UnitAction;
import action.UnitActionType;
package ai.util;
public class SimpleActionComparator extends ActionComparator {
@Override | public int value(Action action) { |
njustesen/hero-aicademy | src/ai/util/SimpleActionComparator.java | // Path: src/model/Card.java
// public enum Card {
//
// KNIGHT(CardType.UNIT),
// ARCHER(CardType.UNIT),
// CLERIC(CardType.UNIT),
// WIZARD(CardType.UNIT),
// NINJA(CardType.UNIT),
// INFERNO(CardType.SPELL),
// REVIVE_POTION(CardType.ITEM),
// RUNEMETAL(CardType.ITEM),
// SCROLL(CardType.ITEM),
// DRAGONSCALE(CardType.ITEM),
// SHINING_HELM(CardType.ITEM),
// CRYSTAL(CardType.UNIT);
//
// public final CardType type;
//
// Card(CardType type) {
// this.type = type;
// }
//
// }
//
// Path: src/model/SquareType.java
// public enum SquareType {
//
// NONE, ASSAULT, DEFENSE, POWER, DEPLOY_1, DEPLOY_2;
//
// }
//
// Path: src/action/Action.java
// public abstract class Action {
//
// }
//
// Path: src/action/DropAction.java
// public class DropAction extends Action {
//
// public Card type;
// public Position to;
//
// public DropAction(Card type, Position to) {
// super();
// this.type = type;
// this.to = to;
// }
//
// @Override
// public int hashCode() {
// final int prime = 31;
// int result = 1;
// result = prime * result + ((to == null) ? 0 : to.hashCode());
// result = prime * result + ((type == null) ? 0 : type.hashCode());
// return result;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj)
// return true;
// if (obj == null)
// return false;
// if (getClass() != obj.getClass())
// return false;
// final DropAction other = (DropAction) obj;
// if (to == null) {
// if (other.to != null)
// return false;
// } else if (!to.equals(other.to))
// return false;
// if (type != other.type)
// return false;
// return true;
// }
//
// @Override
// public String toString() {
// return "DropAction [type=" + type + ", to=" + to + "]";
// }
//
// }
//
// Path: src/action/EndTurnAction.java
// public class EndTurnAction extends Action {
//
// @Override
// public String toString() {
// return "EndTurnAction []";
// }
//
// }
//
// Path: src/action/SwapCardAction.java
// public class SwapCardAction extends Action {
//
// public Card card;
//
// public SwapCardAction(Card card) {
// super();
// this.card = card;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj)
// return true;
// if (obj == null)
// return false;
// if (getClass() != obj.getClass())
// return false;
// SwapCardAction other = (SwapCardAction) obj;
// if (card != other.card)
// return false;
// return true;
// }
//
// @Override
// public String toString() {
// return "SwapCardAction [card=" + card.name() + "]";
// }
//
// }
//
// Path: src/action/UnitAction.java
// public class UnitAction extends Action {
//
// public Position from;
// public Position to;
// public UnitActionType type;
//
// public UnitAction(Position from, Position to, UnitActionType type) {
// super();
// this.from = from;
// this.to = to;
// this.type = type;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj)
// return true;
// if (obj == null)
// return false;
// if (getClass() != obj.getClass())
// return false;
// UnitAction other = (UnitAction) obj;
// if (from == null) {
// if (other.from != null)
// return false;
// } else if (!from.equals(other.from))
// return false;
// if (to == null) {
// if (other.to != null)
// return false;
// } else if (!to.equals(other.to))
// return false;
// if (type != other.type)
// return false;
// return true;
// }
//
//
//
// @Override
// public String toString() {
// return "UnitAction [from=" + from + ", to=" + to + "]";
// }
//
// }
//
// Path: src/action/UnitActionType.java
// public enum UnitActionType {
// ATTACK, MOVE, HEAL, SWAP;
// }
| import model.Card;
import model.SquareType;
import action.Action;
import action.DropAction;
import action.EndTurnAction;
import action.SwapCardAction;
import action.UnitAction;
import action.UnitActionType; | package ai.util;
public class SimpleActionComparator extends ActionComparator {
@Override
public int value(Action action) {
| // Path: src/model/Card.java
// public enum Card {
//
// KNIGHT(CardType.UNIT),
// ARCHER(CardType.UNIT),
// CLERIC(CardType.UNIT),
// WIZARD(CardType.UNIT),
// NINJA(CardType.UNIT),
// INFERNO(CardType.SPELL),
// REVIVE_POTION(CardType.ITEM),
// RUNEMETAL(CardType.ITEM),
// SCROLL(CardType.ITEM),
// DRAGONSCALE(CardType.ITEM),
// SHINING_HELM(CardType.ITEM),
// CRYSTAL(CardType.UNIT);
//
// public final CardType type;
//
// Card(CardType type) {
// this.type = type;
// }
//
// }
//
// Path: src/model/SquareType.java
// public enum SquareType {
//
// NONE, ASSAULT, DEFENSE, POWER, DEPLOY_1, DEPLOY_2;
//
// }
//
// Path: src/action/Action.java
// public abstract class Action {
//
// }
//
// Path: src/action/DropAction.java
// public class DropAction extends Action {
//
// public Card type;
// public Position to;
//
// public DropAction(Card type, Position to) {
// super();
// this.type = type;
// this.to = to;
// }
//
// @Override
// public int hashCode() {
// final int prime = 31;
// int result = 1;
// result = prime * result + ((to == null) ? 0 : to.hashCode());
// result = prime * result + ((type == null) ? 0 : type.hashCode());
// return result;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj)
// return true;
// if (obj == null)
// return false;
// if (getClass() != obj.getClass())
// return false;
// final DropAction other = (DropAction) obj;
// if (to == null) {
// if (other.to != null)
// return false;
// } else if (!to.equals(other.to))
// return false;
// if (type != other.type)
// return false;
// return true;
// }
//
// @Override
// public String toString() {
// return "DropAction [type=" + type + ", to=" + to + "]";
// }
//
// }
//
// Path: src/action/EndTurnAction.java
// public class EndTurnAction extends Action {
//
// @Override
// public String toString() {
// return "EndTurnAction []";
// }
//
// }
//
// Path: src/action/SwapCardAction.java
// public class SwapCardAction extends Action {
//
// public Card card;
//
// public SwapCardAction(Card card) {
// super();
// this.card = card;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj)
// return true;
// if (obj == null)
// return false;
// if (getClass() != obj.getClass())
// return false;
// SwapCardAction other = (SwapCardAction) obj;
// if (card != other.card)
// return false;
// return true;
// }
//
// @Override
// public String toString() {
// return "SwapCardAction [card=" + card.name() + "]";
// }
//
// }
//
// Path: src/action/UnitAction.java
// public class UnitAction extends Action {
//
// public Position from;
// public Position to;
// public UnitActionType type;
//
// public UnitAction(Position from, Position to, UnitActionType type) {
// super();
// this.from = from;
// this.to = to;
// this.type = type;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj)
// return true;
// if (obj == null)
// return false;
// if (getClass() != obj.getClass())
// return false;
// UnitAction other = (UnitAction) obj;
// if (from == null) {
// if (other.from != null)
// return false;
// } else if (!from.equals(other.from))
// return false;
// if (to == null) {
// if (other.to != null)
// return false;
// } else if (!to.equals(other.to))
// return false;
// if (type != other.type)
// return false;
// return true;
// }
//
//
//
// @Override
// public String toString() {
// return "UnitAction [from=" + from + ", to=" + to + "]";
// }
//
// }
//
// Path: src/action/UnitActionType.java
// public enum UnitActionType {
// ATTACK, MOVE, HEAL, SWAP;
// }
// Path: src/ai/util/SimpleActionComparator.java
import model.Card;
import model.SquareType;
import action.Action;
import action.DropAction;
import action.EndTurnAction;
import action.SwapCardAction;
import action.UnitAction;
import action.UnitActionType;
package ai.util;
public class SimpleActionComparator extends ActionComparator {
@Override
public int value(Action action) {
| if (action instanceof EndTurnAction) |
njustesen/hero-aicademy | src/ai/util/SimpleActionComparator.java | // Path: src/model/Card.java
// public enum Card {
//
// KNIGHT(CardType.UNIT),
// ARCHER(CardType.UNIT),
// CLERIC(CardType.UNIT),
// WIZARD(CardType.UNIT),
// NINJA(CardType.UNIT),
// INFERNO(CardType.SPELL),
// REVIVE_POTION(CardType.ITEM),
// RUNEMETAL(CardType.ITEM),
// SCROLL(CardType.ITEM),
// DRAGONSCALE(CardType.ITEM),
// SHINING_HELM(CardType.ITEM),
// CRYSTAL(CardType.UNIT);
//
// public final CardType type;
//
// Card(CardType type) {
// this.type = type;
// }
//
// }
//
// Path: src/model/SquareType.java
// public enum SquareType {
//
// NONE, ASSAULT, DEFENSE, POWER, DEPLOY_1, DEPLOY_2;
//
// }
//
// Path: src/action/Action.java
// public abstract class Action {
//
// }
//
// Path: src/action/DropAction.java
// public class DropAction extends Action {
//
// public Card type;
// public Position to;
//
// public DropAction(Card type, Position to) {
// super();
// this.type = type;
// this.to = to;
// }
//
// @Override
// public int hashCode() {
// final int prime = 31;
// int result = 1;
// result = prime * result + ((to == null) ? 0 : to.hashCode());
// result = prime * result + ((type == null) ? 0 : type.hashCode());
// return result;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj)
// return true;
// if (obj == null)
// return false;
// if (getClass() != obj.getClass())
// return false;
// final DropAction other = (DropAction) obj;
// if (to == null) {
// if (other.to != null)
// return false;
// } else if (!to.equals(other.to))
// return false;
// if (type != other.type)
// return false;
// return true;
// }
//
// @Override
// public String toString() {
// return "DropAction [type=" + type + ", to=" + to + "]";
// }
//
// }
//
// Path: src/action/EndTurnAction.java
// public class EndTurnAction extends Action {
//
// @Override
// public String toString() {
// return "EndTurnAction []";
// }
//
// }
//
// Path: src/action/SwapCardAction.java
// public class SwapCardAction extends Action {
//
// public Card card;
//
// public SwapCardAction(Card card) {
// super();
// this.card = card;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj)
// return true;
// if (obj == null)
// return false;
// if (getClass() != obj.getClass())
// return false;
// SwapCardAction other = (SwapCardAction) obj;
// if (card != other.card)
// return false;
// return true;
// }
//
// @Override
// public String toString() {
// return "SwapCardAction [card=" + card.name() + "]";
// }
//
// }
//
// Path: src/action/UnitAction.java
// public class UnitAction extends Action {
//
// public Position from;
// public Position to;
// public UnitActionType type;
//
// public UnitAction(Position from, Position to, UnitActionType type) {
// super();
// this.from = from;
// this.to = to;
// this.type = type;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj)
// return true;
// if (obj == null)
// return false;
// if (getClass() != obj.getClass())
// return false;
// UnitAction other = (UnitAction) obj;
// if (from == null) {
// if (other.from != null)
// return false;
// } else if (!from.equals(other.from))
// return false;
// if (to == null) {
// if (other.to != null)
// return false;
// } else if (!to.equals(other.to))
// return false;
// if (type != other.type)
// return false;
// return true;
// }
//
//
//
// @Override
// public String toString() {
// return "UnitAction [from=" + from + ", to=" + to + "]";
// }
//
// }
//
// Path: src/action/UnitActionType.java
// public enum UnitActionType {
// ATTACK, MOVE, HEAL, SWAP;
// }
| import model.Card;
import model.SquareType;
import action.Action;
import action.DropAction;
import action.EndTurnAction;
import action.SwapCardAction;
import action.UnitAction;
import action.UnitActionType; | package ai.util;
public class SimpleActionComparator extends ActionComparator {
@Override
public int value(Action action) {
if (action instanceof EndTurnAction)
if (state.APLeft == 0)
return 10000;
else
return 0;
| // Path: src/model/Card.java
// public enum Card {
//
// KNIGHT(CardType.UNIT),
// ARCHER(CardType.UNIT),
// CLERIC(CardType.UNIT),
// WIZARD(CardType.UNIT),
// NINJA(CardType.UNIT),
// INFERNO(CardType.SPELL),
// REVIVE_POTION(CardType.ITEM),
// RUNEMETAL(CardType.ITEM),
// SCROLL(CardType.ITEM),
// DRAGONSCALE(CardType.ITEM),
// SHINING_HELM(CardType.ITEM),
// CRYSTAL(CardType.UNIT);
//
// public final CardType type;
//
// Card(CardType type) {
// this.type = type;
// }
//
// }
//
// Path: src/model/SquareType.java
// public enum SquareType {
//
// NONE, ASSAULT, DEFENSE, POWER, DEPLOY_1, DEPLOY_2;
//
// }
//
// Path: src/action/Action.java
// public abstract class Action {
//
// }
//
// Path: src/action/DropAction.java
// public class DropAction extends Action {
//
// public Card type;
// public Position to;
//
// public DropAction(Card type, Position to) {
// super();
// this.type = type;
// this.to = to;
// }
//
// @Override
// public int hashCode() {
// final int prime = 31;
// int result = 1;
// result = prime * result + ((to == null) ? 0 : to.hashCode());
// result = prime * result + ((type == null) ? 0 : type.hashCode());
// return result;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj)
// return true;
// if (obj == null)
// return false;
// if (getClass() != obj.getClass())
// return false;
// final DropAction other = (DropAction) obj;
// if (to == null) {
// if (other.to != null)
// return false;
// } else if (!to.equals(other.to))
// return false;
// if (type != other.type)
// return false;
// return true;
// }
//
// @Override
// public String toString() {
// return "DropAction [type=" + type + ", to=" + to + "]";
// }
//
// }
//
// Path: src/action/EndTurnAction.java
// public class EndTurnAction extends Action {
//
// @Override
// public String toString() {
// return "EndTurnAction []";
// }
//
// }
//
// Path: src/action/SwapCardAction.java
// public class SwapCardAction extends Action {
//
// public Card card;
//
// public SwapCardAction(Card card) {
// super();
// this.card = card;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj)
// return true;
// if (obj == null)
// return false;
// if (getClass() != obj.getClass())
// return false;
// SwapCardAction other = (SwapCardAction) obj;
// if (card != other.card)
// return false;
// return true;
// }
//
// @Override
// public String toString() {
// return "SwapCardAction [card=" + card.name() + "]";
// }
//
// }
//
// Path: src/action/UnitAction.java
// public class UnitAction extends Action {
//
// public Position from;
// public Position to;
// public UnitActionType type;
//
// public UnitAction(Position from, Position to, UnitActionType type) {
// super();
// this.from = from;
// this.to = to;
// this.type = type;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj)
// return true;
// if (obj == null)
// return false;
// if (getClass() != obj.getClass())
// return false;
// UnitAction other = (UnitAction) obj;
// if (from == null) {
// if (other.from != null)
// return false;
// } else if (!from.equals(other.from))
// return false;
// if (to == null) {
// if (other.to != null)
// return false;
// } else if (!to.equals(other.to))
// return false;
// if (type != other.type)
// return false;
// return true;
// }
//
//
//
// @Override
// public String toString() {
// return "UnitAction [from=" + from + ", to=" + to + "]";
// }
//
// }
//
// Path: src/action/UnitActionType.java
// public enum UnitActionType {
// ATTACK, MOVE, HEAL, SWAP;
// }
// Path: src/ai/util/SimpleActionComparator.java
import model.Card;
import model.SquareType;
import action.Action;
import action.DropAction;
import action.EndTurnAction;
import action.SwapCardAction;
import action.UnitAction;
import action.UnitActionType;
package ai.util;
public class SimpleActionComparator extends ActionComparator {
@Override
public int value(Action action) {
if (action instanceof EndTurnAction)
if (state.APLeft == 0)
return 10000;
else
return 0;
| if (action instanceof SwapCardAction) |
njustesen/hero-aicademy | src/ai/util/SimpleActionComparator.java | // Path: src/model/Card.java
// public enum Card {
//
// KNIGHT(CardType.UNIT),
// ARCHER(CardType.UNIT),
// CLERIC(CardType.UNIT),
// WIZARD(CardType.UNIT),
// NINJA(CardType.UNIT),
// INFERNO(CardType.SPELL),
// REVIVE_POTION(CardType.ITEM),
// RUNEMETAL(CardType.ITEM),
// SCROLL(CardType.ITEM),
// DRAGONSCALE(CardType.ITEM),
// SHINING_HELM(CardType.ITEM),
// CRYSTAL(CardType.UNIT);
//
// public final CardType type;
//
// Card(CardType type) {
// this.type = type;
// }
//
// }
//
// Path: src/model/SquareType.java
// public enum SquareType {
//
// NONE, ASSAULT, DEFENSE, POWER, DEPLOY_1, DEPLOY_2;
//
// }
//
// Path: src/action/Action.java
// public abstract class Action {
//
// }
//
// Path: src/action/DropAction.java
// public class DropAction extends Action {
//
// public Card type;
// public Position to;
//
// public DropAction(Card type, Position to) {
// super();
// this.type = type;
// this.to = to;
// }
//
// @Override
// public int hashCode() {
// final int prime = 31;
// int result = 1;
// result = prime * result + ((to == null) ? 0 : to.hashCode());
// result = prime * result + ((type == null) ? 0 : type.hashCode());
// return result;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj)
// return true;
// if (obj == null)
// return false;
// if (getClass() != obj.getClass())
// return false;
// final DropAction other = (DropAction) obj;
// if (to == null) {
// if (other.to != null)
// return false;
// } else if (!to.equals(other.to))
// return false;
// if (type != other.type)
// return false;
// return true;
// }
//
// @Override
// public String toString() {
// return "DropAction [type=" + type + ", to=" + to + "]";
// }
//
// }
//
// Path: src/action/EndTurnAction.java
// public class EndTurnAction extends Action {
//
// @Override
// public String toString() {
// return "EndTurnAction []";
// }
//
// }
//
// Path: src/action/SwapCardAction.java
// public class SwapCardAction extends Action {
//
// public Card card;
//
// public SwapCardAction(Card card) {
// super();
// this.card = card;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj)
// return true;
// if (obj == null)
// return false;
// if (getClass() != obj.getClass())
// return false;
// SwapCardAction other = (SwapCardAction) obj;
// if (card != other.card)
// return false;
// return true;
// }
//
// @Override
// public String toString() {
// return "SwapCardAction [card=" + card.name() + "]";
// }
//
// }
//
// Path: src/action/UnitAction.java
// public class UnitAction extends Action {
//
// public Position from;
// public Position to;
// public UnitActionType type;
//
// public UnitAction(Position from, Position to, UnitActionType type) {
// super();
// this.from = from;
// this.to = to;
// this.type = type;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj)
// return true;
// if (obj == null)
// return false;
// if (getClass() != obj.getClass())
// return false;
// UnitAction other = (UnitAction) obj;
// if (from == null) {
// if (other.from != null)
// return false;
// } else if (!from.equals(other.from))
// return false;
// if (to == null) {
// if (other.to != null)
// return false;
// } else if (!to.equals(other.to))
// return false;
// if (type != other.type)
// return false;
// return true;
// }
//
//
//
// @Override
// public String toString() {
// return "UnitAction [from=" + from + ", to=" + to + "]";
// }
//
// }
//
// Path: src/action/UnitActionType.java
// public enum UnitActionType {
// ATTACK, MOVE, HEAL, SWAP;
// }
| import model.Card;
import model.SquareType;
import action.Action;
import action.DropAction;
import action.EndTurnAction;
import action.SwapCardAction;
import action.UnitAction;
import action.UnitActionType; | package ai.util;
public class SimpleActionComparator extends ActionComparator {
@Override
public int value(Action action) {
if (action instanceof EndTurnAction)
if (state.APLeft == 0)
return 10000;
else
return 0;
if (action instanceof SwapCardAction)
return 0;
| // Path: src/model/Card.java
// public enum Card {
//
// KNIGHT(CardType.UNIT),
// ARCHER(CardType.UNIT),
// CLERIC(CardType.UNIT),
// WIZARD(CardType.UNIT),
// NINJA(CardType.UNIT),
// INFERNO(CardType.SPELL),
// REVIVE_POTION(CardType.ITEM),
// RUNEMETAL(CardType.ITEM),
// SCROLL(CardType.ITEM),
// DRAGONSCALE(CardType.ITEM),
// SHINING_HELM(CardType.ITEM),
// CRYSTAL(CardType.UNIT);
//
// public final CardType type;
//
// Card(CardType type) {
// this.type = type;
// }
//
// }
//
// Path: src/model/SquareType.java
// public enum SquareType {
//
// NONE, ASSAULT, DEFENSE, POWER, DEPLOY_1, DEPLOY_2;
//
// }
//
// Path: src/action/Action.java
// public abstract class Action {
//
// }
//
// Path: src/action/DropAction.java
// public class DropAction extends Action {
//
// public Card type;
// public Position to;
//
// public DropAction(Card type, Position to) {
// super();
// this.type = type;
// this.to = to;
// }
//
// @Override
// public int hashCode() {
// final int prime = 31;
// int result = 1;
// result = prime * result + ((to == null) ? 0 : to.hashCode());
// result = prime * result + ((type == null) ? 0 : type.hashCode());
// return result;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj)
// return true;
// if (obj == null)
// return false;
// if (getClass() != obj.getClass())
// return false;
// final DropAction other = (DropAction) obj;
// if (to == null) {
// if (other.to != null)
// return false;
// } else if (!to.equals(other.to))
// return false;
// if (type != other.type)
// return false;
// return true;
// }
//
// @Override
// public String toString() {
// return "DropAction [type=" + type + ", to=" + to + "]";
// }
//
// }
//
// Path: src/action/EndTurnAction.java
// public class EndTurnAction extends Action {
//
// @Override
// public String toString() {
// return "EndTurnAction []";
// }
//
// }
//
// Path: src/action/SwapCardAction.java
// public class SwapCardAction extends Action {
//
// public Card card;
//
// public SwapCardAction(Card card) {
// super();
// this.card = card;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj)
// return true;
// if (obj == null)
// return false;
// if (getClass() != obj.getClass())
// return false;
// SwapCardAction other = (SwapCardAction) obj;
// if (card != other.card)
// return false;
// return true;
// }
//
// @Override
// public String toString() {
// return "SwapCardAction [card=" + card.name() + "]";
// }
//
// }
//
// Path: src/action/UnitAction.java
// public class UnitAction extends Action {
//
// public Position from;
// public Position to;
// public UnitActionType type;
//
// public UnitAction(Position from, Position to, UnitActionType type) {
// super();
// this.from = from;
// this.to = to;
// this.type = type;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj)
// return true;
// if (obj == null)
// return false;
// if (getClass() != obj.getClass())
// return false;
// UnitAction other = (UnitAction) obj;
// if (from == null) {
// if (other.from != null)
// return false;
// } else if (!from.equals(other.from))
// return false;
// if (to == null) {
// if (other.to != null)
// return false;
// } else if (!to.equals(other.to))
// return false;
// if (type != other.type)
// return false;
// return true;
// }
//
//
//
// @Override
// public String toString() {
// return "UnitAction [from=" + from + ", to=" + to + "]";
// }
//
// }
//
// Path: src/action/UnitActionType.java
// public enum UnitActionType {
// ATTACK, MOVE, HEAL, SWAP;
// }
// Path: src/ai/util/SimpleActionComparator.java
import model.Card;
import model.SquareType;
import action.Action;
import action.DropAction;
import action.EndTurnAction;
import action.SwapCardAction;
import action.UnitAction;
import action.UnitActionType;
package ai.util;
public class SimpleActionComparator extends ActionComparator {
@Override
public int value(Action action) {
if (action instanceof EndTurnAction)
if (state.APLeft == 0)
return 10000;
else
return 0;
if (action instanceof SwapCardAction)
return 0;
| if (action instanceof DropAction) { |
njustesen/hero-aicademy | src/ai/util/SimpleActionComparator.java | // Path: src/model/Card.java
// public enum Card {
//
// KNIGHT(CardType.UNIT),
// ARCHER(CardType.UNIT),
// CLERIC(CardType.UNIT),
// WIZARD(CardType.UNIT),
// NINJA(CardType.UNIT),
// INFERNO(CardType.SPELL),
// REVIVE_POTION(CardType.ITEM),
// RUNEMETAL(CardType.ITEM),
// SCROLL(CardType.ITEM),
// DRAGONSCALE(CardType.ITEM),
// SHINING_HELM(CardType.ITEM),
// CRYSTAL(CardType.UNIT);
//
// public final CardType type;
//
// Card(CardType type) {
// this.type = type;
// }
//
// }
//
// Path: src/model/SquareType.java
// public enum SquareType {
//
// NONE, ASSAULT, DEFENSE, POWER, DEPLOY_1, DEPLOY_2;
//
// }
//
// Path: src/action/Action.java
// public abstract class Action {
//
// }
//
// Path: src/action/DropAction.java
// public class DropAction extends Action {
//
// public Card type;
// public Position to;
//
// public DropAction(Card type, Position to) {
// super();
// this.type = type;
// this.to = to;
// }
//
// @Override
// public int hashCode() {
// final int prime = 31;
// int result = 1;
// result = prime * result + ((to == null) ? 0 : to.hashCode());
// result = prime * result + ((type == null) ? 0 : type.hashCode());
// return result;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj)
// return true;
// if (obj == null)
// return false;
// if (getClass() != obj.getClass())
// return false;
// final DropAction other = (DropAction) obj;
// if (to == null) {
// if (other.to != null)
// return false;
// } else if (!to.equals(other.to))
// return false;
// if (type != other.type)
// return false;
// return true;
// }
//
// @Override
// public String toString() {
// return "DropAction [type=" + type + ", to=" + to + "]";
// }
//
// }
//
// Path: src/action/EndTurnAction.java
// public class EndTurnAction extends Action {
//
// @Override
// public String toString() {
// return "EndTurnAction []";
// }
//
// }
//
// Path: src/action/SwapCardAction.java
// public class SwapCardAction extends Action {
//
// public Card card;
//
// public SwapCardAction(Card card) {
// super();
// this.card = card;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj)
// return true;
// if (obj == null)
// return false;
// if (getClass() != obj.getClass())
// return false;
// SwapCardAction other = (SwapCardAction) obj;
// if (card != other.card)
// return false;
// return true;
// }
//
// @Override
// public String toString() {
// return "SwapCardAction [card=" + card.name() + "]";
// }
//
// }
//
// Path: src/action/UnitAction.java
// public class UnitAction extends Action {
//
// public Position from;
// public Position to;
// public UnitActionType type;
//
// public UnitAction(Position from, Position to, UnitActionType type) {
// super();
// this.from = from;
// this.to = to;
// this.type = type;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj)
// return true;
// if (obj == null)
// return false;
// if (getClass() != obj.getClass())
// return false;
// UnitAction other = (UnitAction) obj;
// if (from == null) {
// if (other.from != null)
// return false;
// } else if (!from.equals(other.from))
// return false;
// if (to == null) {
// if (other.to != null)
// return false;
// } else if (!to.equals(other.to))
// return false;
// if (type != other.type)
// return false;
// return true;
// }
//
//
//
// @Override
// public String toString() {
// return "UnitAction [from=" + from + ", to=" + to + "]";
// }
//
// }
//
// Path: src/action/UnitActionType.java
// public enum UnitActionType {
// ATTACK, MOVE, HEAL, SWAP;
// }
| import model.Card;
import model.SquareType;
import action.Action;
import action.DropAction;
import action.EndTurnAction;
import action.SwapCardAction;
import action.UnitAction;
import action.UnitActionType; | package ai.util;
public class SimpleActionComparator extends ActionComparator {
@Override
public int value(Action action) {
if (action instanceof EndTurnAction)
if (state.APLeft == 0)
return 10000;
else
return 0;
if (action instanceof SwapCardAction)
return 0;
if (action instanceof DropAction) {
final DropAction drop = ((DropAction) action); | // Path: src/model/Card.java
// public enum Card {
//
// KNIGHT(CardType.UNIT),
// ARCHER(CardType.UNIT),
// CLERIC(CardType.UNIT),
// WIZARD(CardType.UNIT),
// NINJA(CardType.UNIT),
// INFERNO(CardType.SPELL),
// REVIVE_POTION(CardType.ITEM),
// RUNEMETAL(CardType.ITEM),
// SCROLL(CardType.ITEM),
// DRAGONSCALE(CardType.ITEM),
// SHINING_HELM(CardType.ITEM),
// CRYSTAL(CardType.UNIT);
//
// public final CardType type;
//
// Card(CardType type) {
// this.type = type;
// }
//
// }
//
// Path: src/model/SquareType.java
// public enum SquareType {
//
// NONE, ASSAULT, DEFENSE, POWER, DEPLOY_1, DEPLOY_2;
//
// }
//
// Path: src/action/Action.java
// public abstract class Action {
//
// }
//
// Path: src/action/DropAction.java
// public class DropAction extends Action {
//
// public Card type;
// public Position to;
//
// public DropAction(Card type, Position to) {
// super();
// this.type = type;
// this.to = to;
// }
//
// @Override
// public int hashCode() {
// final int prime = 31;
// int result = 1;
// result = prime * result + ((to == null) ? 0 : to.hashCode());
// result = prime * result + ((type == null) ? 0 : type.hashCode());
// return result;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj)
// return true;
// if (obj == null)
// return false;
// if (getClass() != obj.getClass())
// return false;
// final DropAction other = (DropAction) obj;
// if (to == null) {
// if (other.to != null)
// return false;
// } else if (!to.equals(other.to))
// return false;
// if (type != other.type)
// return false;
// return true;
// }
//
// @Override
// public String toString() {
// return "DropAction [type=" + type + ", to=" + to + "]";
// }
//
// }
//
// Path: src/action/EndTurnAction.java
// public class EndTurnAction extends Action {
//
// @Override
// public String toString() {
// return "EndTurnAction []";
// }
//
// }
//
// Path: src/action/SwapCardAction.java
// public class SwapCardAction extends Action {
//
// public Card card;
//
// public SwapCardAction(Card card) {
// super();
// this.card = card;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj)
// return true;
// if (obj == null)
// return false;
// if (getClass() != obj.getClass())
// return false;
// SwapCardAction other = (SwapCardAction) obj;
// if (card != other.card)
// return false;
// return true;
// }
//
// @Override
// public String toString() {
// return "SwapCardAction [card=" + card.name() + "]";
// }
//
// }
//
// Path: src/action/UnitAction.java
// public class UnitAction extends Action {
//
// public Position from;
// public Position to;
// public UnitActionType type;
//
// public UnitAction(Position from, Position to, UnitActionType type) {
// super();
// this.from = from;
// this.to = to;
// this.type = type;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj)
// return true;
// if (obj == null)
// return false;
// if (getClass() != obj.getClass())
// return false;
// UnitAction other = (UnitAction) obj;
// if (from == null) {
// if (other.from != null)
// return false;
// } else if (!from.equals(other.from))
// return false;
// if (to == null) {
// if (other.to != null)
// return false;
// } else if (!to.equals(other.to))
// return false;
// if (type != other.type)
// return false;
// return true;
// }
//
//
//
// @Override
// public String toString() {
// return "UnitAction [from=" + from + ", to=" + to + "]";
// }
//
// }
//
// Path: src/action/UnitActionType.java
// public enum UnitActionType {
// ATTACK, MOVE, HEAL, SWAP;
// }
// Path: src/ai/util/SimpleActionComparator.java
import model.Card;
import model.SquareType;
import action.Action;
import action.DropAction;
import action.EndTurnAction;
import action.SwapCardAction;
import action.UnitAction;
import action.UnitActionType;
package ai.util;
public class SimpleActionComparator extends ActionComparator {
@Override
public int value(Action action) {
if (action instanceof EndTurnAction)
if (state.APLeft == 0)
return 10000;
else
return 0;
if (action instanceof SwapCardAction)
return 0;
if (action instanceof DropAction) {
final DropAction drop = ((DropAction) action); | if (drop.type == Card.INFERNO) { |
njustesen/hero-aicademy | src/ai/util/SimpleActionComparator.java | // Path: src/model/Card.java
// public enum Card {
//
// KNIGHT(CardType.UNIT),
// ARCHER(CardType.UNIT),
// CLERIC(CardType.UNIT),
// WIZARD(CardType.UNIT),
// NINJA(CardType.UNIT),
// INFERNO(CardType.SPELL),
// REVIVE_POTION(CardType.ITEM),
// RUNEMETAL(CardType.ITEM),
// SCROLL(CardType.ITEM),
// DRAGONSCALE(CardType.ITEM),
// SHINING_HELM(CardType.ITEM),
// CRYSTAL(CardType.UNIT);
//
// public final CardType type;
//
// Card(CardType type) {
// this.type = type;
// }
//
// }
//
// Path: src/model/SquareType.java
// public enum SquareType {
//
// NONE, ASSAULT, DEFENSE, POWER, DEPLOY_1, DEPLOY_2;
//
// }
//
// Path: src/action/Action.java
// public abstract class Action {
//
// }
//
// Path: src/action/DropAction.java
// public class DropAction extends Action {
//
// public Card type;
// public Position to;
//
// public DropAction(Card type, Position to) {
// super();
// this.type = type;
// this.to = to;
// }
//
// @Override
// public int hashCode() {
// final int prime = 31;
// int result = 1;
// result = prime * result + ((to == null) ? 0 : to.hashCode());
// result = prime * result + ((type == null) ? 0 : type.hashCode());
// return result;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj)
// return true;
// if (obj == null)
// return false;
// if (getClass() != obj.getClass())
// return false;
// final DropAction other = (DropAction) obj;
// if (to == null) {
// if (other.to != null)
// return false;
// } else if (!to.equals(other.to))
// return false;
// if (type != other.type)
// return false;
// return true;
// }
//
// @Override
// public String toString() {
// return "DropAction [type=" + type + ", to=" + to + "]";
// }
//
// }
//
// Path: src/action/EndTurnAction.java
// public class EndTurnAction extends Action {
//
// @Override
// public String toString() {
// return "EndTurnAction []";
// }
//
// }
//
// Path: src/action/SwapCardAction.java
// public class SwapCardAction extends Action {
//
// public Card card;
//
// public SwapCardAction(Card card) {
// super();
// this.card = card;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj)
// return true;
// if (obj == null)
// return false;
// if (getClass() != obj.getClass())
// return false;
// SwapCardAction other = (SwapCardAction) obj;
// if (card != other.card)
// return false;
// return true;
// }
//
// @Override
// public String toString() {
// return "SwapCardAction [card=" + card.name() + "]";
// }
//
// }
//
// Path: src/action/UnitAction.java
// public class UnitAction extends Action {
//
// public Position from;
// public Position to;
// public UnitActionType type;
//
// public UnitAction(Position from, Position to, UnitActionType type) {
// super();
// this.from = from;
// this.to = to;
// this.type = type;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj)
// return true;
// if (obj == null)
// return false;
// if (getClass() != obj.getClass())
// return false;
// UnitAction other = (UnitAction) obj;
// if (from == null) {
// if (other.from != null)
// return false;
// } else if (!from.equals(other.from))
// return false;
// if (to == null) {
// if (other.to != null)
// return false;
// } else if (!to.equals(other.to))
// return false;
// if (type != other.type)
// return false;
// return true;
// }
//
//
//
// @Override
// public String toString() {
// return "UnitAction [from=" + from + ", to=" + to + "]";
// }
//
// }
//
// Path: src/action/UnitActionType.java
// public enum UnitActionType {
// ATTACK, MOVE, HEAL, SWAP;
// }
| import model.Card;
import model.SquareType;
import action.Action;
import action.DropAction;
import action.EndTurnAction;
import action.SwapCardAction;
import action.UnitAction;
import action.UnitActionType; | package ai.util;
public class SimpleActionComparator extends ActionComparator {
@Override
public int value(Action action) {
if (action instanceof EndTurnAction)
if (state.APLeft == 0)
return 10000;
else
return 0;
if (action instanceof SwapCardAction)
return 0;
if (action instanceof DropAction) {
final DropAction drop = ((DropAction) action);
if (drop.type == Card.INFERNO) {
return 3;
} else if (drop.type == Card.REVIVE_POTION) {
if (state.units[drop.to.x][drop.to.y].hp == 0)
return 10;
else
return 3;
} else if (drop.type == Card.SCROLL)
return 3;
else if (drop.type == Card.DRAGONSCALE)
return 3;
else if (drop.type == Card.RUNEMETAL)
return 3;
else if (drop.type == Card.SHINING_HELM)
return 3;
else
return 6; | // Path: src/model/Card.java
// public enum Card {
//
// KNIGHT(CardType.UNIT),
// ARCHER(CardType.UNIT),
// CLERIC(CardType.UNIT),
// WIZARD(CardType.UNIT),
// NINJA(CardType.UNIT),
// INFERNO(CardType.SPELL),
// REVIVE_POTION(CardType.ITEM),
// RUNEMETAL(CardType.ITEM),
// SCROLL(CardType.ITEM),
// DRAGONSCALE(CardType.ITEM),
// SHINING_HELM(CardType.ITEM),
// CRYSTAL(CardType.UNIT);
//
// public final CardType type;
//
// Card(CardType type) {
// this.type = type;
// }
//
// }
//
// Path: src/model/SquareType.java
// public enum SquareType {
//
// NONE, ASSAULT, DEFENSE, POWER, DEPLOY_1, DEPLOY_2;
//
// }
//
// Path: src/action/Action.java
// public abstract class Action {
//
// }
//
// Path: src/action/DropAction.java
// public class DropAction extends Action {
//
// public Card type;
// public Position to;
//
// public DropAction(Card type, Position to) {
// super();
// this.type = type;
// this.to = to;
// }
//
// @Override
// public int hashCode() {
// final int prime = 31;
// int result = 1;
// result = prime * result + ((to == null) ? 0 : to.hashCode());
// result = prime * result + ((type == null) ? 0 : type.hashCode());
// return result;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj)
// return true;
// if (obj == null)
// return false;
// if (getClass() != obj.getClass())
// return false;
// final DropAction other = (DropAction) obj;
// if (to == null) {
// if (other.to != null)
// return false;
// } else if (!to.equals(other.to))
// return false;
// if (type != other.type)
// return false;
// return true;
// }
//
// @Override
// public String toString() {
// return "DropAction [type=" + type + ", to=" + to + "]";
// }
//
// }
//
// Path: src/action/EndTurnAction.java
// public class EndTurnAction extends Action {
//
// @Override
// public String toString() {
// return "EndTurnAction []";
// }
//
// }
//
// Path: src/action/SwapCardAction.java
// public class SwapCardAction extends Action {
//
// public Card card;
//
// public SwapCardAction(Card card) {
// super();
// this.card = card;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj)
// return true;
// if (obj == null)
// return false;
// if (getClass() != obj.getClass())
// return false;
// SwapCardAction other = (SwapCardAction) obj;
// if (card != other.card)
// return false;
// return true;
// }
//
// @Override
// public String toString() {
// return "SwapCardAction [card=" + card.name() + "]";
// }
//
// }
//
// Path: src/action/UnitAction.java
// public class UnitAction extends Action {
//
// public Position from;
// public Position to;
// public UnitActionType type;
//
// public UnitAction(Position from, Position to, UnitActionType type) {
// super();
// this.from = from;
// this.to = to;
// this.type = type;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj)
// return true;
// if (obj == null)
// return false;
// if (getClass() != obj.getClass())
// return false;
// UnitAction other = (UnitAction) obj;
// if (from == null) {
// if (other.from != null)
// return false;
// } else if (!from.equals(other.from))
// return false;
// if (to == null) {
// if (other.to != null)
// return false;
// } else if (!to.equals(other.to))
// return false;
// if (type != other.type)
// return false;
// return true;
// }
//
//
//
// @Override
// public String toString() {
// return "UnitAction [from=" + from + ", to=" + to + "]";
// }
//
// }
//
// Path: src/action/UnitActionType.java
// public enum UnitActionType {
// ATTACK, MOVE, HEAL, SWAP;
// }
// Path: src/ai/util/SimpleActionComparator.java
import model.Card;
import model.SquareType;
import action.Action;
import action.DropAction;
import action.EndTurnAction;
import action.SwapCardAction;
import action.UnitAction;
import action.UnitActionType;
package ai.util;
public class SimpleActionComparator extends ActionComparator {
@Override
public int value(Action action) {
if (action instanceof EndTurnAction)
if (state.APLeft == 0)
return 10000;
else
return 0;
if (action instanceof SwapCardAction)
return 0;
if (action instanceof DropAction) {
final DropAction drop = ((DropAction) action);
if (drop.type == Card.INFERNO) {
return 3;
} else if (drop.type == Card.REVIVE_POTION) {
if (state.units[drop.to.x][drop.to.y].hp == 0)
return 10;
else
return 3;
} else if (drop.type == Card.SCROLL)
return 3;
else if (drop.type == Card.DRAGONSCALE)
return 3;
else if (drop.type == Card.RUNEMETAL)
return 3;
else if (drop.type == Card.SHINING_HELM)
return 3;
else
return 6; | } else if (action instanceof UnitAction) |
njustesen/hero-aicademy | src/ai/util/SimpleActionComparator.java | // Path: src/model/Card.java
// public enum Card {
//
// KNIGHT(CardType.UNIT),
// ARCHER(CardType.UNIT),
// CLERIC(CardType.UNIT),
// WIZARD(CardType.UNIT),
// NINJA(CardType.UNIT),
// INFERNO(CardType.SPELL),
// REVIVE_POTION(CardType.ITEM),
// RUNEMETAL(CardType.ITEM),
// SCROLL(CardType.ITEM),
// DRAGONSCALE(CardType.ITEM),
// SHINING_HELM(CardType.ITEM),
// CRYSTAL(CardType.UNIT);
//
// public final CardType type;
//
// Card(CardType type) {
// this.type = type;
// }
//
// }
//
// Path: src/model/SquareType.java
// public enum SquareType {
//
// NONE, ASSAULT, DEFENSE, POWER, DEPLOY_1, DEPLOY_2;
//
// }
//
// Path: src/action/Action.java
// public abstract class Action {
//
// }
//
// Path: src/action/DropAction.java
// public class DropAction extends Action {
//
// public Card type;
// public Position to;
//
// public DropAction(Card type, Position to) {
// super();
// this.type = type;
// this.to = to;
// }
//
// @Override
// public int hashCode() {
// final int prime = 31;
// int result = 1;
// result = prime * result + ((to == null) ? 0 : to.hashCode());
// result = prime * result + ((type == null) ? 0 : type.hashCode());
// return result;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj)
// return true;
// if (obj == null)
// return false;
// if (getClass() != obj.getClass())
// return false;
// final DropAction other = (DropAction) obj;
// if (to == null) {
// if (other.to != null)
// return false;
// } else if (!to.equals(other.to))
// return false;
// if (type != other.type)
// return false;
// return true;
// }
//
// @Override
// public String toString() {
// return "DropAction [type=" + type + ", to=" + to + "]";
// }
//
// }
//
// Path: src/action/EndTurnAction.java
// public class EndTurnAction extends Action {
//
// @Override
// public String toString() {
// return "EndTurnAction []";
// }
//
// }
//
// Path: src/action/SwapCardAction.java
// public class SwapCardAction extends Action {
//
// public Card card;
//
// public SwapCardAction(Card card) {
// super();
// this.card = card;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj)
// return true;
// if (obj == null)
// return false;
// if (getClass() != obj.getClass())
// return false;
// SwapCardAction other = (SwapCardAction) obj;
// if (card != other.card)
// return false;
// return true;
// }
//
// @Override
// public String toString() {
// return "SwapCardAction [card=" + card.name() + "]";
// }
//
// }
//
// Path: src/action/UnitAction.java
// public class UnitAction extends Action {
//
// public Position from;
// public Position to;
// public UnitActionType type;
//
// public UnitAction(Position from, Position to, UnitActionType type) {
// super();
// this.from = from;
// this.to = to;
// this.type = type;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj)
// return true;
// if (obj == null)
// return false;
// if (getClass() != obj.getClass())
// return false;
// UnitAction other = (UnitAction) obj;
// if (from == null) {
// if (other.from != null)
// return false;
// } else if (!from.equals(other.from))
// return false;
// if (to == null) {
// if (other.to != null)
// return false;
// } else if (!to.equals(other.to))
// return false;
// if (type != other.type)
// return false;
// return true;
// }
//
//
//
// @Override
// public String toString() {
// return "UnitAction [from=" + from + ", to=" + to + "]";
// }
//
// }
//
// Path: src/action/UnitActionType.java
// public enum UnitActionType {
// ATTACK, MOVE, HEAL, SWAP;
// }
| import model.Card;
import model.SquareType;
import action.Action;
import action.DropAction;
import action.EndTurnAction;
import action.SwapCardAction;
import action.UnitAction;
import action.UnitActionType; |
if (action instanceof EndTurnAction)
if (state.APLeft == 0)
return 10000;
else
return 0;
if (action instanceof SwapCardAction)
return 0;
if (action instanceof DropAction) {
final DropAction drop = ((DropAction) action);
if (drop.type == Card.INFERNO) {
return 3;
} else if (drop.type == Card.REVIVE_POTION) {
if (state.units[drop.to.x][drop.to.y].hp == 0)
return 10;
else
return 3;
} else if (drop.type == Card.SCROLL)
return 3;
else if (drop.type == Card.DRAGONSCALE)
return 3;
else if (drop.type == Card.RUNEMETAL)
return 3;
else if (drop.type == Card.SHINING_HELM)
return 3;
else
return 6;
} else if (action instanceof UnitAction) | // Path: src/model/Card.java
// public enum Card {
//
// KNIGHT(CardType.UNIT),
// ARCHER(CardType.UNIT),
// CLERIC(CardType.UNIT),
// WIZARD(CardType.UNIT),
// NINJA(CardType.UNIT),
// INFERNO(CardType.SPELL),
// REVIVE_POTION(CardType.ITEM),
// RUNEMETAL(CardType.ITEM),
// SCROLL(CardType.ITEM),
// DRAGONSCALE(CardType.ITEM),
// SHINING_HELM(CardType.ITEM),
// CRYSTAL(CardType.UNIT);
//
// public final CardType type;
//
// Card(CardType type) {
// this.type = type;
// }
//
// }
//
// Path: src/model/SquareType.java
// public enum SquareType {
//
// NONE, ASSAULT, DEFENSE, POWER, DEPLOY_1, DEPLOY_2;
//
// }
//
// Path: src/action/Action.java
// public abstract class Action {
//
// }
//
// Path: src/action/DropAction.java
// public class DropAction extends Action {
//
// public Card type;
// public Position to;
//
// public DropAction(Card type, Position to) {
// super();
// this.type = type;
// this.to = to;
// }
//
// @Override
// public int hashCode() {
// final int prime = 31;
// int result = 1;
// result = prime * result + ((to == null) ? 0 : to.hashCode());
// result = prime * result + ((type == null) ? 0 : type.hashCode());
// return result;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj)
// return true;
// if (obj == null)
// return false;
// if (getClass() != obj.getClass())
// return false;
// final DropAction other = (DropAction) obj;
// if (to == null) {
// if (other.to != null)
// return false;
// } else if (!to.equals(other.to))
// return false;
// if (type != other.type)
// return false;
// return true;
// }
//
// @Override
// public String toString() {
// return "DropAction [type=" + type + ", to=" + to + "]";
// }
//
// }
//
// Path: src/action/EndTurnAction.java
// public class EndTurnAction extends Action {
//
// @Override
// public String toString() {
// return "EndTurnAction []";
// }
//
// }
//
// Path: src/action/SwapCardAction.java
// public class SwapCardAction extends Action {
//
// public Card card;
//
// public SwapCardAction(Card card) {
// super();
// this.card = card;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj)
// return true;
// if (obj == null)
// return false;
// if (getClass() != obj.getClass())
// return false;
// SwapCardAction other = (SwapCardAction) obj;
// if (card != other.card)
// return false;
// return true;
// }
//
// @Override
// public String toString() {
// return "SwapCardAction [card=" + card.name() + "]";
// }
//
// }
//
// Path: src/action/UnitAction.java
// public class UnitAction extends Action {
//
// public Position from;
// public Position to;
// public UnitActionType type;
//
// public UnitAction(Position from, Position to, UnitActionType type) {
// super();
// this.from = from;
// this.to = to;
// this.type = type;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj)
// return true;
// if (obj == null)
// return false;
// if (getClass() != obj.getClass())
// return false;
// UnitAction other = (UnitAction) obj;
// if (from == null) {
// if (other.from != null)
// return false;
// } else if (!from.equals(other.from))
// return false;
// if (to == null) {
// if (other.to != null)
// return false;
// } else if (!to.equals(other.to))
// return false;
// if (type != other.type)
// return false;
// return true;
// }
//
//
//
// @Override
// public String toString() {
// return "UnitAction [from=" + from + ", to=" + to + "]";
// }
//
// }
//
// Path: src/action/UnitActionType.java
// public enum UnitActionType {
// ATTACK, MOVE, HEAL, SWAP;
// }
// Path: src/ai/util/SimpleActionComparator.java
import model.Card;
import model.SquareType;
import action.Action;
import action.DropAction;
import action.EndTurnAction;
import action.SwapCardAction;
import action.UnitAction;
import action.UnitActionType;
if (action instanceof EndTurnAction)
if (state.APLeft == 0)
return 10000;
else
return 0;
if (action instanceof SwapCardAction)
return 0;
if (action instanceof DropAction) {
final DropAction drop = ((DropAction) action);
if (drop.type == Card.INFERNO) {
return 3;
} else if (drop.type == Card.REVIVE_POTION) {
if (state.units[drop.to.x][drop.to.y].hp == 0)
return 10;
else
return 3;
} else if (drop.type == Card.SCROLL)
return 3;
else if (drop.type == Card.DRAGONSCALE)
return 3;
else if (drop.type == Card.RUNEMETAL)
return 3;
else if (drop.type == Card.SHINING_HELM)
return 3;
else
return 6;
} else if (action instanceof UnitAction) | if (((UnitAction) action).type == UnitActionType.ATTACK) { |
njustesen/hero-aicademy | src/util/CachedLines.java | // Path: src/model/HaMap.java
// public class HaMap {
//
// public String name;
// public int width;
// public int height;
// public SquareType[][] squares;
// public List<Position> assaultSquares;
// public List<Position> p1DeploySquares;
// public List<Position> p2DeploySquares;
// public List<Position> p1Crystals;
// public List<Position> p2Crystals;
//
// public HaMap(int width, int height, SquareType[][] squares, String name) {
// super();
// this.name = name;
// this.width = width;
// this.height = height;
// this.squares = squares;
// assaultSquares = new ArrayList<Position>();
// p1DeploySquares = new ArrayList<Position>();
// p2DeploySquares = new ArrayList<Position>();
// p1Crystals = new ArrayList<Position>();
// p2Crystals = new ArrayList<Position>();
// for (int x = 0; x < squares.length; x++)
// for (int y = 0; y < squares[0].length; y++) {
// if (squares[x][y] == SquareType.DEPLOY_1)
// p1DeploySquares.add(new Position(x, y));
// if (squares[x][y] == SquareType.DEPLOY_2)
// p2DeploySquares.add(new Position(x, y));
// if (squares[x][y] == SquareType.ASSAULT)
// assaultSquares.add(new Position(x, y));
// }
// }
//
// public SquareType squareAt(int x, int y) {
//
// return squares[x][y];
//
// }
//
// public SquareType squareAt(Position position) {
// return squareAt(position.x, position.y);
// }
//
// }
//
// Path: src/model/Position.java
// public class Position {
//
// public int x;
// public int y;
//
// public Position(int x, int y) {
// super();
// this.x = x;
// this.y = y;
// }
//
// public Position() {
// super();
// x = 0;
// y = 0;
// }
//
// public Direction getDirection(Position pos) {
// if (pos == null)
// return null;
// return Direction.direction(pos.x - x, pos.y - y);
// }
//
// public int hashCode() {
// int result = 1;
// result = 5 * result + x;
// result = 5 * result + y;
// return result;
// }
//
// @Override
// public String toString() {
// return "(" + x + "," + y + ")";
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj)
// return true;
// if (obj == null)
// return false;
// if (getClass() != obj.getClass())
// return false;
// final Position other = (Position) obj;
// if (x != other.x)
// return false;
// if (y != other.y)
// return false;
// return true;
// }
//
// public int distance(Position to) {
// int xx = x - to.x;
// if (xx < 0)
// xx = xx * (-1);
// int yy = y - to.y;
// if (yy < 0)
// yy = yy * (-1);
// return xx + yy;
// }
//
// }
| import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import model.HaMap;
import model.Position; | package util;
public class CachedLines {
public static Map<Position, Map<Position, List<Position>>> posMap = new HashMap<Position, Map<Position, List<Position>>>(); | // Path: src/model/HaMap.java
// public class HaMap {
//
// public String name;
// public int width;
// public int height;
// public SquareType[][] squares;
// public List<Position> assaultSquares;
// public List<Position> p1DeploySquares;
// public List<Position> p2DeploySquares;
// public List<Position> p1Crystals;
// public List<Position> p2Crystals;
//
// public HaMap(int width, int height, SquareType[][] squares, String name) {
// super();
// this.name = name;
// this.width = width;
// this.height = height;
// this.squares = squares;
// assaultSquares = new ArrayList<Position>();
// p1DeploySquares = new ArrayList<Position>();
// p2DeploySquares = new ArrayList<Position>();
// p1Crystals = new ArrayList<Position>();
// p2Crystals = new ArrayList<Position>();
// for (int x = 0; x < squares.length; x++)
// for (int y = 0; y < squares[0].length; y++) {
// if (squares[x][y] == SquareType.DEPLOY_1)
// p1DeploySquares.add(new Position(x, y));
// if (squares[x][y] == SquareType.DEPLOY_2)
// p2DeploySquares.add(new Position(x, y));
// if (squares[x][y] == SquareType.ASSAULT)
// assaultSquares.add(new Position(x, y));
// }
// }
//
// public SquareType squareAt(int x, int y) {
//
// return squares[x][y];
//
// }
//
// public SquareType squareAt(Position position) {
// return squareAt(position.x, position.y);
// }
//
// }
//
// Path: src/model/Position.java
// public class Position {
//
// public int x;
// public int y;
//
// public Position(int x, int y) {
// super();
// this.x = x;
// this.y = y;
// }
//
// public Position() {
// super();
// x = 0;
// y = 0;
// }
//
// public Direction getDirection(Position pos) {
// if (pos == null)
// return null;
// return Direction.direction(pos.x - x, pos.y - y);
// }
//
// public int hashCode() {
// int result = 1;
// result = 5 * result + x;
// result = 5 * result + y;
// return result;
// }
//
// @Override
// public String toString() {
// return "(" + x + "," + y + ")";
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj)
// return true;
// if (obj == null)
// return false;
// if (getClass() != obj.getClass())
// return false;
// final Position other = (Position) obj;
// if (x != other.x)
// return false;
// if (y != other.y)
// return false;
// return true;
// }
//
// public int distance(Position to) {
// int xx = x - to.x;
// if (xx < 0)
// xx = xx * (-1);
// int yy = y - to.y;
// if (yy < 0)
// yy = yy * (-1);
// return xx + yy;
// }
//
// }
// Path: src/util/CachedLines.java
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import model.HaMap;
import model.Position;
package util;
public class CachedLines {
public static Map<Position, Map<Position, List<Position>>> posMap = new HashMap<Position, Map<Position, List<Position>>>(); | public static HaMap map; |
njustesen/hero-aicademy | src/action/SingletonAction.java | // Path: src/model/Card.java
// public enum Card {
//
// KNIGHT(CardType.UNIT),
// ARCHER(CardType.UNIT),
// CLERIC(CardType.UNIT),
// WIZARD(CardType.UNIT),
// NINJA(CardType.UNIT),
// INFERNO(CardType.SPELL),
// REVIVE_POTION(CardType.ITEM),
// RUNEMETAL(CardType.ITEM),
// SCROLL(CardType.ITEM),
// DRAGONSCALE(CardType.ITEM),
// SHINING_HELM(CardType.ITEM),
// CRYSTAL(CardType.UNIT);
//
// public final CardType type;
//
// Card(CardType type) {
// this.type = type;
// }
//
// }
//
// Path: src/model/HaMap.java
// public class HaMap {
//
// public String name;
// public int width;
// public int height;
// public SquareType[][] squares;
// public List<Position> assaultSquares;
// public List<Position> p1DeploySquares;
// public List<Position> p2DeploySquares;
// public List<Position> p1Crystals;
// public List<Position> p2Crystals;
//
// public HaMap(int width, int height, SquareType[][] squares, String name) {
// super();
// this.name = name;
// this.width = width;
// this.height = height;
// this.squares = squares;
// assaultSquares = new ArrayList<Position>();
// p1DeploySquares = new ArrayList<Position>();
// p2DeploySquares = new ArrayList<Position>();
// p1Crystals = new ArrayList<Position>();
// p2Crystals = new ArrayList<Position>();
// for (int x = 0; x < squares.length; x++)
// for (int y = 0; y < squares[0].length; y++) {
// if (squares[x][y] == SquareType.DEPLOY_1)
// p1DeploySquares.add(new Position(x, y));
// if (squares[x][y] == SquareType.DEPLOY_2)
// p2DeploySquares.add(new Position(x, y));
// if (squares[x][y] == SquareType.ASSAULT)
// assaultSquares.add(new Position(x, y));
// }
// }
//
// public SquareType squareAt(int x, int y) {
//
// return squares[x][y];
//
// }
//
// public SquareType squareAt(Position position) {
// return squareAt(position.x, position.y);
// }
//
// }
//
// Path: src/model/Position.java
// public class Position {
//
// public int x;
// public int y;
//
// public Position(int x, int y) {
// super();
// this.x = x;
// this.y = y;
// }
//
// public Position() {
// super();
// x = 0;
// y = 0;
// }
//
// public Direction getDirection(Position pos) {
// if (pos == null)
// return null;
// return Direction.direction(pos.x - x, pos.y - y);
// }
//
// public int hashCode() {
// int result = 1;
// result = 5 * result + x;
// result = 5 * result + y;
// return result;
// }
//
// @Override
// public String toString() {
// return "(" + x + "," + y + ")";
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj)
// return true;
// if (obj == null)
// return false;
// if (getClass() != obj.getClass())
// return false;
// final Position other = (Position) obj;
// if (x != other.x)
// return false;
// if (y != other.y)
// return false;
// return true;
// }
//
// public int distance(Position to) {
// int xx = x - to.x;
// if (xx < 0)
// xx = xx * (-1);
// int yy = y - to.y;
// if (yy < 0)
// yy = yy * (-1);
// return xx + yy;
// }
//
// }
| import java.util.HashMap;
import java.util.Map;
import model.Card;
import model.HaMap;
import model.Position; | package action;
public class SingletonAction {
public static final EndTurnAction endTurnAction = new EndTurnAction();
public static final PlayAgainAction playAgainAction = new PlayAgainAction();
public static final UndoAction undoAction = new UndoAction(); | // Path: src/model/Card.java
// public enum Card {
//
// KNIGHT(CardType.UNIT),
// ARCHER(CardType.UNIT),
// CLERIC(CardType.UNIT),
// WIZARD(CardType.UNIT),
// NINJA(CardType.UNIT),
// INFERNO(CardType.SPELL),
// REVIVE_POTION(CardType.ITEM),
// RUNEMETAL(CardType.ITEM),
// SCROLL(CardType.ITEM),
// DRAGONSCALE(CardType.ITEM),
// SHINING_HELM(CardType.ITEM),
// CRYSTAL(CardType.UNIT);
//
// public final CardType type;
//
// Card(CardType type) {
// this.type = type;
// }
//
// }
//
// Path: src/model/HaMap.java
// public class HaMap {
//
// public String name;
// public int width;
// public int height;
// public SquareType[][] squares;
// public List<Position> assaultSquares;
// public List<Position> p1DeploySquares;
// public List<Position> p2DeploySquares;
// public List<Position> p1Crystals;
// public List<Position> p2Crystals;
//
// public HaMap(int width, int height, SquareType[][] squares, String name) {
// super();
// this.name = name;
// this.width = width;
// this.height = height;
// this.squares = squares;
// assaultSquares = new ArrayList<Position>();
// p1DeploySquares = new ArrayList<Position>();
// p2DeploySquares = new ArrayList<Position>();
// p1Crystals = new ArrayList<Position>();
// p2Crystals = new ArrayList<Position>();
// for (int x = 0; x < squares.length; x++)
// for (int y = 0; y < squares[0].length; y++) {
// if (squares[x][y] == SquareType.DEPLOY_1)
// p1DeploySquares.add(new Position(x, y));
// if (squares[x][y] == SquareType.DEPLOY_2)
// p2DeploySquares.add(new Position(x, y));
// if (squares[x][y] == SquareType.ASSAULT)
// assaultSquares.add(new Position(x, y));
// }
// }
//
// public SquareType squareAt(int x, int y) {
//
// return squares[x][y];
//
// }
//
// public SquareType squareAt(Position position) {
// return squareAt(position.x, position.y);
// }
//
// }
//
// Path: src/model/Position.java
// public class Position {
//
// public int x;
// public int y;
//
// public Position(int x, int y) {
// super();
// this.x = x;
// this.y = y;
// }
//
// public Position() {
// super();
// x = 0;
// y = 0;
// }
//
// public Direction getDirection(Position pos) {
// if (pos == null)
// return null;
// return Direction.direction(pos.x - x, pos.y - y);
// }
//
// public int hashCode() {
// int result = 1;
// result = 5 * result + x;
// result = 5 * result + y;
// return result;
// }
//
// @Override
// public String toString() {
// return "(" + x + "," + y + ")";
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj)
// return true;
// if (obj == null)
// return false;
// if (getClass() != obj.getClass())
// return false;
// final Position other = (Position) obj;
// if (x != other.x)
// return false;
// if (y != other.y)
// return false;
// return true;
// }
//
// public int distance(Position to) {
// int xx = x - to.x;
// if (xx < 0)
// xx = xx * (-1);
// int yy = y - to.y;
// if (yy < 0)
// yy = yy * (-1);
// return xx + yy;
// }
//
// }
// Path: src/action/SingletonAction.java
import java.util.HashMap;
import java.util.Map;
import model.Card;
import model.HaMap;
import model.Position;
package action;
public class SingletonAction {
public static final EndTurnAction endTurnAction = new EndTurnAction();
public static final PlayAgainAction playAgainAction = new PlayAgainAction();
public static final UndoAction undoAction = new UndoAction(); | public static final Map<Card, SwapCardAction> swapActions = new HashMap<Card, SwapCardAction>(); |
njustesen/hero-aicademy | src/action/SingletonAction.java | // Path: src/model/Card.java
// public enum Card {
//
// KNIGHT(CardType.UNIT),
// ARCHER(CardType.UNIT),
// CLERIC(CardType.UNIT),
// WIZARD(CardType.UNIT),
// NINJA(CardType.UNIT),
// INFERNO(CardType.SPELL),
// REVIVE_POTION(CardType.ITEM),
// RUNEMETAL(CardType.ITEM),
// SCROLL(CardType.ITEM),
// DRAGONSCALE(CardType.ITEM),
// SHINING_HELM(CardType.ITEM),
// CRYSTAL(CardType.UNIT);
//
// public final CardType type;
//
// Card(CardType type) {
// this.type = type;
// }
//
// }
//
// Path: src/model/HaMap.java
// public class HaMap {
//
// public String name;
// public int width;
// public int height;
// public SquareType[][] squares;
// public List<Position> assaultSquares;
// public List<Position> p1DeploySquares;
// public List<Position> p2DeploySquares;
// public List<Position> p1Crystals;
// public List<Position> p2Crystals;
//
// public HaMap(int width, int height, SquareType[][] squares, String name) {
// super();
// this.name = name;
// this.width = width;
// this.height = height;
// this.squares = squares;
// assaultSquares = new ArrayList<Position>();
// p1DeploySquares = new ArrayList<Position>();
// p2DeploySquares = new ArrayList<Position>();
// p1Crystals = new ArrayList<Position>();
// p2Crystals = new ArrayList<Position>();
// for (int x = 0; x < squares.length; x++)
// for (int y = 0; y < squares[0].length; y++) {
// if (squares[x][y] == SquareType.DEPLOY_1)
// p1DeploySquares.add(new Position(x, y));
// if (squares[x][y] == SquareType.DEPLOY_2)
// p2DeploySquares.add(new Position(x, y));
// if (squares[x][y] == SquareType.ASSAULT)
// assaultSquares.add(new Position(x, y));
// }
// }
//
// public SquareType squareAt(int x, int y) {
//
// return squares[x][y];
//
// }
//
// public SquareType squareAt(Position position) {
// return squareAt(position.x, position.y);
// }
//
// }
//
// Path: src/model/Position.java
// public class Position {
//
// public int x;
// public int y;
//
// public Position(int x, int y) {
// super();
// this.x = x;
// this.y = y;
// }
//
// public Position() {
// super();
// x = 0;
// y = 0;
// }
//
// public Direction getDirection(Position pos) {
// if (pos == null)
// return null;
// return Direction.direction(pos.x - x, pos.y - y);
// }
//
// public int hashCode() {
// int result = 1;
// result = 5 * result + x;
// result = 5 * result + y;
// return result;
// }
//
// @Override
// public String toString() {
// return "(" + x + "," + y + ")";
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj)
// return true;
// if (obj == null)
// return false;
// if (getClass() != obj.getClass())
// return false;
// final Position other = (Position) obj;
// if (x != other.x)
// return false;
// if (y != other.y)
// return false;
// return true;
// }
//
// public int distance(Position to) {
// int xx = x - to.x;
// if (xx < 0)
// xx = xx * (-1);
// int yy = y - to.y;
// if (yy < 0)
// yy = yy * (-1);
// return xx + yy;
// }
//
// }
| import java.util.HashMap;
import java.util.Map;
import model.Card;
import model.HaMap;
import model.Position; | package action;
public class SingletonAction {
public static final EndTurnAction endTurnAction = new EndTurnAction();
public static final PlayAgainAction playAgainAction = new PlayAgainAction();
public static final UndoAction undoAction = new UndoAction();
public static final Map<Card, SwapCardAction> swapActions = new HashMap<Card, SwapCardAction>();
static {
swapActions.put(Card.ARCHER, new SwapCardAction(Card.ARCHER));
swapActions.put(Card.CLERIC, new SwapCardAction(Card.CLERIC));
swapActions.put(Card.DRAGONSCALE, new SwapCardAction(Card.DRAGONSCALE));
swapActions.put(Card.INFERNO, new SwapCardAction(Card.INFERNO));
swapActions.put(Card.KNIGHT, new SwapCardAction(Card.KNIGHT));
swapActions.put(Card.NINJA, new SwapCardAction(Card.NINJA));
swapActions.put(Card.REVIVE_POTION, new SwapCardAction(
Card.REVIVE_POTION));
swapActions.put(Card.RUNEMETAL, new SwapCardAction(Card.RUNEMETAL));
swapActions.put(Card.SCROLL, new SwapCardAction(Card.SCROLL));
swapActions.put(Card.SHINING_HELM,
new SwapCardAction(Card.SHINING_HELM));
swapActions.put(Card.WIZARD, new SwapCardAction(Card.WIZARD));
}
| // Path: src/model/Card.java
// public enum Card {
//
// KNIGHT(CardType.UNIT),
// ARCHER(CardType.UNIT),
// CLERIC(CardType.UNIT),
// WIZARD(CardType.UNIT),
// NINJA(CardType.UNIT),
// INFERNO(CardType.SPELL),
// REVIVE_POTION(CardType.ITEM),
// RUNEMETAL(CardType.ITEM),
// SCROLL(CardType.ITEM),
// DRAGONSCALE(CardType.ITEM),
// SHINING_HELM(CardType.ITEM),
// CRYSTAL(CardType.UNIT);
//
// public final CardType type;
//
// Card(CardType type) {
// this.type = type;
// }
//
// }
//
// Path: src/model/HaMap.java
// public class HaMap {
//
// public String name;
// public int width;
// public int height;
// public SquareType[][] squares;
// public List<Position> assaultSquares;
// public List<Position> p1DeploySquares;
// public List<Position> p2DeploySquares;
// public List<Position> p1Crystals;
// public List<Position> p2Crystals;
//
// public HaMap(int width, int height, SquareType[][] squares, String name) {
// super();
// this.name = name;
// this.width = width;
// this.height = height;
// this.squares = squares;
// assaultSquares = new ArrayList<Position>();
// p1DeploySquares = new ArrayList<Position>();
// p2DeploySquares = new ArrayList<Position>();
// p1Crystals = new ArrayList<Position>();
// p2Crystals = new ArrayList<Position>();
// for (int x = 0; x < squares.length; x++)
// for (int y = 0; y < squares[0].length; y++) {
// if (squares[x][y] == SquareType.DEPLOY_1)
// p1DeploySquares.add(new Position(x, y));
// if (squares[x][y] == SquareType.DEPLOY_2)
// p2DeploySquares.add(new Position(x, y));
// if (squares[x][y] == SquareType.ASSAULT)
// assaultSquares.add(new Position(x, y));
// }
// }
//
// public SquareType squareAt(int x, int y) {
//
// return squares[x][y];
//
// }
//
// public SquareType squareAt(Position position) {
// return squareAt(position.x, position.y);
// }
//
// }
//
// Path: src/model/Position.java
// public class Position {
//
// public int x;
// public int y;
//
// public Position(int x, int y) {
// super();
// this.x = x;
// this.y = y;
// }
//
// public Position() {
// super();
// x = 0;
// y = 0;
// }
//
// public Direction getDirection(Position pos) {
// if (pos == null)
// return null;
// return Direction.direction(pos.x - x, pos.y - y);
// }
//
// public int hashCode() {
// int result = 1;
// result = 5 * result + x;
// result = 5 * result + y;
// return result;
// }
//
// @Override
// public String toString() {
// return "(" + x + "," + y + ")";
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj)
// return true;
// if (obj == null)
// return false;
// if (getClass() != obj.getClass())
// return false;
// final Position other = (Position) obj;
// if (x != other.x)
// return false;
// if (y != other.y)
// return false;
// return true;
// }
//
// public int distance(Position to) {
// int xx = x - to.x;
// if (xx < 0)
// xx = xx * (-1);
// int yy = y - to.y;
// if (yy < 0)
// yy = yy * (-1);
// return xx + yy;
// }
//
// }
// Path: src/action/SingletonAction.java
import java.util.HashMap;
import java.util.Map;
import model.Card;
import model.HaMap;
import model.Position;
package action;
public class SingletonAction {
public static final EndTurnAction endTurnAction = new EndTurnAction();
public static final PlayAgainAction playAgainAction = new PlayAgainAction();
public static final UndoAction undoAction = new UndoAction();
public static final Map<Card, SwapCardAction> swapActions = new HashMap<Card, SwapCardAction>();
static {
swapActions.put(Card.ARCHER, new SwapCardAction(Card.ARCHER));
swapActions.put(Card.CLERIC, new SwapCardAction(Card.CLERIC));
swapActions.put(Card.DRAGONSCALE, new SwapCardAction(Card.DRAGONSCALE));
swapActions.put(Card.INFERNO, new SwapCardAction(Card.INFERNO));
swapActions.put(Card.KNIGHT, new SwapCardAction(Card.KNIGHT));
swapActions.put(Card.NINJA, new SwapCardAction(Card.NINJA));
swapActions.put(Card.REVIVE_POTION, new SwapCardAction(
Card.REVIVE_POTION));
swapActions.put(Card.RUNEMETAL, new SwapCardAction(Card.RUNEMETAL));
swapActions.put(Card.SCROLL, new SwapCardAction(Card.SCROLL));
swapActions.put(Card.SHINING_HELM,
new SwapCardAction(Card.SHINING_HELM));
swapActions.put(Card.WIZARD, new SwapCardAction(Card.WIZARD));
}
| public static Position[][] positions; |
njustesen/hero-aicademy | src/action/SingletonAction.java | // Path: src/model/Card.java
// public enum Card {
//
// KNIGHT(CardType.UNIT),
// ARCHER(CardType.UNIT),
// CLERIC(CardType.UNIT),
// WIZARD(CardType.UNIT),
// NINJA(CardType.UNIT),
// INFERNO(CardType.SPELL),
// REVIVE_POTION(CardType.ITEM),
// RUNEMETAL(CardType.ITEM),
// SCROLL(CardType.ITEM),
// DRAGONSCALE(CardType.ITEM),
// SHINING_HELM(CardType.ITEM),
// CRYSTAL(CardType.UNIT);
//
// public final CardType type;
//
// Card(CardType type) {
// this.type = type;
// }
//
// }
//
// Path: src/model/HaMap.java
// public class HaMap {
//
// public String name;
// public int width;
// public int height;
// public SquareType[][] squares;
// public List<Position> assaultSquares;
// public List<Position> p1DeploySquares;
// public List<Position> p2DeploySquares;
// public List<Position> p1Crystals;
// public List<Position> p2Crystals;
//
// public HaMap(int width, int height, SquareType[][] squares, String name) {
// super();
// this.name = name;
// this.width = width;
// this.height = height;
// this.squares = squares;
// assaultSquares = new ArrayList<Position>();
// p1DeploySquares = new ArrayList<Position>();
// p2DeploySquares = new ArrayList<Position>();
// p1Crystals = new ArrayList<Position>();
// p2Crystals = new ArrayList<Position>();
// for (int x = 0; x < squares.length; x++)
// for (int y = 0; y < squares[0].length; y++) {
// if (squares[x][y] == SquareType.DEPLOY_1)
// p1DeploySquares.add(new Position(x, y));
// if (squares[x][y] == SquareType.DEPLOY_2)
// p2DeploySquares.add(new Position(x, y));
// if (squares[x][y] == SquareType.ASSAULT)
// assaultSquares.add(new Position(x, y));
// }
// }
//
// public SquareType squareAt(int x, int y) {
//
// return squares[x][y];
//
// }
//
// public SquareType squareAt(Position position) {
// return squareAt(position.x, position.y);
// }
//
// }
//
// Path: src/model/Position.java
// public class Position {
//
// public int x;
// public int y;
//
// public Position(int x, int y) {
// super();
// this.x = x;
// this.y = y;
// }
//
// public Position() {
// super();
// x = 0;
// y = 0;
// }
//
// public Direction getDirection(Position pos) {
// if (pos == null)
// return null;
// return Direction.direction(pos.x - x, pos.y - y);
// }
//
// public int hashCode() {
// int result = 1;
// result = 5 * result + x;
// result = 5 * result + y;
// return result;
// }
//
// @Override
// public String toString() {
// return "(" + x + "," + y + ")";
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj)
// return true;
// if (obj == null)
// return false;
// if (getClass() != obj.getClass())
// return false;
// final Position other = (Position) obj;
// if (x != other.x)
// return false;
// if (y != other.y)
// return false;
// return true;
// }
//
// public int distance(Position to) {
// int xx = x - to.x;
// if (xx < 0)
// xx = xx * (-1);
// int yy = y - to.y;
// if (yy < 0)
// yy = yy * (-1);
// return xx + yy;
// }
//
// }
| import java.util.HashMap;
import java.util.Map;
import model.Card;
import model.HaMap;
import model.Position; | package action;
public class SingletonAction {
public static final EndTurnAction endTurnAction = new EndTurnAction();
public static final PlayAgainAction playAgainAction = new PlayAgainAction();
public static final UndoAction undoAction = new UndoAction();
public static final Map<Card, SwapCardAction> swapActions = new HashMap<Card, SwapCardAction>();
static {
swapActions.put(Card.ARCHER, new SwapCardAction(Card.ARCHER));
swapActions.put(Card.CLERIC, new SwapCardAction(Card.CLERIC));
swapActions.put(Card.DRAGONSCALE, new SwapCardAction(Card.DRAGONSCALE));
swapActions.put(Card.INFERNO, new SwapCardAction(Card.INFERNO));
swapActions.put(Card.KNIGHT, new SwapCardAction(Card.KNIGHT));
swapActions.put(Card.NINJA, new SwapCardAction(Card.NINJA));
swapActions.put(Card.REVIVE_POTION, new SwapCardAction(
Card.REVIVE_POTION));
swapActions.put(Card.RUNEMETAL, new SwapCardAction(Card.RUNEMETAL));
swapActions.put(Card.SCROLL, new SwapCardAction(Card.SCROLL));
swapActions.put(Card.SHINING_HELM,
new SwapCardAction(Card.SHINING_HELM));
swapActions.put(Card.WIZARD, new SwapCardAction(Card.WIZARD));
}
public static Position[][] positions;
| // Path: src/model/Card.java
// public enum Card {
//
// KNIGHT(CardType.UNIT),
// ARCHER(CardType.UNIT),
// CLERIC(CardType.UNIT),
// WIZARD(CardType.UNIT),
// NINJA(CardType.UNIT),
// INFERNO(CardType.SPELL),
// REVIVE_POTION(CardType.ITEM),
// RUNEMETAL(CardType.ITEM),
// SCROLL(CardType.ITEM),
// DRAGONSCALE(CardType.ITEM),
// SHINING_HELM(CardType.ITEM),
// CRYSTAL(CardType.UNIT);
//
// public final CardType type;
//
// Card(CardType type) {
// this.type = type;
// }
//
// }
//
// Path: src/model/HaMap.java
// public class HaMap {
//
// public String name;
// public int width;
// public int height;
// public SquareType[][] squares;
// public List<Position> assaultSquares;
// public List<Position> p1DeploySquares;
// public List<Position> p2DeploySquares;
// public List<Position> p1Crystals;
// public List<Position> p2Crystals;
//
// public HaMap(int width, int height, SquareType[][] squares, String name) {
// super();
// this.name = name;
// this.width = width;
// this.height = height;
// this.squares = squares;
// assaultSquares = new ArrayList<Position>();
// p1DeploySquares = new ArrayList<Position>();
// p2DeploySquares = new ArrayList<Position>();
// p1Crystals = new ArrayList<Position>();
// p2Crystals = new ArrayList<Position>();
// for (int x = 0; x < squares.length; x++)
// for (int y = 0; y < squares[0].length; y++) {
// if (squares[x][y] == SquareType.DEPLOY_1)
// p1DeploySquares.add(new Position(x, y));
// if (squares[x][y] == SquareType.DEPLOY_2)
// p2DeploySquares.add(new Position(x, y));
// if (squares[x][y] == SquareType.ASSAULT)
// assaultSquares.add(new Position(x, y));
// }
// }
//
// public SquareType squareAt(int x, int y) {
//
// return squares[x][y];
//
// }
//
// public SquareType squareAt(Position position) {
// return squareAt(position.x, position.y);
// }
//
// }
//
// Path: src/model/Position.java
// public class Position {
//
// public int x;
// public int y;
//
// public Position(int x, int y) {
// super();
// this.x = x;
// this.y = y;
// }
//
// public Position() {
// super();
// x = 0;
// y = 0;
// }
//
// public Direction getDirection(Position pos) {
// if (pos == null)
// return null;
// return Direction.direction(pos.x - x, pos.y - y);
// }
//
// public int hashCode() {
// int result = 1;
// result = 5 * result + x;
// result = 5 * result + y;
// return result;
// }
//
// @Override
// public String toString() {
// return "(" + x + "," + y + ")";
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj)
// return true;
// if (obj == null)
// return false;
// if (getClass() != obj.getClass())
// return false;
// final Position other = (Position) obj;
// if (x != other.x)
// return false;
// if (y != other.y)
// return false;
// return true;
// }
//
// public int distance(Position to) {
// int xx = x - to.x;
// if (xx < 0)
// xx = xx * (-1);
// int yy = y - to.y;
// if (yy < 0)
// yy = yy * (-1);
// return xx + yy;
// }
//
// }
// Path: src/action/SingletonAction.java
import java.util.HashMap;
import java.util.Map;
import model.Card;
import model.HaMap;
import model.Position;
package action;
public class SingletonAction {
public static final EndTurnAction endTurnAction = new EndTurnAction();
public static final PlayAgainAction playAgainAction = new PlayAgainAction();
public static final UndoAction undoAction = new UndoAction();
public static final Map<Card, SwapCardAction> swapActions = new HashMap<Card, SwapCardAction>();
static {
swapActions.put(Card.ARCHER, new SwapCardAction(Card.ARCHER));
swapActions.put(Card.CLERIC, new SwapCardAction(Card.CLERIC));
swapActions.put(Card.DRAGONSCALE, new SwapCardAction(Card.DRAGONSCALE));
swapActions.put(Card.INFERNO, new SwapCardAction(Card.INFERNO));
swapActions.put(Card.KNIGHT, new SwapCardAction(Card.KNIGHT));
swapActions.put(Card.NINJA, new SwapCardAction(Card.NINJA));
swapActions.put(Card.REVIVE_POTION, new SwapCardAction(
Card.REVIVE_POTION));
swapActions.put(Card.RUNEMETAL, new SwapCardAction(Card.RUNEMETAL));
swapActions.put(Card.SCROLL, new SwapCardAction(Card.SCROLL));
swapActions.put(Card.SHINING_HELM,
new SwapCardAction(Card.SHINING_HELM));
swapActions.put(Card.WIZARD, new SwapCardAction(Card.WIZARD));
}
public static Position[][] positions;
| public static void init(HaMap map){ |
njustesen/hero-aicademy | test/CardSet/CardSetTest.java | // Path: src/model/Card.java
// public enum Card {
//
// KNIGHT(CardType.UNIT),
// ARCHER(CardType.UNIT),
// CLERIC(CardType.UNIT),
// WIZARD(CardType.UNIT),
// NINJA(CardType.UNIT),
// INFERNO(CardType.SPELL),
// REVIVE_POTION(CardType.ITEM),
// RUNEMETAL(CardType.ITEM),
// SCROLL(CardType.ITEM),
// DRAGONSCALE(CardType.ITEM),
// SHINING_HELM(CardType.ITEM),
// CRYSTAL(CardType.UNIT);
//
// public final CardType type;
//
// Card(CardType type) {
// this.type = type;
// }
//
// }
//
// Path: src/model/CardSet.java
// public class CardSet {
//
// public int[] cards;
// public int size;
// public int seed;
//
// public CardSet() {
// cards = new int[Card.values().length];
// size = 0;
// seed = (int) (Math.random() * 1000);
// }
//
// public CardSet(int seed) {
// cards = new int[Card.values().length];
// size = 0;
// this.seed = seed;
// }
//
// public Card determined() {
// if (seed > 100000)
// seed = (int) (seed * 0.1);
// else
// seed = (int) (seed * 1.3 + 7);
// return get(seed % size);
// }
//
// public Card random() {
// return get((int) Math.floor(Math.random() * size));
// }
//
// public Card get(Integer r) {
// int c = 0;
// int i = 0;
// while (true) {
// c += cards[i];
// if (c > r)
// break;
// i++;
// }
// return Card.values()[i];
// }
//
// public void add(Card card) {
// cards[card.ordinal()]++;
// size++;
// }
//
// public void remove(Card card) {
// if (cards[card.ordinal()] > 0) {
// cards[card.ordinal()]--;
// size--;
// }
// }
//
// public boolean hasUnits() {
// if (units() > 0)
// return true;
// return false;
// }
//
// public void addAll(CardSet other) {
// size += other.size;
// for (int i = 0; i < other.cards.length; i++)
// cards[i] += other.cards[i];
// }
//
// public void clear() {
// size = 0;
// Arrays.fill(cards, 0);
// }
//
// public boolean isEmpty() {
// return size == 0;
// }
//
// public void imitate(CardSet p1Hand) {
// clear();
// addAll(p1Hand);
// seed = p1Hand.seed;
// }
//
// public int units() {
// int units = 0;
// for (final Card card : Card.values())
// if (card.type == CardType.UNIT && card != Card.CRYSTAL)
// units += cards[card.ordinal()];
// return units;
// }
//
//
// public boolean has(Card card) {
// if (cards.length > card.ordinal())
// return cards[card.ordinal()] > 0 ? true : false;
// return false;
// }
//
// public boolean contains(Card card) {
// if (cards.length > card.ordinal())
// return cards[card.ordinal()] > 0;
// return false;
// }
//
// public int count(Card card) {
// if (cards.length > card.ordinal())
// return cards[card.ordinal()];
// return 0;
// }
//
// @Override
// public int hashCode() {
// int hash = 1;
// final int prime = 7;
// for (int i = 0; i < cards.length; i++)
// hash = hash * prime + cards[i];
// return hash;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj)
// return true;
// if (obj == null)
// return false;
// if (getClass() != obj.getClass())
// return false;
// final CardSet other = (CardSet) obj;
// if (!Arrays.equals(cards, other.cards))
// return false;
// return true;
// }
//
// @Override
// public String toString() {
// return Arrays.toString(cards).replaceAll(" ", "");
// }
//
//
// }
| import model.Card;
import model.CardSet; | package CardSet;
public class CardSetTest {
public static void main(String[] args){
CardSet set = new CardSet(); | // Path: src/model/Card.java
// public enum Card {
//
// KNIGHT(CardType.UNIT),
// ARCHER(CardType.UNIT),
// CLERIC(CardType.UNIT),
// WIZARD(CardType.UNIT),
// NINJA(CardType.UNIT),
// INFERNO(CardType.SPELL),
// REVIVE_POTION(CardType.ITEM),
// RUNEMETAL(CardType.ITEM),
// SCROLL(CardType.ITEM),
// DRAGONSCALE(CardType.ITEM),
// SHINING_HELM(CardType.ITEM),
// CRYSTAL(CardType.UNIT);
//
// public final CardType type;
//
// Card(CardType type) {
// this.type = type;
// }
//
// }
//
// Path: src/model/CardSet.java
// public class CardSet {
//
// public int[] cards;
// public int size;
// public int seed;
//
// public CardSet() {
// cards = new int[Card.values().length];
// size = 0;
// seed = (int) (Math.random() * 1000);
// }
//
// public CardSet(int seed) {
// cards = new int[Card.values().length];
// size = 0;
// this.seed = seed;
// }
//
// public Card determined() {
// if (seed > 100000)
// seed = (int) (seed * 0.1);
// else
// seed = (int) (seed * 1.3 + 7);
// return get(seed % size);
// }
//
// public Card random() {
// return get((int) Math.floor(Math.random() * size));
// }
//
// public Card get(Integer r) {
// int c = 0;
// int i = 0;
// while (true) {
// c += cards[i];
// if (c > r)
// break;
// i++;
// }
// return Card.values()[i];
// }
//
// public void add(Card card) {
// cards[card.ordinal()]++;
// size++;
// }
//
// public void remove(Card card) {
// if (cards[card.ordinal()] > 0) {
// cards[card.ordinal()]--;
// size--;
// }
// }
//
// public boolean hasUnits() {
// if (units() > 0)
// return true;
// return false;
// }
//
// public void addAll(CardSet other) {
// size += other.size;
// for (int i = 0; i < other.cards.length; i++)
// cards[i] += other.cards[i];
// }
//
// public void clear() {
// size = 0;
// Arrays.fill(cards, 0);
// }
//
// public boolean isEmpty() {
// return size == 0;
// }
//
// public void imitate(CardSet p1Hand) {
// clear();
// addAll(p1Hand);
// seed = p1Hand.seed;
// }
//
// public int units() {
// int units = 0;
// for (final Card card : Card.values())
// if (card.type == CardType.UNIT && card != Card.CRYSTAL)
// units += cards[card.ordinal()];
// return units;
// }
//
//
// public boolean has(Card card) {
// if (cards.length > card.ordinal())
// return cards[card.ordinal()] > 0 ? true : false;
// return false;
// }
//
// public boolean contains(Card card) {
// if (cards.length > card.ordinal())
// return cards[card.ordinal()] > 0;
// return false;
// }
//
// public int count(Card card) {
// if (cards.length > card.ordinal())
// return cards[card.ordinal()];
// return 0;
// }
//
// @Override
// public int hashCode() {
// int hash = 1;
// final int prime = 7;
// for (int i = 0; i < cards.length; i++)
// hash = hash * prime + cards[i];
// return hash;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj)
// return true;
// if (obj == null)
// return false;
// if (getClass() != obj.getClass())
// return false;
// final CardSet other = (CardSet) obj;
// if (!Arrays.equals(cards, other.cards))
// return false;
// return true;
// }
//
// @Override
// public String toString() {
// return Arrays.toString(cards).replaceAll(" ", "");
// }
//
//
// }
// Path: test/CardSet/CardSetTest.java
import model.Card;
import model.CardSet;
package CardSet;
public class CardSetTest {
public static void main(String[] args){
CardSet set = new CardSet(); | set.add(Card.ARCHER); |
stoussaint/spring-data-marklogic | src/test/java/com/_4dconcept/springframework/data/marklogic/repository/config/MarklogicRepositoryConfigurationExtensionTest.java | // Path: src/main/java/com/_4dconcept/springframework/data/marklogic/repository/MarklogicRepository.java
// @NoRepositoryBean
// public interface MarklogicRepository<T, ID>
// extends PagingAndSortingRepository<T, ID>, QueryByExampleExecutor<T> {
//
// /*
// * (non-Javadoc)
// * @see org.springframework.data.repository.CrudRepository#save(java.lang.Iterable)
// */
// <S extends T> List<S> saveAll(Iterable<S> entites);
//
// /*
// * (non-Javadoc)
// * @see org.springframework.data.repository.CrudRepository#findAll()
// */
// List<T> findAll();
//
// /*
// * (non-Javadoc)
// * @see org.springframework.data.repository.PagingAndSortingRepository#findAll(org.springframework.data.domain.Sort)
// */
// List<T> findAll(Sort sort);
//
// /*
// * (non-Javadoc)
// * @see org.springframework.data.repository.CrudRepository#findAll(java.lang.Iterable)
// */
// List<T> findAllById(Iterable<ID> ids);
//
// /* (non-Javadoc)
// * @see org.springframework.data.repository.query.QueryByExampleExecutor#findAll(org.springframework.data.domain.Example)
// */
// <S extends T> List<S> findAll(Example<S> example);
//
// /* (non-Javadoc)
// * @see org.springframework.data.repository.query.QueryByExampleExecutor#findAll(org.springframework.data.domain.Example, org.springframework.data.domain.Sort)
// */
// <S extends T> List<S> findAll(Example<S> example, Sort sort);
//
// }
| import java.util.Collection;
import static org.junit.Assert.fail;
import static org.mockito.Mockito.mock;
import com._4dconcept.springframework.data.marklogic.core.mapping.Document;
import com._4dconcept.springframework.data.marklogic.repository.MarklogicRepository;
import org.junit.Test;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.DefaultBeanNameGenerator;
import org.springframework.core.env.Environment;
import org.springframework.core.env.StandardEnvironment;
import org.springframework.core.io.ResourceLoader;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.core.type.AnnotationMetadata;
import org.springframework.data.repository.Repository;
import org.springframework.data.repository.config.AnnotationRepositoryConfigurationSource;
import org.springframework.data.repository.config.RepositoryConfiguration;
import org.springframework.data.repository.config.RepositoryConfigurationSource; | return;
}
}
fail("Expected to find config for repository interface ".concat(repositoryInterface.getName()).concat(" but got ")
.concat(configs.toString()));
}
private static void assertDoesNotHaveRepo(Class<?> repositoryInterface,
Collection<RepositoryConfiguration<RepositoryConfigurationSource>> configs) {
for (RepositoryConfiguration<?> config : configs) {
if (config.getRepositoryInterface().equals(repositoryInterface.getName())) {
fail("Expected not to find config for repository interface ".concat(repositoryInterface.getName()));
}
}
}
@EnableMarklogicRepositories(considerNestedRepositories = true)
static class Config {
}
@Document
static class Sample {}
interface SampleRepository extends Repository<Sample, Long> {}
interface UnannotatedRepository extends Repository<Object, Long> {}
| // Path: src/main/java/com/_4dconcept/springframework/data/marklogic/repository/MarklogicRepository.java
// @NoRepositoryBean
// public interface MarklogicRepository<T, ID>
// extends PagingAndSortingRepository<T, ID>, QueryByExampleExecutor<T> {
//
// /*
// * (non-Javadoc)
// * @see org.springframework.data.repository.CrudRepository#save(java.lang.Iterable)
// */
// <S extends T> List<S> saveAll(Iterable<S> entites);
//
// /*
// * (non-Javadoc)
// * @see org.springframework.data.repository.CrudRepository#findAll()
// */
// List<T> findAll();
//
// /*
// * (non-Javadoc)
// * @see org.springframework.data.repository.PagingAndSortingRepository#findAll(org.springframework.data.domain.Sort)
// */
// List<T> findAll(Sort sort);
//
// /*
// * (non-Javadoc)
// * @see org.springframework.data.repository.CrudRepository#findAll(java.lang.Iterable)
// */
// List<T> findAllById(Iterable<ID> ids);
//
// /* (non-Javadoc)
// * @see org.springframework.data.repository.query.QueryByExampleExecutor#findAll(org.springframework.data.domain.Example)
// */
// <S extends T> List<S> findAll(Example<S> example);
//
// /* (non-Javadoc)
// * @see org.springframework.data.repository.query.QueryByExampleExecutor#findAll(org.springframework.data.domain.Example, org.springframework.data.domain.Sort)
// */
// <S extends T> List<S> findAll(Example<S> example, Sort sort);
//
// }
// Path: src/test/java/com/_4dconcept/springframework/data/marklogic/repository/config/MarklogicRepositoryConfigurationExtensionTest.java
import java.util.Collection;
import static org.junit.Assert.fail;
import static org.mockito.Mockito.mock;
import com._4dconcept.springframework.data.marklogic.core.mapping.Document;
import com._4dconcept.springframework.data.marklogic.repository.MarklogicRepository;
import org.junit.Test;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.DefaultBeanNameGenerator;
import org.springframework.core.env.Environment;
import org.springframework.core.env.StandardEnvironment;
import org.springframework.core.io.ResourceLoader;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.core.type.AnnotationMetadata;
import org.springframework.data.repository.Repository;
import org.springframework.data.repository.config.AnnotationRepositoryConfigurationSource;
import org.springframework.data.repository.config.RepositoryConfiguration;
import org.springframework.data.repository.config.RepositoryConfigurationSource;
return;
}
}
fail("Expected to find config for repository interface ".concat(repositoryInterface.getName()).concat(" but got ")
.concat(configs.toString()));
}
private static void assertDoesNotHaveRepo(Class<?> repositoryInterface,
Collection<RepositoryConfiguration<RepositoryConfigurationSource>> configs) {
for (RepositoryConfiguration<?> config : configs) {
if (config.getRepositoryInterface().equals(repositoryInterface.getName())) {
fail("Expected not to find config for repository interface ".concat(repositoryInterface.getName()));
}
}
}
@EnableMarklogicRepositories(considerNestedRepositories = true)
static class Config {
}
@Document
static class Sample {}
interface SampleRepository extends Repository<Sample, Long> {}
interface UnannotatedRepository extends Repository<Object, Long> {}
| interface StoreRepository extends MarklogicRepository<Object, Long> {} |
stoussaint/spring-data-marklogic | src/test/java/com/_4dconcept/springframework/data/marklogic/MarklogicUtilsTest.java | // Path: src/test/java/com/_4dconcept/springframework/data/marklogic/repository/Person.java
// @Document(uri = "/contact/person/#{id}.xml")
// @Collection("#{entityClass.getSimpleName()}")
// @XmlRootElement
// public class Person {
//
// @Nullable private String id;
// private String firstname;
// private String lastname;
// private Integer age;
// private List<String> skills;
// private Boolean active;
//
// @Collection
// private String type;
//
// private List<String> extraCollections;
//
// private Address address;
//
// public Person() {}
//
// public Person(@Nullable String id, String firstname, String lastname, Integer age, String country) {
// this.id = id;
// this.firstname = firstname;
// this.lastname = lastname;
// this.age = age;
//
// address = new Address();
// address.setCountry(country);
// }
//
// @XmlElement()
// @Nullable
// public String getId() {
// return id;
// }
//
// public void setId(String id) {
// this.id = id;
// }
//
// public String getFirstname() {
// return firstname;
// }
//
// public void setFirstname(String firstname) {
// this.firstname = firstname;
// }
//
// public String getLastname() {
// return lastname;
// }
//
// public void setLastname(String lastname) {
// this.lastname = lastname;
// }
//
// public Integer getAge() {
// return age;
// }
//
// public void setAge(Integer age) {
// this.age = age;
// }
//
// public Address getAddress() {
// return address;
// }
//
// public void setAddress(Address address) {
// this.address = address;
// }
//
// public Boolean getActive() {
// return active;
// }
//
// public void setActive(Boolean active) {
// this.active = active;
// }
//
// @XmlElementWrapper(name = "skills")
// @XmlElement(name = "skill")
// public List<String> getSkills() {
// return skills;
// }
//
// public void setSkills(List<String> skills) {
// this.skills = skills;
// }
//
// public String getType() {
// return type;
// }
//
// public void setType(String type) {
// this.type = type;
// }
//
// @Collection(prefix = "extra")
// public List<String> getExtraCollections() {
// return extraCollections;
// }
//
// public void setExtraCollections(List<String> extraCollections) {
// this.extraCollections = extraCollections;
// }
//
// /* (non-Javadoc)
// * @see java.lang.Object#toString()
// */
// @Override
// public String toString() {
// return String.format("%s %s", firstname, lastname);
// }
//
// }
| import com._4dconcept.springframework.data.marklogic.repository.Person;
import org.junit.Test;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.MatcherAssert.assertThat; | package com._4dconcept.springframework.data.marklogic;
public class MarklogicUtilsTest {
@Test
public void checkCollectionExpansion() {
assertThat(MarklogicUtils.expandsExpression("myCollection", null), is("myCollection")); | // Path: src/test/java/com/_4dconcept/springframework/data/marklogic/repository/Person.java
// @Document(uri = "/contact/person/#{id}.xml")
// @Collection("#{entityClass.getSimpleName()}")
// @XmlRootElement
// public class Person {
//
// @Nullable private String id;
// private String firstname;
// private String lastname;
// private Integer age;
// private List<String> skills;
// private Boolean active;
//
// @Collection
// private String type;
//
// private List<String> extraCollections;
//
// private Address address;
//
// public Person() {}
//
// public Person(@Nullable String id, String firstname, String lastname, Integer age, String country) {
// this.id = id;
// this.firstname = firstname;
// this.lastname = lastname;
// this.age = age;
//
// address = new Address();
// address.setCountry(country);
// }
//
// @XmlElement()
// @Nullable
// public String getId() {
// return id;
// }
//
// public void setId(String id) {
// this.id = id;
// }
//
// public String getFirstname() {
// return firstname;
// }
//
// public void setFirstname(String firstname) {
// this.firstname = firstname;
// }
//
// public String getLastname() {
// return lastname;
// }
//
// public void setLastname(String lastname) {
// this.lastname = lastname;
// }
//
// public Integer getAge() {
// return age;
// }
//
// public void setAge(Integer age) {
// this.age = age;
// }
//
// public Address getAddress() {
// return address;
// }
//
// public void setAddress(Address address) {
// this.address = address;
// }
//
// public Boolean getActive() {
// return active;
// }
//
// public void setActive(Boolean active) {
// this.active = active;
// }
//
// @XmlElementWrapper(name = "skills")
// @XmlElement(name = "skill")
// public List<String> getSkills() {
// return skills;
// }
//
// public void setSkills(List<String> skills) {
// this.skills = skills;
// }
//
// public String getType() {
// return type;
// }
//
// public void setType(String type) {
// this.type = type;
// }
//
// @Collection(prefix = "extra")
// public List<String> getExtraCollections() {
// return extraCollections;
// }
//
// public void setExtraCollections(List<String> extraCollections) {
// this.extraCollections = extraCollections;
// }
//
// /* (non-Javadoc)
// * @see java.lang.Object#toString()
// */
// @Override
// public String toString() {
// return String.format("%s %s", firstname, lastname);
// }
//
// }
// Path: src/test/java/com/_4dconcept/springframework/data/marklogic/MarklogicUtilsTest.java
import com._4dconcept.springframework.data.marklogic.repository.Person;
import org.junit.Test;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
package com._4dconcept.springframework.data.marklogic;
public class MarklogicUtilsTest {
@Test
public void checkCollectionExpansion() {
assertThat(MarklogicUtils.expandsExpression("myCollection", null), is("myCollection")); | assertThat(MarklogicUtils.expandsExpression("#{entityClass.getSimpleName()}", Person.class), is("Person")); |
stoussaint/spring-data-marklogic | src/main/java/com/_4dconcept/springframework/data/marklogic/core/MarklogicOperations.java | // Path: src/main/java/com/_4dconcept/springframework/data/marklogic/core/convert/MarklogicConverter.java
// public interface MarklogicConverter extends
// EntityConverter<MarklogicPersistentEntity<?>, MarklogicPersistentProperty, Object, MarklogicContentHolder>,
// MarklogicWriter<Object>, MarklogicReader<Object> {
//
// }
//
// Path: src/main/java/com/_4dconcept/springframework/data/marklogic/core/query/Query.java
// public class Query {
//
// private long skip;
// private int limit;
// private @Nullable String collection;
// private @Nullable Criteria criteria;
// private List<SortCriteria> sortCriteria;
//
// public Query() {
// }
//
// public Query(Criteria criteria) {
// this.criteria = criteria;
// }
//
// /**
// * @return the skip
// */
// public long getSkip() {
// return skip;
// }
//
// /**
// * @param skip the skip to set
// */
// public void setSkip(long skip) {
// this.skip = skip;
// }
//
// /**
// * @return the limit
// */
// public int getLimit() {
// return limit;
// }
//
// /**
// * @param limit the limit to set
// */
// public void setLimit(int limit) {
// this.limit = limit;
// }
//
// /**
// * @return the collection
// */
// @Nullable
// public String getCollection() {
// return collection;
// }
//
// /**
// * @param collection the collection to set
// */
// public void setCollection(String collection) {
// this.collection = collection;
// }
//
// /**
// * @return the criteria
// */
// @Nullable
// public Criteria getCriteria() {
// return criteria;
// }
//
// /**
// * @param criteria the criteria to set
// */
// public void setCriteria(Criteria criteria) {
// this.criteria = criteria;
// }
//
// /**
// * @return the sortCriteria
// */
// public List<SortCriteria> getSortCriteria() {
// return sortCriteria == null ? Collections.emptyList() : sortCriteria;
// }
//
// /**
// * @param sortCriteria the sortCriteria to set
// */
// public void setSortCriteria(List<SortCriteria> sortCriteria) {
// this.sortCriteria = sortCriteria;
// }
// }
| import com._4dconcept.springframework.data.marklogic.core.convert.MarklogicConverter;
import com._4dconcept.springframework.data.marklogic.core.query.Query;
import org.springframework.lang.Nullable;
import java.util.List; | /**
* Retrieve the default collection of the given entity
* @param entity the entity
* @param options search options
* @param <T> The entity type
* @return the default collection
*/
@Nullable
<T> String resolveDefaultCollection(T entity, MarklogicOperationOptions options);
/**
* Retrieve the content idenfitier of the given entity
* @param entity the entity
* @param <T> The entity type
* @return the content identifier
*/
@Nullable
<T> Object resolveContentIdentifier(T entity);
/**
* Returns the number of documents for the given {@link Query}.
*
* @param query the query
* @return the number of content matching the query
*/
long count(Query query);
/**
* @return the underlying {@link MarklogicConverter}.
*/ | // Path: src/main/java/com/_4dconcept/springframework/data/marklogic/core/convert/MarklogicConverter.java
// public interface MarklogicConverter extends
// EntityConverter<MarklogicPersistentEntity<?>, MarklogicPersistentProperty, Object, MarklogicContentHolder>,
// MarklogicWriter<Object>, MarklogicReader<Object> {
//
// }
//
// Path: src/main/java/com/_4dconcept/springframework/data/marklogic/core/query/Query.java
// public class Query {
//
// private long skip;
// private int limit;
// private @Nullable String collection;
// private @Nullable Criteria criteria;
// private List<SortCriteria> sortCriteria;
//
// public Query() {
// }
//
// public Query(Criteria criteria) {
// this.criteria = criteria;
// }
//
// /**
// * @return the skip
// */
// public long getSkip() {
// return skip;
// }
//
// /**
// * @param skip the skip to set
// */
// public void setSkip(long skip) {
// this.skip = skip;
// }
//
// /**
// * @return the limit
// */
// public int getLimit() {
// return limit;
// }
//
// /**
// * @param limit the limit to set
// */
// public void setLimit(int limit) {
// this.limit = limit;
// }
//
// /**
// * @return the collection
// */
// @Nullable
// public String getCollection() {
// return collection;
// }
//
// /**
// * @param collection the collection to set
// */
// public void setCollection(String collection) {
// this.collection = collection;
// }
//
// /**
// * @return the criteria
// */
// @Nullable
// public Criteria getCriteria() {
// return criteria;
// }
//
// /**
// * @param criteria the criteria to set
// */
// public void setCriteria(Criteria criteria) {
// this.criteria = criteria;
// }
//
// /**
// * @return the sortCriteria
// */
// public List<SortCriteria> getSortCriteria() {
// return sortCriteria == null ? Collections.emptyList() : sortCriteria;
// }
//
// /**
// * @param sortCriteria the sortCriteria to set
// */
// public void setSortCriteria(List<SortCriteria> sortCriteria) {
// this.sortCriteria = sortCriteria;
// }
// }
// Path: src/main/java/com/_4dconcept/springframework/data/marklogic/core/MarklogicOperations.java
import com._4dconcept.springframework.data.marklogic.core.convert.MarklogicConverter;
import com._4dconcept.springframework.data.marklogic.core.query.Query;
import org.springframework.lang.Nullable;
import java.util.List;
/**
* Retrieve the default collection of the given entity
* @param entity the entity
* @param options search options
* @param <T> The entity type
* @return the default collection
*/
@Nullable
<T> String resolveDefaultCollection(T entity, MarklogicOperationOptions options);
/**
* Retrieve the content idenfitier of the given entity
* @param entity the entity
* @param <T> The entity type
* @return the content identifier
*/
@Nullable
<T> Object resolveContentIdentifier(T entity);
/**
* Returns the number of documents for the given {@link Query}.
*
* @param query the query
* @return the number of content matching the query
*/
long count(Query query);
/**
* @return the underlying {@link MarklogicConverter}.
*/ | MarklogicConverter getConverter(); |
stoussaint/spring-data-marklogic | src/test/java/com/_4dconcept/springframework/data/marklogic/core/mapping/BasicMarklogicPersistentPropertyTest.java | // Path: src/test/java/com/_4dconcept/springframework/data/marklogic/core/mapping/namespaceaware/SuperType.java
// public class SuperType {
//
// private String id;
//
// /**
// * @return the id
// */
// public String getId() {
// return id;
// }
//
// /**
// * @param id the id to set
// */
// public void setId(String id) {
// this.id = id;
// }
// }
| import static org.hamcrest.MatcherAssert.assertThat;
import com._4dconcept.springframework.data.marklogic.core.mapping.namespaceaware.SuperType;
import org.junit.Test;
import org.springframework.data.annotation.Id;
import org.springframework.data.mapping.model.Property;
import org.springframework.data.mapping.model.SimpleTypeHolder;
import org.springframework.data.util.ClassTypeInformation;
import org.springframework.util.ReflectionUtils;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;
import javax.xml.namespace.QName;
import java.lang.reflect.Field;
import static org.hamcrest.CoreMatchers.is; | }
@Test
public void resolveQName() {
checkPropertyQName("id", "/super/type");
checkPropertyQName("name", "/test/type");
checkPropertyQName("sample", "/test/classtype");
checkPropertyQName("surname", "/test/classtype");
}
class Person {
@Id
String id;
String firstname;
String lastname;
}
class Company {
String id;
String name;
}
class Identifier {
@Id
String uuid;
String id;
}
@XmlTransient | // Path: src/test/java/com/_4dconcept/springframework/data/marklogic/core/mapping/namespaceaware/SuperType.java
// public class SuperType {
//
// private String id;
//
// /**
// * @return the id
// */
// public String getId() {
// return id;
// }
//
// /**
// * @param id the id to set
// */
// public void setId(String id) {
// this.id = id;
// }
// }
// Path: src/test/java/com/_4dconcept/springframework/data/marklogic/core/mapping/BasicMarklogicPersistentPropertyTest.java
import static org.hamcrest.MatcherAssert.assertThat;
import com._4dconcept.springframework.data.marklogic.core.mapping.namespaceaware.SuperType;
import org.junit.Test;
import org.springframework.data.annotation.Id;
import org.springframework.data.mapping.model.Property;
import org.springframework.data.mapping.model.SimpleTypeHolder;
import org.springframework.data.util.ClassTypeInformation;
import org.springframework.util.ReflectionUtils;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;
import javax.xml.namespace.QName;
import java.lang.reflect.Field;
import static org.hamcrest.CoreMatchers.is;
}
@Test
public void resolveQName() {
checkPropertyQName("id", "/super/type");
checkPropertyQName("name", "/test/type");
checkPropertyQName("sample", "/test/classtype");
checkPropertyQName("surname", "/test/classtype");
}
class Person {
@Id
String id;
String firstname;
String lastname;
}
class Company {
String id;
String name;
}
class Identifier {
@Id
String uuid;
String id;
}
@XmlTransient | class AbstractType extends SuperType { |
stoussaint/spring-data-marklogic | src/main/java/com/_4dconcept/springframework/data/marklogic/MarklogicUtils.java | // Path: src/main/java/com/_4dconcept/springframework/data/marklogic/core/mapping/MarklogicPersistentEntity.java
// public interface MarklogicPersistentEntity<T> extends PersistentEntity<T, MarklogicPersistentProperty> {
//
// /**
// * @return the uri the entity shall be persisted to.
// */
// String getUri();
//
// /**
// * @return the default defaultCollection the entity should be created with
// */
// String getDefaultCollection();
//
// /**
// * @return true if the id is to be found in property fragment
// */
// boolean idInPropertyFragment();
//
// }
//
// Path: src/main/java/com/_4dconcept/springframework/data/marklogic/core/mapping/MarklogicPersistentProperty.java
// public interface MarklogicPersistentProperty extends PersistentProperty<MarklogicPersistentProperty> {
//
// /**
// * @return whether the property is explicitly marked as an identifier property of the owning {@link PersistentEntity}.
// */
// boolean isExplicitIdProperty();
//
// /**
// * @return the full qualified name of the property
// */
// QName getQName();
//
// Optional<Method> getReadMethod();
//
// }
| import com._4dconcept.springframework.data.marklogic.core.mapping.MarklogicPersistentEntity;
import com._4dconcept.springframework.data.marklogic.core.mapping.MarklogicPersistentProperty;
import org.springframework.dao.InvalidDataAccessApiUsageException;
import org.springframework.dao.TypeMismatchDataAccessException;
import org.springframework.data.mapping.context.MappingContext;
import org.springframework.expression.Expression;
import org.springframework.expression.ParserContext;
import org.springframework.expression.common.LiteralExpression;
import org.springframework.expression.spel.standard.SpelExpressionParser;
import org.springframework.lang.Nullable;
import org.springframework.util.StringUtils;
import java.util.function.Supplier; | package com._4dconcept.springframework.data.marklogic;
/**
* Helper class featuring helper methods for working with Marklogic specific elements.
* Mainly intended for internal use within the framework.
*
* @author stoussaint
* @since 2017-11-30
*/
public final class MarklogicUtils {
private static final SpelExpressionParser PARSER = new SpelExpressionParser();
/**
* Private constructor to prevent instantiation.
*/
private MarklogicUtils() {}
/**
* Expands the given expression using the provided type as context.
*
* @param expression the expression to expand
* @param entityType the entityType used as context
* @return the expanded expression. If the given expression is a literal or null, it is return as it.
*/
@Nullable
public static String expandsExpression(@Nullable String expression, @Nullable Class<?> entityType) {
return expandsExpression(expression, entityType, null, null);
}
/**
* Expands the given expression using the provided type, entity and id as context.
*
* @param expression the expression to expand
* @param entityType the entityType used as context
* @param entity the entity to use as context
* @return the expanded expression. If the given expression is a literal or null, it is return as it.
*/
@Nullable
public static String expandsExpression(@Nullable String expression, @Nullable Class<?> entityType, @Nullable Object entity, @Nullable Supplier<Object> idSupplier) {
return expandsExpression(expression, new DocumentExpressionContext() {
@Override
public Class<?> getEntityClass() {
return entityType;
}
@Override
public Object getEntity() {
return entity;
}
@Override
public Object getId() {
return idSupplier != null ? idSupplier.get() : null;
}
});
}
@Nullable | // Path: src/main/java/com/_4dconcept/springframework/data/marklogic/core/mapping/MarklogicPersistentEntity.java
// public interface MarklogicPersistentEntity<T> extends PersistentEntity<T, MarklogicPersistentProperty> {
//
// /**
// * @return the uri the entity shall be persisted to.
// */
// String getUri();
//
// /**
// * @return the default defaultCollection the entity should be created with
// */
// String getDefaultCollection();
//
// /**
// * @return true if the id is to be found in property fragment
// */
// boolean idInPropertyFragment();
//
// }
//
// Path: src/main/java/com/_4dconcept/springframework/data/marklogic/core/mapping/MarklogicPersistentProperty.java
// public interface MarklogicPersistentProperty extends PersistentProperty<MarklogicPersistentProperty> {
//
// /**
// * @return whether the property is explicitly marked as an identifier property of the owning {@link PersistentEntity}.
// */
// boolean isExplicitIdProperty();
//
// /**
// * @return the full qualified name of the property
// */
// QName getQName();
//
// Optional<Method> getReadMethod();
//
// }
// Path: src/main/java/com/_4dconcept/springframework/data/marklogic/MarklogicUtils.java
import com._4dconcept.springframework.data.marklogic.core.mapping.MarklogicPersistentEntity;
import com._4dconcept.springframework.data.marklogic.core.mapping.MarklogicPersistentProperty;
import org.springframework.dao.InvalidDataAccessApiUsageException;
import org.springframework.dao.TypeMismatchDataAccessException;
import org.springframework.data.mapping.context.MappingContext;
import org.springframework.expression.Expression;
import org.springframework.expression.ParserContext;
import org.springframework.expression.common.LiteralExpression;
import org.springframework.expression.spel.standard.SpelExpressionParser;
import org.springframework.lang.Nullable;
import org.springframework.util.StringUtils;
import java.util.function.Supplier;
package com._4dconcept.springframework.data.marklogic;
/**
* Helper class featuring helper methods for working with Marklogic specific elements.
* Mainly intended for internal use within the framework.
*
* @author stoussaint
* @since 2017-11-30
*/
public final class MarklogicUtils {
private static final SpelExpressionParser PARSER = new SpelExpressionParser();
/**
* Private constructor to prevent instantiation.
*/
private MarklogicUtils() {}
/**
* Expands the given expression using the provided type as context.
*
* @param expression the expression to expand
* @param entityType the entityType used as context
* @return the expanded expression. If the given expression is a literal or null, it is return as it.
*/
@Nullable
public static String expandsExpression(@Nullable String expression, @Nullable Class<?> entityType) {
return expandsExpression(expression, entityType, null, null);
}
/**
* Expands the given expression using the provided type, entity and id as context.
*
* @param expression the expression to expand
* @param entityType the entityType used as context
* @param entity the entity to use as context
* @return the expanded expression. If the given expression is a literal or null, it is return as it.
*/
@Nullable
public static String expandsExpression(@Nullable String expression, @Nullable Class<?> entityType, @Nullable Object entity, @Nullable Supplier<Object> idSupplier) {
return expandsExpression(expression, new DocumentExpressionContext() {
@Override
public Class<?> getEntityClass() {
return entityType;
}
@Override
public Object getEntity() {
return entity;
}
@Override
public Object getId() {
return idSupplier != null ? idSupplier.get() : null;
}
});
}
@Nullable | public static Object retrieveIdentifier(Object object, MappingContext<? extends MarklogicPersistentEntity<?>, MarklogicPersistentProperty> mappingContext) { |
stoussaint/spring-data-marklogic | src/main/java/com/_4dconcept/springframework/data/marklogic/MarklogicUtils.java | // Path: src/main/java/com/_4dconcept/springframework/data/marklogic/core/mapping/MarklogicPersistentEntity.java
// public interface MarklogicPersistentEntity<T> extends PersistentEntity<T, MarklogicPersistentProperty> {
//
// /**
// * @return the uri the entity shall be persisted to.
// */
// String getUri();
//
// /**
// * @return the default defaultCollection the entity should be created with
// */
// String getDefaultCollection();
//
// /**
// * @return true if the id is to be found in property fragment
// */
// boolean idInPropertyFragment();
//
// }
//
// Path: src/main/java/com/_4dconcept/springframework/data/marklogic/core/mapping/MarklogicPersistentProperty.java
// public interface MarklogicPersistentProperty extends PersistentProperty<MarklogicPersistentProperty> {
//
// /**
// * @return whether the property is explicitly marked as an identifier property of the owning {@link PersistentEntity}.
// */
// boolean isExplicitIdProperty();
//
// /**
// * @return the full qualified name of the property
// */
// QName getQName();
//
// Optional<Method> getReadMethod();
//
// }
| import com._4dconcept.springframework.data.marklogic.core.mapping.MarklogicPersistentEntity;
import com._4dconcept.springframework.data.marklogic.core.mapping.MarklogicPersistentProperty;
import org.springframework.dao.InvalidDataAccessApiUsageException;
import org.springframework.dao.TypeMismatchDataAccessException;
import org.springframework.data.mapping.context.MappingContext;
import org.springframework.expression.Expression;
import org.springframework.expression.ParserContext;
import org.springframework.expression.common.LiteralExpression;
import org.springframework.expression.spel.standard.SpelExpressionParser;
import org.springframework.lang.Nullable;
import org.springframework.util.StringUtils;
import java.util.function.Supplier; | package com._4dconcept.springframework.data.marklogic;
/**
* Helper class featuring helper methods for working with Marklogic specific elements.
* Mainly intended for internal use within the framework.
*
* @author stoussaint
* @since 2017-11-30
*/
public final class MarklogicUtils {
private static final SpelExpressionParser PARSER = new SpelExpressionParser();
/**
* Private constructor to prevent instantiation.
*/
private MarklogicUtils() {}
/**
* Expands the given expression using the provided type as context.
*
* @param expression the expression to expand
* @param entityType the entityType used as context
* @return the expanded expression. If the given expression is a literal or null, it is return as it.
*/
@Nullable
public static String expandsExpression(@Nullable String expression, @Nullable Class<?> entityType) {
return expandsExpression(expression, entityType, null, null);
}
/**
* Expands the given expression using the provided type, entity and id as context.
*
* @param expression the expression to expand
* @param entityType the entityType used as context
* @param entity the entity to use as context
* @return the expanded expression. If the given expression is a literal or null, it is return as it.
*/
@Nullable
public static String expandsExpression(@Nullable String expression, @Nullable Class<?> entityType, @Nullable Object entity, @Nullable Supplier<Object> idSupplier) {
return expandsExpression(expression, new DocumentExpressionContext() {
@Override
public Class<?> getEntityClass() {
return entityType;
}
@Override
public Object getEntity() {
return entity;
}
@Override
public Object getId() {
return idSupplier != null ? idSupplier.get() : null;
}
});
}
@Nullable | // Path: src/main/java/com/_4dconcept/springframework/data/marklogic/core/mapping/MarklogicPersistentEntity.java
// public interface MarklogicPersistentEntity<T> extends PersistentEntity<T, MarklogicPersistentProperty> {
//
// /**
// * @return the uri the entity shall be persisted to.
// */
// String getUri();
//
// /**
// * @return the default defaultCollection the entity should be created with
// */
// String getDefaultCollection();
//
// /**
// * @return true if the id is to be found in property fragment
// */
// boolean idInPropertyFragment();
//
// }
//
// Path: src/main/java/com/_4dconcept/springframework/data/marklogic/core/mapping/MarklogicPersistentProperty.java
// public interface MarklogicPersistentProperty extends PersistentProperty<MarklogicPersistentProperty> {
//
// /**
// * @return whether the property is explicitly marked as an identifier property of the owning {@link PersistentEntity}.
// */
// boolean isExplicitIdProperty();
//
// /**
// * @return the full qualified name of the property
// */
// QName getQName();
//
// Optional<Method> getReadMethod();
//
// }
// Path: src/main/java/com/_4dconcept/springframework/data/marklogic/MarklogicUtils.java
import com._4dconcept.springframework.data.marklogic.core.mapping.MarklogicPersistentEntity;
import com._4dconcept.springframework.data.marklogic.core.mapping.MarklogicPersistentProperty;
import org.springframework.dao.InvalidDataAccessApiUsageException;
import org.springframework.dao.TypeMismatchDataAccessException;
import org.springframework.data.mapping.context.MappingContext;
import org.springframework.expression.Expression;
import org.springframework.expression.ParserContext;
import org.springframework.expression.common.LiteralExpression;
import org.springframework.expression.spel.standard.SpelExpressionParser;
import org.springframework.lang.Nullable;
import org.springframework.util.StringUtils;
import java.util.function.Supplier;
package com._4dconcept.springframework.data.marklogic;
/**
* Helper class featuring helper methods for working with Marklogic specific elements.
* Mainly intended for internal use within the framework.
*
* @author stoussaint
* @since 2017-11-30
*/
public final class MarklogicUtils {
private static final SpelExpressionParser PARSER = new SpelExpressionParser();
/**
* Private constructor to prevent instantiation.
*/
private MarklogicUtils() {}
/**
* Expands the given expression using the provided type as context.
*
* @param expression the expression to expand
* @param entityType the entityType used as context
* @return the expanded expression. If the given expression is a literal or null, it is return as it.
*/
@Nullable
public static String expandsExpression(@Nullable String expression, @Nullable Class<?> entityType) {
return expandsExpression(expression, entityType, null, null);
}
/**
* Expands the given expression using the provided type, entity and id as context.
*
* @param expression the expression to expand
* @param entityType the entityType used as context
* @param entity the entity to use as context
* @return the expanded expression. If the given expression is a literal or null, it is return as it.
*/
@Nullable
public static String expandsExpression(@Nullable String expression, @Nullable Class<?> entityType, @Nullable Object entity, @Nullable Supplier<Object> idSupplier) {
return expandsExpression(expression, new DocumentExpressionContext() {
@Override
public Class<?> getEntityClass() {
return entityType;
}
@Override
public Object getEntity() {
return entity;
}
@Override
public Object getId() {
return idSupplier != null ? idSupplier.get() : null;
}
});
}
@Nullable | public static Object retrieveIdentifier(Object object, MappingContext<? extends MarklogicPersistentEntity<?>, MarklogicPersistentProperty> mappingContext) { |
stoussaint/spring-data-marklogic | src/main/java/com/_4dconcept/springframework/data/marklogic/repository/support/MappingMarklogicEntityInformation.java | // Path: src/main/java/com/_4dconcept/springframework/data/marklogic/core/mapping/MarklogicPersistentEntity.java
// public interface MarklogicPersistentEntity<T> extends PersistentEntity<T, MarklogicPersistentProperty> {
//
// /**
// * @return the uri the entity shall be persisted to.
// */
// String getUri();
//
// /**
// * @return the default defaultCollection the entity should be created with
// */
// String getDefaultCollection();
//
// /**
// * @return true if the id is to be found in property fragment
// */
// boolean idInPropertyFragment();
//
// }
//
// Path: src/main/java/com/_4dconcept/springframework/data/marklogic/repository/query/MarklogicEntityInformation.java
// public interface MarklogicEntityInformation<T, ID> extends EntityInformation<T, ID> {
//
// /**
// * @return the uri the entity shall be persisted to.
// */
// String getUri();
//
// /**
// * @return the default collection the entity will be persisted in
// */
// String getDefaultCollection();
//
// /**
// * @return true if the id element is expected to be find in property fragment
// */
// boolean idInPropertyFragment();
//
// }
| import com._4dconcept.springframework.data.marklogic.core.mapping.MarklogicPersistentEntity;
import com._4dconcept.springframework.data.marklogic.repository.query.MarklogicEntityInformation;
import org.springframework.data.repository.core.support.PersistentEntityInformation;
import org.springframework.lang.Nullable; | /*
* Copyright 2017 the original author or authors.
*
* 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._4dconcept.springframework.data.marklogic.repository.support;
/**
* {@link MarklogicEntityInformation} implementation using a {@link MarklogicPersistentEntity} instance to lookup the necessary
* information. Can be configured with a custom uri or default collection to be returned which will override the one returned by the
* {@link MarklogicPersistentEntity} if given.
*
* @author Stéphane Toussaint
*/
public class MappingMarklogicEntityInformation<T, ID> extends PersistentEntityInformation<T, ID>
implements MarklogicEntityInformation<T, ID> {
| // Path: src/main/java/com/_4dconcept/springframework/data/marklogic/core/mapping/MarklogicPersistentEntity.java
// public interface MarklogicPersistentEntity<T> extends PersistentEntity<T, MarklogicPersistentProperty> {
//
// /**
// * @return the uri the entity shall be persisted to.
// */
// String getUri();
//
// /**
// * @return the default defaultCollection the entity should be created with
// */
// String getDefaultCollection();
//
// /**
// * @return true if the id is to be found in property fragment
// */
// boolean idInPropertyFragment();
//
// }
//
// Path: src/main/java/com/_4dconcept/springframework/data/marklogic/repository/query/MarklogicEntityInformation.java
// public interface MarklogicEntityInformation<T, ID> extends EntityInformation<T, ID> {
//
// /**
// * @return the uri the entity shall be persisted to.
// */
// String getUri();
//
// /**
// * @return the default collection the entity will be persisted in
// */
// String getDefaultCollection();
//
// /**
// * @return true if the id element is expected to be find in property fragment
// */
// boolean idInPropertyFragment();
//
// }
// Path: src/main/java/com/_4dconcept/springframework/data/marklogic/repository/support/MappingMarklogicEntityInformation.java
import com._4dconcept.springframework.data.marklogic.core.mapping.MarklogicPersistentEntity;
import com._4dconcept.springframework.data.marklogic.repository.query.MarklogicEntityInformation;
import org.springframework.data.repository.core.support.PersistentEntityInformation;
import org.springframework.lang.Nullable;
/*
* Copyright 2017 the original author or authors.
*
* 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._4dconcept.springframework.data.marklogic.repository.support;
/**
* {@link MarklogicEntityInformation} implementation using a {@link MarklogicPersistentEntity} instance to lookup the necessary
* information. Can be configured with a custom uri or default collection to be returned which will override the one returned by the
* {@link MarklogicPersistentEntity} if given.
*
* @author Stéphane Toussaint
*/
public class MappingMarklogicEntityInformation<T, ID> extends PersistentEntityInformation<T, ID>
implements MarklogicEntityInformation<T, ID> {
| private final MarklogicPersistentEntity<T> entityMetadata; |
stoussaint/spring-data-marklogic | src/main/java/com/_4dconcept/springframework/data/marklogic/core/mapping/BasicMarklogicPersistentEntity.java | // Path: src/main/java/com/_4dconcept/springframework/data/marklogic/MarklogicUrlUtils.java
// public abstract class MarklogicUrlUtils {
//
// /**
// * Private constructor to prevent instantiation.
// */
// private MarklogicUrlUtils() {}
//
// /**
// * Obtains the uri name to use for the provided class
// *
// * @param entityClass The class to determine the preferred uri name for
// * @return The preferred rul name
// */
// public static String getPreferredUrlPattern(Class<?> entityClass) {
// String URL_PREFIX = "/content/";
// String URL_SUFFIX = "/#{id}.xml";
// return URL_PREFIX + entityClass.getSimpleName().toLowerCase() + URL_SUFFIX;
// }
// }
| import com._4dconcept.springframework.data.marklogic.MarklogicUrlUtils;
import org.springframework.data.mapping.MappingException;
import org.springframework.data.mapping.model.BasicPersistentEntity;
import org.springframework.data.util.TypeInformation;
import org.springframework.lang.Nullable;
import org.springframework.util.StringUtils;
import java.util.Comparator; | /*
* Copyright 2017 the original author or authors.
*
* 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._4dconcept.springframework.data.marklogic.core.mapping;
/**
* Specialized value object to capture information of {@link MarklogicPersistentEntity}s.
* It provide access to entity 'uri', 'defaultCollection'
*
* @author Stéphane Toussaint
*/
public class BasicMarklogicPersistentEntity<T> extends BasicPersistentEntity<T, MarklogicPersistentProperty> implements MarklogicPersistentEntity<T> {
private final String uri;
private @Nullable final String defaultCollection;
private final boolean idInPropertyFragment;
BasicMarklogicPersistentEntity(TypeInformation<T> information) {
this(information, null);
}
private BasicMarklogicPersistentEntity(TypeInformation<T> information, @Nullable Comparator<MarklogicPersistentProperty> comparator) {
super(information, comparator);
Class<T> rawType = getTypeInformation().getType(); | // Path: src/main/java/com/_4dconcept/springframework/data/marklogic/MarklogicUrlUtils.java
// public abstract class MarklogicUrlUtils {
//
// /**
// * Private constructor to prevent instantiation.
// */
// private MarklogicUrlUtils() {}
//
// /**
// * Obtains the uri name to use for the provided class
// *
// * @param entityClass The class to determine the preferred uri name for
// * @return The preferred rul name
// */
// public static String getPreferredUrlPattern(Class<?> entityClass) {
// String URL_PREFIX = "/content/";
// String URL_SUFFIX = "/#{id}.xml";
// return URL_PREFIX + entityClass.getSimpleName().toLowerCase() + URL_SUFFIX;
// }
// }
// Path: src/main/java/com/_4dconcept/springframework/data/marklogic/core/mapping/BasicMarklogicPersistentEntity.java
import com._4dconcept.springframework.data.marklogic.MarklogicUrlUtils;
import org.springframework.data.mapping.MappingException;
import org.springframework.data.mapping.model.BasicPersistentEntity;
import org.springframework.data.util.TypeInformation;
import org.springframework.lang.Nullable;
import org.springframework.util.StringUtils;
import java.util.Comparator;
/*
* Copyright 2017 the original author or authors.
*
* 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._4dconcept.springframework.data.marklogic.core.mapping;
/**
* Specialized value object to capture information of {@link MarklogicPersistentEntity}s.
* It provide access to entity 'uri', 'defaultCollection'
*
* @author Stéphane Toussaint
*/
public class BasicMarklogicPersistentEntity<T> extends BasicPersistentEntity<T, MarklogicPersistentProperty> implements MarklogicPersistentEntity<T> {
private final String uri;
private @Nullable final String defaultCollection;
private final boolean idInPropertyFragment;
BasicMarklogicPersistentEntity(TypeInformation<T> information) {
this(information, null);
}
private BasicMarklogicPersistentEntity(TypeInformation<T> information, @Nullable Comparator<MarklogicPersistentProperty> comparator) {
super(information, comparator);
Class<T> rawType = getTypeInformation().getType(); | String fallback = MarklogicUrlUtils.getPreferredUrlPattern(rawType); |
stoussaint/spring-data-marklogic | src/test/java/com/_4dconcept/springframework/data/marklogic/core/convert/MappingMarklogicConverterTest.java | // Path: src/main/java/com/_4dconcept/springframework/data/marklogic/core/mapping/MarklogicMappingContext.java
// public class MarklogicMappingContext extends AbstractMappingContext<BasicMarklogicPersistentEntity<?>, MarklogicPersistentProperty> {
//
// @Override
// protected <T> BasicMarklogicPersistentEntity<T> createPersistentEntity(TypeInformation<T> typeInformation) {
// return new BasicMarklogicPersistentEntity<>(typeInformation);
// }
//
// @Override
// protected MarklogicPersistentProperty createPersistentProperty(Property property,
// BasicMarklogicPersistentEntity<?> owner, SimpleTypeHolder simpleTypeHolder) {
// return new BasicMarklogicPersistentProperty(property, owner, simpleTypeHolder);
// }
// }
| import static org.hamcrest.MatcherAssert.assertThat;
import com._4dconcept.springframework.data.marklogic.core.mapping.Collection;
import com._4dconcept.springframework.data.marklogic.core.mapping.Document;
import com._4dconcept.springframework.data.marklogic.core.mapping.MarklogicMappingContext;
import org.hamcrest.CoreMatchers;
import org.junit.Test;
import org.springframework.core.convert.ConverterNotFoundException;
import org.springframework.core.convert.TypeDescriptor;
import org.springframework.core.convert.converter.ConditionalGenericConverter;
import org.springframework.core.convert.converter.GenericConverter;
import org.springframework.lang.Nullable;
import java.util.Arrays;
import java.util.Collections;
import java.util.Set; | public Set<ConvertiblePair> getConvertibleTypes() {
return Collections.singleton(new ConvertiblePair(ConvertibleObject.class, String.class));
}
@Override
public Object convert(@Nullable Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
return "<empty />";
}
}
static class DocumentConverter implements ConditionalGenericConverter {
@Override
public boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType) {
return sourceType.getObjectType().isAnnotationPresent(Document.class);
}
@Override
public Set<ConvertiblePair> getConvertibleTypes() {
return Collections.singleton(new ConvertiblePair(Object.class, String.class));
}
@Override
public Object convert(@Nullable Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
return "<person><id>1</id></person>";
}
}
private MappingMarklogicConverter createConverterWithDelegates(GenericConverter... converters) { | // Path: src/main/java/com/_4dconcept/springframework/data/marklogic/core/mapping/MarklogicMappingContext.java
// public class MarklogicMappingContext extends AbstractMappingContext<BasicMarklogicPersistentEntity<?>, MarklogicPersistentProperty> {
//
// @Override
// protected <T> BasicMarklogicPersistentEntity<T> createPersistentEntity(TypeInformation<T> typeInformation) {
// return new BasicMarklogicPersistentEntity<>(typeInformation);
// }
//
// @Override
// protected MarklogicPersistentProperty createPersistentProperty(Property property,
// BasicMarklogicPersistentEntity<?> owner, SimpleTypeHolder simpleTypeHolder) {
// return new BasicMarklogicPersistentProperty(property, owner, simpleTypeHolder);
// }
// }
// Path: src/test/java/com/_4dconcept/springframework/data/marklogic/core/convert/MappingMarklogicConverterTest.java
import static org.hamcrest.MatcherAssert.assertThat;
import com._4dconcept.springframework.data.marklogic.core.mapping.Collection;
import com._4dconcept.springframework.data.marklogic.core.mapping.Document;
import com._4dconcept.springframework.data.marklogic.core.mapping.MarklogicMappingContext;
import org.hamcrest.CoreMatchers;
import org.junit.Test;
import org.springframework.core.convert.ConverterNotFoundException;
import org.springframework.core.convert.TypeDescriptor;
import org.springframework.core.convert.converter.ConditionalGenericConverter;
import org.springframework.core.convert.converter.GenericConverter;
import org.springframework.lang.Nullable;
import java.util.Arrays;
import java.util.Collections;
import java.util.Set;
public Set<ConvertiblePair> getConvertibleTypes() {
return Collections.singleton(new ConvertiblePair(ConvertibleObject.class, String.class));
}
@Override
public Object convert(@Nullable Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
return "<empty />";
}
}
static class DocumentConverter implements ConditionalGenericConverter {
@Override
public boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType) {
return sourceType.getObjectType().isAnnotationPresent(Document.class);
}
@Override
public Set<ConvertiblePair> getConvertibleTypes() {
return Collections.singleton(new ConvertiblePair(Object.class, String.class));
}
@Override
public Object convert(@Nullable Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
return "<person><id>1</id></person>";
}
}
private MappingMarklogicConverter createConverterWithDelegates(GenericConverter... converters) { | MappingMarklogicConverter mappingMarklogicConverter = new MappingMarklogicConverter(new MarklogicMappingContext()); |
stoussaint/spring-data-marklogic | src/main/java/com/_4dconcept/springframework/data/marklogic/core/mapping/BasicMarklogicPersistentProperty.java | // Path: src/main/java/com/_4dconcept/springframework/data/marklogic/MarklogicTypeUtils.java
// public class MarklogicTypeUtils {
//
// private static final Logger LOGGER = LoggerFactory.getLogger(MarklogicTypeUtils.class);
//
// private static final Map<Class<?>,Class<?>> PRIMITIVE_MAP = new HashMap<>();
//
// static {
// PRIMITIVE_MAP.put(boolean.class, Boolean.class);
// PRIMITIVE_MAP.put(byte.class, Byte.class);
// PRIMITIVE_MAP.put(char.class, Character.class);
// PRIMITIVE_MAP.put(short.class, Short.class);
// PRIMITIVE_MAP.put(int.class, Integer.class);
// PRIMITIVE_MAP.put(long.class, Long.class);
// PRIMITIVE_MAP.put(float.class, Float.class);
// PRIMITIVE_MAP.put(double.class, Double.class);
// }
//
// private MarklogicTypeUtils() {}
//
// public static boolean isSimpleType(Class<?> type) {
// return type.isPrimitive() || type.equals(String.class) || isBoxingType(type);
// }
//
// public static <T> T convertStringToPrimitive(Class<T> returnType, String value) {
// try {
// Method m = PRIMITIVE_MAP.get(returnType).getMethod("valueOf", String.class);
// @SuppressWarnings("unchecked") // Trust the valueOf method of the boxing type
// T result = (T) m.invoke(null, value);
// return result;
// } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
// LOGGER.debug("Unable to generate primitive value for type {}", returnType.getName());
// return null;
// }
// }
//
// /**
// * Retrieve the first non XmlTransient annotated type from deeperType to upperType.
// *
// * @param deeperType the deeperType of the hierarchy to test
// * @param upperType the upperType of the hierarchy to test
// * @return the xml eligible type
// */
// public static Class<?> resolveXmlType(Class<?> deeperType, Class<?> upperType) {
// if (!deeperType.isAssignableFrom(upperType)) {
// throw new IllegalArgumentException(String.format("%s --> %s is not a valid hierarchy", upperType, deeperType));
// }
//
// Deque<Class<?>> types = new ArrayDeque<>();
//
// Class<?> currentType = upperType;
// while (! deeperType.equals(currentType)) {
// types.push(currentType);
// currentType = currentType.getSuperclass();
// }
//
// types.push(deeperType);
//
// while (! types.isEmpty()) {
// Class<?> type = types.pop();
// if (type.getAnnotation(XmlTransient.class) == null) {
// return type;
// }
// }
//
// throw new IllegalArgumentException(String.format("Unable to determine a non XmlTransient type in provided hierarchy %s --> %s", upperType, deeperType));
// }
//
// public static boolean isSupportedType(Class<?> aClass) {
// return MarklogicSupportedType.fromClass(aClass).isPresent();
// }
//
// private static boolean isBoxingType(Class<?> type) {
// return MarklogicTypeUtils.PRIMITIVE_MAP.values().contains(type);
// }
// }
| import com._4dconcept.springframework.data.marklogic.MarklogicTypeUtils;
import org.springframework.data.mapping.Association;
import org.springframework.data.mapping.model.AnnotationBasedPersistentProperty;
import org.springframework.data.mapping.model.Property;
import org.springframework.data.mapping.model.SimpleTypeHolder;
import org.springframework.lang.Nullable;
import javax.xml.bind.annotation.*;
import javax.xml.namespace.QName;
import java.lang.reflect.Method;
import java.util.HashSet;
import java.util.Optional;
import java.util.Set; | if (xmlElement != null) {
if (!xmlElement.namespace().equals(XML_DEFAULT)) {
namespaceUri = xmlElement.namespace();
}
localName = xmlElement.name().equals(XML_DEFAULT) ? getName() : xmlElement.name();
}
if (namespaceUri == null && this.getField() != null) {
namespaceUri = resolvesNamespaceUriFromEnclosingType(this.getField().getDeclaringClass());
}
if (namespaceUri == null) namespaceUri = "";
if (localName == null) localName = getName();
return new QName(namespaceUri, localName);
}
@Override
protected Association<MarklogicPersistentProperty> createAssociation() {
return new Association<>(this, null);
}
@Override
public Optional<Method> getReadMethod() {
return getProperty().getGetter();
}
@Nullable
private String resolvesNamespaceUriFromEnclosingType(Class<?> type) { | // Path: src/main/java/com/_4dconcept/springframework/data/marklogic/MarklogicTypeUtils.java
// public class MarklogicTypeUtils {
//
// private static final Logger LOGGER = LoggerFactory.getLogger(MarklogicTypeUtils.class);
//
// private static final Map<Class<?>,Class<?>> PRIMITIVE_MAP = new HashMap<>();
//
// static {
// PRIMITIVE_MAP.put(boolean.class, Boolean.class);
// PRIMITIVE_MAP.put(byte.class, Byte.class);
// PRIMITIVE_MAP.put(char.class, Character.class);
// PRIMITIVE_MAP.put(short.class, Short.class);
// PRIMITIVE_MAP.put(int.class, Integer.class);
// PRIMITIVE_MAP.put(long.class, Long.class);
// PRIMITIVE_MAP.put(float.class, Float.class);
// PRIMITIVE_MAP.put(double.class, Double.class);
// }
//
// private MarklogicTypeUtils() {}
//
// public static boolean isSimpleType(Class<?> type) {
// return type.isPrimitive() || type.equals(String.class) || isBoxingType(type);
// }
//
// public static <T> T convertStringToPrimitive(Class<T> returnType, String value) {
// try {
// Method m = PRIMITIVE_MAP.get(returnType).getMethod("valueOf", String.class);
// @SuppressWarnings("unchecked") // Trust the valueOf method of the boxing type
// T result = (T) m.invoke(null, value);
// return result;
// } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
// LOGGER.debug("Unable to generate primitive value for type {}", returnType.getName());
// return null;
// }
// }
//
// /**
// * Retrieve the first non XmlTransient annotated type from deeperType to upperType.
// *
// * @param deeperType the deeperType of the hierarchy to test
// * @param upperType the upperType of the hierarchy to test
// * @return the xml eligible type
// */
// public static Class<?> resolveXmlType(Class<?> deeperType, Class<?> upperType) {
// if (!deeperType.isAssignableFrom(upperType)) {
// throw new IllegalArgumentException(String.format("%s --> %s is not a valid hierarchy", upperType, deeperType));
// }
//
// Deque<Class<?>> types = new ArrayDeque<>();
//
// Class<?> currentType = upperType;
// while (! deeperType.equals(currentType)) {
// types.push(currentType);
// currentType = currentType.getSuperclass();
// }
//
// types.push(deeperType);
//
// while (! types.isEmpty()) {
// Class<?> type = types.pop();
// if (type.getAnnotation(XmlTransient.class) == null) {
// return type;
// }
// }
//
// throw new IllegalArgumentException(String.format("Unable to determine a non XmlTransient type in provided hierarchy %s --> %s", upperType, deeperType));
// }
//
// public static boolean isSupportedType(Class<?> aClass) {
// return MarklogicSupportedType.fromClass(aClass).isPresent();
// }
//
// private static boolean isBoxingType(Class<?> type) {
// return MarklogicTypeUtils.PRIMITIVE_MAP.values().contains(type);
// }
// }
// Path: src/main/java/com/_4dconcept/springframework/data/marklogic/core/mapping/BasicMarklogicPersistentProperty.java
import com._4dconcept.springframework.data.marklogic.MarklogicTypeUtils;
import org.springframework.data.mapping.Association;
import org.springframework.data.mapping.model.AnnotationBasedPersistentProperty;
import org.springframework.data.mapping.model.Property;
import org.springframework.data.mapping.model.SimpleTypeHolder;
import org.springframework.lang.Nullable;
import javax.xml.bind.annotation.*;
import javax.xml.namespace.QName;
import java.lang.reflect.Method;
import java.util.HashSet;
import java.util.Optional;
import java.util.Set;
if (xmlElement != null) {
if (!xmlElement.namespace().equals(XML_DEFAULT)) {
namespaceUri = xmlElement.namespace();
}
localName = xmlElement.name().equals(XML_DEFAULT) ? getName() : xmlElement.name();
}
if (namespaceUri == null && this.getField() != null) {
namespaceUri = resolvesNamespaceUriFromEnclosingType(this.getField().getDeclaringClass());
}
if (namespaceUri == null) namespaceUri = "";
if (localName == null) localName = getName();
return new QName(namespaceUri, localName);
}
@Override
protected Association<MarklogicPersistentProperty> createAssociation() {
return new Association<>(this, null);
}
@Override
public Optional<Method> getReadMethod() {
return getProperty().getGetter();
}
@Nullable
private String resolvesNamespaceUriFromEnclosingType(Class<?> type) { | Class<?> xmlType = MarklogicTypeUtils.resolveXmlType(type, this.getOwner().getType()); |
stoussaint/spring-data-marklogic | src/main/java/com/_4dconcept/springframework/data/marklogic/core/convert/MappingMarklogicConverter.java | // Path: src/main/java/com/_4dconcept/springframework/data/marklogic/MarklogicTypeUtils.java
// public class MarklogicTypeUtils {
//
// private static final Logger LOGGER = LoggerFactory.getLogger(MarklogicTypeUtils.class);
//
// private static final Map<Class<?>,Class<?>> PRIMITIVE_MAP = new HashMap<>();
//
// static {
// PRIMITIVE_MAP.put(boolean.class, Boolean.class);
// PRIMITIVE_MAP.put(byte.class, Byte.class);
// PRIMITIVE_MAP.put(char.class, Character.class);
// PRIMITIVE_MAP.put(short.class, Short.class);
// PRIMITIVE_MAP.put(int.class, Integer.class);
// PRIMITIVE_MAP.put(long.class, Long.class);
// PRIMITIVE_MAP.put(float.class, Float.class);
// PRIMITIVE_MAP.put(double.class, Double.class);
// }
//
// private MarklogicTypeUtils() {}
//
// public static boolean isSimpleType(Class<?> type) {
// return type.isPrimitive() || type.equals(String.class) || isBoxingType(type);
// }
//
// public static <T> T convertStringToPrimitive(Class<T> returnType, String value) {
// try {
// Method m = PRIMITIVE_MAP.get(returnType).getMethod("valueOf", String.class);
// @SuppressWarnings("unchecked") // Trust the valueOf method of the boxing type
// T result = (T) m.invoke(null, value);
// return result;
// } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
// LOGGER.debug("Unable to generate primitive value for type {}", returnType.getName());
// return null;
// }
// }
//
// /**
// * Retrieve the first non XmlTransient annotated type from deeperType to upperType.
// *
// * @param deeperType the deeperType of the hierarchy to test
// * @param upperType the upperType of the hierarchy to test
// * @return the xml eligible type
// */
// public static Class<?> resolveXmlType(Class<?> deeperType, Class<?> upperType) {
// if (!deeperType.isAssignableFrom(upperType)) {
// throw new IllegalArgumentException(String.format("%s --> %s is not a valid hierarchy", upperType, deeperType));
// }
//
// Deque<Class<?>> types = new ArrayDeque<>();
//
// Class<?> currentType = upperType;
// while (! deeperType.equals(currentType)) {
// types.push(currentType);
// currentType = currentType.getSuperclass();
// }
//
// types.push(deeperType);
//
// while (! types.isEmpty()) {
// Class<?> type = types.pop();
// if (type.getAnnotation(XmlTransient.class) == null) {
// return type;
// }
// }
//
// throw new IllegalArgumentException(String.format("Unable to determine a non XmlTransient type in provided hierarchy %s --> %s", upperType, deeperType));
// }
//
// public static boolean isSupportedType(Class<?> aClass) {
// return MarklogicSupportedType.fromClass(aClass).isPresent();
// }
//
// private static boolean isBoxingType(Class<?> type) {
// return MarklogicTypeUtils.PRIMITIVE_MAP.values().contains(type);
// }
// }
//
// Path: src/main/java/com/_4dconcept/springframework/data/marklogic/core/mapping/MarklogicMappingContext.java
// public class MarklogicMappingContext extends AbstractMappingContext<BasicMarklogicPersistentEntity<?>, MarklogicPersistentProperty> {
//
// @Override
// protected <T> BasicMarklogicPersistentEntity<T> createPersistentEntity(TypeInformation<T> typeInformation) {
// return new BasicMarklogicPersistentEntity<>(typeInformation);
// }
//
// @Override
// protected MarklogicPersistentProperty createPersistentProperty(Property property,
// BasicMarklogicPersistentEntity<?> owner, SimpleTypeHolder simpleTypeHolder) {
// return new BasicMarklogicPersistentProperty(property, owner, simpleTypeHolder);
// }
// }
| import com._4dconcept.springframework.data.marklogic.MarklogicTypeUtils;
import com._4dconcept.springframework.data.marklogic.core.mapping.MarklogicMappingContext;
import com.marklogic.xcc.ResultItem;
import org.springframework.core.convert.ConversionFailedException;
import org.springframework.core.convert.ConversionService;
import org.springframework.core.convert.ConverterNotFoundException;
import org.springframework.core.convert.TypeDescriptor;
import org.springframework.core.convert.support.GenericConversionService;
import org.springframework.data.mapping.context.MappingContext;
import org.springframework.lang.Nullable; | /*
* Copyright 2017 the original author or authors.
*
* 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._4dconcept.springframework.data.marklogic.core.convert;
/**
* {@link MarklogicConverter} that uses a {@link MappingContext} to compute extra
* information such as uri or defaultCollection.
*
* @author Stéphane Toussaint
*/
public class MappingMarklogicConverter extends AbstractMarklogicConverter {
protected final MarklogicMappingContext mappingContext;
public MappingMarklogicConverter(MarklogicMappingContext mappingContext) {
this(mappingContext, null);
}
public MappingMarklogicConverter(MarklogicMappingContext mappingContext, @Nullable GenericConversionService conversionService) {
super(conversionService);
this.mappingContext = mappingContext;
}
@Override
public <R> R read(Class<R> returnType, MarklogicContentHolder holder) {
ResultItem resultItem = (ResultItem) holder.getContent();
if (String.class.equals(returnType)) {
return returnType.cast(resultItem.asString());
}
R result = null;
if (returnType.isPrimitive()) { | // Path: src/main/java/com/_4dconcept/springframework/data/marklogic/MarklogicTypeUtils.java
// public class MarklogicTypeUtils {
//
// private static final Logger LOGGER = LoggerFactory.getLogger(MarklogicTypeUtils.class);
//
// private static final Map<Class<?>,Class<?>> PRIMITIVE_MAP = new HashMap<>();
//
// static {
// PRIMITIVE_MAP.put(boolean.class, Boolean.class);
// PRIMITIVE_MAP.put(byte.class, Byte.class);
// PRIMITIVE_MAP.put(char.class, Character.class);
// PRIMITIVE_MAP.put(short.class, Short.class);
// PRIMITIVE_MAP.put(int.class, Integer.class);
// PRIMITIVE_MAP.put(long.class, Long.class);
// PRIMITIVE_MAP.put(float.class, Float.class);
// PRIMITIVE_MAP.put(double.class, Double.class);
// }
//
// private MarklogicTypeUtils() {}
//
// public static boolean isSimpleType(Class<?> type) {
// return type.isPrimitive() || type.equals(String.class) || isBoxingType(type);
// }
//
// public static <T> T convertStringToPrimitive(Class<T> returnType, String value) {
// try {
// Method m = PRIMITIVE_MAP.get(returnType).getMethod("valueOf", String.class);
// @SuppressWarnings("unchecked") // Trust the valueOf method of the boxing type
// T result = (T) m.invoke(null, value);
// return result;
// } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
// LOGGER.debug("Unable to generate primitive value for type {}", returnType.getName());
// return null;
// }
// }
//
// /**
// * Retrieve the first non XmlTransient annotated type from deeperType to upperType.
// *
// * @param deeperType the deeperType of the hierarchy to test
// * @param upperType the upperType of the hierarchy to test
// * @return the xml eligible type
// */
// public static Class<?> resolveXmlType(Class<?> deeperType, Class<?> upperType) {
// if (!deeperType.isAssignableFrom(upperType)) {
// throw new IllegalArgumentException(String.format("%s --> %s is not a valid hierarchy", upperType, deeperType));
// }
//
// Deque<Class<?>> types = new ArrayDeque<>();
//
// Class<?> currentType = upperType;
// while (! deeperType.equals(currentType)) {
// types.push(currentType);
// currentType = currentType.getSuperclass();
// }
//
// types.push(deeperType);
//
// while (! types.isEmpty()) {
// Class<?> type = types.pop();
// if (type.getAnnotation(XmlTransient.class) == null) {
// return type;
// }
// }
//
// throw new IllegalArgumentException(String.format("Unable to determine a non XmlTransient type in provided hierarchy %s --> %s", upperType, deeperType));
// }
//
// public static boolean isSupportedType(Class<?> aClass) {
// return MarklogicSupportedType.fromClass(aClass).isPresent();
// }
//
// private static boolean isBoxingType(Class<?> type) {
// return MarklogicTypeUtils.PRIMITIVE_MAP.values().contains(type);
// }
// }
//
// Path: src/main/java/com/_4dconcept/springframework/data/marklogic/core/mapping/MarklogicMappingContext.java
// public class MarklogicMappingContext extends AbstractMappingContext<BasicMarklogicPersistentEntity<?>, MarklogicPersistentProperty> {
//
// @Override
// protected <T> BasicMarklogicPersistentEntity<T> createPersistentEntity(TypeInformation<T> typeInformation) {
// return new BasicMarklogicPersistentEntity<>(typeInformation);
// }
//
// @Override
// protected MarklogicPersistentProperty createPersistentProperty(Property property,
// BasicMarklogicPersistentEntity<?> owner, SimpleTypeHolder simpleTypeHolder) {
// return new BasicMarklogicPersistentProperty(property, owner, simpleTypeHolder);
// }
// }
// Path: src/main/java/com/_4dconcept/springframework/data/marklogic/core/convert/MappingMarklogicConverter.java
import com._4dconcept.springframework.data.marklogic.MarklogicTypeUtils;
import com._4dconcept.springframework.data.marklogic.core.mapping.MarklogicMappingContext;
import com.marklogic.xcc.ResultItem;
import org.springframework.core.convert.ConversionFailedException;
import org.springframework.core.convert.ConversionService;
import org.springframework.core.convert.ConverterNotFoundException;
import org.springframework.core.convert.TypeDescriptor;
import org.springframework.core.convert.support.GenericConversionService;
import org.springframework.data.mapping.context.MappingContext;
import org.springframework.lang.Nullable;
/*
* Copyright 2017 the original author or authors.
*
* 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._4dconcept.springframework.data.marklogic.core.convert;
/**
* {@link MarklogicConverter} that uses a {@link MappingContext} to compute extra
* information such as uri or defaultCollection.
*
* @author Stéphane Toussaint
*/
public class MappingMarklogicConverter extends AbstractMarklogicConverter {
protected final MarklogicMappingContext mappingContext;
public MappingMarklogicConverter(MarklogicMappingContext mappingContext) {
this(mappingContext, null);
}
public MappingMarklogicConverter(MarklogicMappingContext mappingContext, @Nullable GenericConversionService conversionService) {
super(conversionService);
this.mappingContext = mappingContext;
}
@Override
public <R> R read(Class<R> returnType, MarklogicContentHolder holder) {
ResultItem resultItem = (ResultItem) holder.getContent();
if (String.class.equals(returnType)) {
return returnType.cast(resultItem.asString());
}
R result = null;
if (returnType.isPrimitive()) { | result = MarklogicTypeUtils.convertStringToPrimitive(returnType, resultItem.asString()); |
stoussaint/spring-data-marklogic | src/test/java/com/_4dconcept/springframework/data/marklogic/MarklogicCollectionUtilsTest.java | // Path: src/main/java/com/_4dconcept/springframework/data/marklogic/core/mapping/MarklogicMappingContext.java
// public class MarklogicMappingContext extends AbstractMappingContext<BasicMarklogicPersistentEntity<?>, MarklogicPersistentProperty> {
//
// @Override
// protected <T> BasicMarklogicPersistentEntity<T> createPersistentEntity(TypeInformation<T> typeInformation) {
// return new BasicMarklogicPersistentEntity<>(typeInformation);
// }
//
// @Override
// protected MarklogicPersistentProperty createPersistentProperty(Property property,
// BasicMarklogicPersistentEntity<?> owner, SimpleTypeHolder simpleTypeHolder) {
// return new BasicMarklogicPersistentProperty(property, owner, simpleTypeHolder);
// }
// }
| import com._4dconcept.springframework.data.marklogic.core.mapping.Collection;
import com._4dconcept.springframework.data.marklogic.core.mapping.MarklogicMappingContext;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.hamcrest.MatcherAssert.assertThat; | package com._4dconcept.springframework.data.marklogic;
public class MarklogicCollectionUtilsTest {
private MarklogicCollectionUtils marklogicCollectionUtils = new MarklogicCollectionUtils() {};
@Test
public void extractCollections() { | // Path: src/main/java/com/_4dconcept/springframework/data/marklogic/core/mapping/MarklogicMappingContext.java
// public class MarklogicMappingContext extends AbstractMappingContext<BasicMarklogicPersistentEntity<?>, MarklogicPersistentProperty> {
//
// @Override
// protected <T> BasicMarklogicPersistentEntity<T> createPersistentEntity(TypeInformation<T> typeInformation) {
// return new BasicMarklogicPersistentEntity<>(typeInformation);
// }
//
// @Override
// protected MarklogicPersistentProperty createPersistentProperty(Property property,
// BasicMarklogicPersistentEntity<?> owner, SimpleTypeHolder simpleTypeHolder) {
// return new BasicMarklogicPersistentProperty(property, owner, simpleTypeHolder);
// }
// }
// Path: src/test/java/com/_4dconcept/springframework/data/marklogic/MarklogicCollectionUtilsTest.java
import com._4dconcept.springframework.data.marklogic.core.mapping.Collection;
import com._4dconcept.springframework.data.marklogic.core.mapping.MarklogicMappingContext;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.hamcrest.MatcherAssert.assertThat;
package com._4dconcept.springframework.data.marklogic;
public class MarklogicCollectionUtilsTest {
private MarklogicCollectionUtils marklogicCollectionUtils = new MarklogicCollectionUtils() {};
@Test
public void extractCollections() { | assertThat(marklogicCollectionUtils.extractCollections(new SampleEntity("test1", "test2"), new MarklogicMappingContext()), containsInAnyOrder("test1", "field:test2", "computed:TEST1")); |
stoussaint/spring-data-marklogic | src/test/java/com/_4dconcept/springframework/data/marklogic/datasource/DatabaseConnectorJtaTransactionTest.java | // Path: src/main/java/com/_4dconcept/springframework/data/marklogic/datasource/lookup/IsolationLevelContentSourceRouter.java
// public class IsolationLevelContentSourceRouter extends AbstractRoutingContentSource {
//
// /** Constants instance for TransactionDefinition */
// private static final Constants constants = new Constants(TransactionDefinition.class);
//
//
// /**
// * Supports Integer values for the isolation level constants
// * as well as isolation level names as defined on the
// * {@link TransactionDefinition TransactionDefinition interface}.
// */
// @Override
// protected Object resolveSpecifiedLookupKey(Object lookupKey) {
// if (lookupKey instanceof Integer) {
// return lookupKey;
// } else if (lookupKey instanceof String) {
// String constantName = (String) lookupKey;
// if (!constantName.startsWith(DefaultTransactionDefinition.PREFIX_ISOLATION)) {
// throw new IllegalArgumentException("Only isolation constants allowed");
// }
// return constants.asNumber(constantName);
// } else {
// throw new IllegalArgumentException(
// "Invalid lookup key - needs to be isolation level Integer or isolation level name String: " + lookupKey);
// }
// }
//
// @Override
// @Nullable
// protected Object determineCurrentLookupKey() {
// return TransactionSynchronizationManager.getCurrentTransactionIsolationLevel();
// }
//
// }
| import com._4dconcept.springframework.data.marklogic.datasource.lookup.IsolationLevelContentSourceRouter;
import com.marklogic.xcc.ContentSource;
import com.marklogic.xcc.Session;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.transaction.TransactionDefinition;
import org.springframework.transaction.TransactionException;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.jta.JtaTransactionManager;
import org.springframework.transaction.jta.JtaTransactionObject;
import org.springframework.transaction.support.TransactionCallbackWithoutResult;
import org.springframework.transaction.support.TransactionSynchronization;
import org.springframework.transaction.support.TransactionSynchronizationManager;
import org.springframework.transaction.support.TransactionTemplate;
import javax.transaction.RollbackException;
import javax.transaction.Status;
import javax.transaction.SystemException;
import javax.transaction.Transaction;
import javax.transaction.TransactionManager;
import javax.transaction.UserTransaction;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.mockito.BDDMockito.atLeastOnce;
import static org.mockito.BDDMockito.given;
import static org.mockito.BDDMockito.mock;
import static org.mockito.BDDMockito.never;
import static org.mockito.BDDMockito.willThrow;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify; | protected void doInTransactionWithoutResult(TransactionStatus status) throws RuntimeException {
Session c = ContentSourceUtils.getSession(dsToUse);
assertTrue("Has thread session", TransactionSynchronizationManager.hasResource(dsToUse));
assertSame(session, c);
ContentSourceUtils.releaseSession(c, dsToUse);
}
});
verify(userTransaction, times(2)).begin();
verify(userTransaction, times(2)).commit();
verify(session).setTransactionMode(Session.TransactionMode.QUERY);
verify(session, times(2)).close();
}
@Test
public void testJtaTransactionWithIsolationLevelContentSourceRouter() throws Exception {
doTestJtaTransactionWithIsolationLevelContentSourceRouter();
}
private void doTestJtaTransactionWithIsolationLevelContentSourceRouter() throws Exception {
given(userTransaction.getStatus()).willReturn(Status.STATUS_NO_TRANSACTION, Status.STATUS_ACTIVE, Status.STATUS_ACTIVE, Status.STATUS_NO_TRANSACTION, Status.STATUS_ACTIVE, Status.STATUS_ACTIVE);
final ContentSource contentSource1 = mock(ContentSource.class);
final Session session1 = mock(Session.class);
given(contentSource1.newSession()).willReturn(session1);
final ContentSource contentSource2 = mock(ContentSource.class);
final Session session2 = mock(Session.class);
given(contentSource2.newSession()).willReturn(session2);
| // Path: src/main/java/com/_4dconcept/springframework/data/marklogic/datasource/lookup/IsolationLevelContentSourceRouter.java
// public class IsolationLevelContentSourceRouter extends AbstractRoutingContentSource {
//
// /** Constants instance for TransactionDefinition */
// private static final Constants constants = new Constants(TransactionDefinition.class);
//
//
// /**
// * Supports Integer values for the isolation level constants
// * as well as isolation level names as defined on the
// * {@link TransactionDefinition TransactionDefinition interface}.
// */
// @Override
// protected Object resolveSpecifiedLookupKey(Object lookupKey) {
// if (lookupKey instanceof Integer) {
// return lookupKey;
// } else if (lookupKey instanceof String) {
// String constantName = (String) lookupKey;
// if (!constantName.startsWith(DefaultTransactionDefinition.PREFIX_ISOLATION)) {
// throw new IllegalArgumentException("Only isolation constants allowed");
// }
// return constants.asNumber(constantName);
// } else {
// throw new IllegalArgumentException(
// "Invalid lookup key - needs to be isolation level Integer or isolation level name String: " + lookupKey);
// }
// }
//
// @Override
// @Nullable
// protected Object determineCurrentLookupKey() {
// return TransactionSynchronizationManager.getCurrentTransactionIsolationLevel();
// }
//
// }
// Path: src/test/java/com/_4dconcept/springframework/data/marklogic/datasource/DatabaseConnectorJtaTransactionTest.java
import com._4dconcept.springframework.data.marklogic.datasource.lookup.IsolationLevelContentSourceRouter;
import com.marklogic.xcc.ContentSource;
import com.marklogic.xcc.Session;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.transaction.TransactionDefinition;
import org.springframework.transaction.TransactionException;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.jta.JtaTransactionManager;
import org.springframework.transaction.jta.JtaTransactionObject;
import org.springframework.transaction.support.TransactionCallbackWithoutResult;
import org.springframework.transaction.support.TransactionSynchronization;
import org.springframework.transaction.support.TransactionSynchronizationManager;
import org.springframework.transaction.support.TransactionTemplate;
import javax.transaction.RollbackException;
import javax.transaction.Status;
import javax.transaction.SystemException;
import javax.transaction.Transaction;
import javax.transaction.TransactionManager;
import javax.transaction.UserTransaction;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.mockito.BDDMockito.atLeastOnce;
import static org.mockito.BDDMockito.given;
import static org.mockito.BDDMockito.mock;
import static org.mockito.BDDMockito.never;
import static org.mockito.BDDMockito.willThrow;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
protected void doInTransactionWithoutResult(TransactionStatus status) throws RuntimeException {
Session c = ContentSourceUtils.getSession(dsToUse);
assertTrue("Has thread session", TransactionSynchronizationManager.hasResource(dsToUse));
assertSame(session, c);
ContentSourceUtils.releaseSession(c, dsToUse);
}
});
verify(userTransaction, times(2)).begin();
verify(userTransaction, times(2)).commit();
verify(session).setTransactionMode(Session.TransactionMode.QUERY);
verify(session, times(2)).close();
}
@Test
public void testJtaTransactionWithIsolationLevelContentSourceRouter() throws Exception {
doTestJtaTransactionWithIsolationLevelContentSourceRouter();
}
private void doTestJtaTransactionWithIsolationLevelContentSourceRouter() throws Exception {
given(userTransaction.getStatus()).willReturn(Status.STATUS_NO_TRANSACTION, Status.STATUS_ACTIVE, Status.STATUS_ACTIVE, Status.STATUS_NO_TRANSACTION, Status.STATUS_ACTIVE, Status.STATUS_ACTIVE);
final ContentSource contentSource1 = mock(ContentSource.class);
final Session session1 = mock(Session.class);
given(contentSource1.newSession()).willReturn(session1);
final ContentSource contentSource2 = mock(ContentSource.class);
final Session session2 = mock(Session.class);
given(contentSource2.newSession()).willReturn(session2);
| final IsolationLevelContentSourceRouter dsToUse = new IsolationLevelContentSourceRouter(); |
szhnet/kcp-netty | kcp-example/src/main/java/io/jpower/kcp/example/echo/EchoClientHandler.java | // Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannel.java
// public interface UkcpChannel extends Channel {
//
// int conv();
//
// @Override
// UkcpChannelConfig config();
//
// UkcpChannel conv(int conv);
//
// @Override
// InetSocketAddress localAddress();
//
// @Override
// InetSocketAddress remoteAddress();
//
// }
| import io.jpower.kcp.netty.UkcpChannel;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter; | package io.jpower.kcp.example.echo;
/**
* Handler implementation for the echo client.
*
* @author <a href="mailto:szhnet@gmail.com">szh</a>
*/
public class EchoClientHandler extends ChannelInboundHandlerAdapter {
private final ByteBuf firstMessage;
/**
* Creates a client-side handler.
*/
public EchoClientHandler() {
firstMessage = Unpooled.buffer(EchoClient.SIZE);
for (int i = 0; i < firstMessage.capacity(); i++) {
firstMessage.writeByte((byte) i);
}
}
@Override
public void channelActive(ChannelHandlerContext ctx) { | // Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannel.java
// public interface UkcpChannel extends Channel {
//
// int conv();
//
// @Override
// UkcpChannelConfig config();
//
// UkcpChannel conv(int conv);
//
// @Override
// InetSocketAddress localAddress();
//
// @Override
// InetSocketAddress remoteAddress();
//
// }
// Path: kcp-example/src/main/java/io/jpower/kcp/example/echo/EchoClientHandler.java
import io.jpower.kcp.netty.UkcpChannel;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
package io.jpower.kcp.example.echo;
/**
* Handler implementation for the echo client.
*
* @author <a href="mailto:szhnet@gmail.com">szh</a>
*/
public class EchoClientHandler extends ChannelInboundHandlerAdapter {
private final ByteBuf firstMessage;
/**
* Creates a client-side handler.
*/
public EchoClientHandler() {
firstMessage = Unpooled.buffer(EchoClient.SIZE);
for (int i = 0; i < firstMessage.capacity(); i++) {
firstMessage.writeByte((byte) i);
}
}
@Override
public void channelActive(ChannelHandlerContext ctx) { | UkcpChannel kcpCh = (UkcpChannel) ctx.channel(); |
szhnet/kcp-netty | kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpClientChannel.java | // Path: kcp-netty/src/main/java/io/jpower/kcp/netty/Consts.java
// public static final InternalLogger sheduleUpdateLog = InternalLoggerFactory.getInstance("io.jpower.kcp.netty" +
// ".sheduleUpdate");
| import static io.jpower.kcp.netty.Consts.sheduleUpdateLog;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.util.List;
import java.util.concurrent.TimeUnit;
import io.netty.buffer.ByteBuf;
import io.netty.channel.AbstractChannel;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelMetadata;
import io.netty.channel.ChannelOutboundBuffer;
import io.netty.channel.ChannelPromise;
import io.netty.channel.EventLoop;
import io.netty.channel.nio.NioEventLoop;
import io.netty.util.internal.StringUtil;
import io.netty.util.internal.logging.InternalLogger;
import io.netty.util.internal.logging.InternalLoggerFactory; |
boolean kcpCanSend() {
return ukcp.canSend(!flushPending);
}
int kcpPeekSize() {
return ukcp.peekSize();
}
int kcpUpdate(int current) {
return ukcp.update(current);
}
int kcpCheck(int current) {
return ukcp.check(current);
}
int kcpTsUpdate() {
return ukcp.getTsUpdate();
}
void kcpTsUpdate(int tsUpdate) {
ukcp.setTsUpdate(tsUpdate);
}
int kcpState() {
return ukcp.getState();
}
void scheduleUpdate(int tsUpdate, int current) { | // Path: kcp-netty/src/main/java/io/jpower/kcp/netty/Consts.java
// public static final InternalLogger sheduleUpdateLog = InternalLoggerFactory.getInstance("io.jpower.kcp.netty" +
// ".sheduleUpdate");
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpClientChannel.java
import static io.jpower.kcp.netty.Consts.sheduleUpdateLog;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.util.List;
import java.util.concurrent.TimeUnit;
import io.netty.buffer.ByteBuf;
import io.netty.channel.AbstractChannel;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelMetadata;
import io.netty.channel.ChannelOutboundBuffer;
import io.netty.channel.ChannelPromise;
import io.netty.channel.EventLoop;
import io.netty.channel.nio.NioEventLoop;
import io.netty.util.internal.StringUtil;
import io.netty.util.internal.logging.InternalLogger;
import io.netty.util.internal.logging.InternalLoggerFactory;
boolean kcpCanSend() {
return ukcp.canSend(!flushPending);
}
int kcpPeekSize() {
return ukcp.peekSize();
}
int kcpUpdate(int current) {
return ukcp.update(current);
}
int kcpCheck(int current) {
return ukcp.check(current);
}
int kcpTsUpdate() {
return ukcp.getTsUpdate();
}
void kcpTsUpdate(int tsUpdate) {
ukcp.setTsUpdate(tsUpdate);
}
int kcpState() {
return ukcp.getState();
}
void scheduleUpdate(int tsUpdate, int current) { | if (sheduleUpdateLog.isDebugEnabled()) { |
szhnet/kcp-netty | kcp-netty/src/main/java/io/jpower/kcp/netty/DefaultUkcpServerChildChannelConfig.java | // Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_AUTO_SET_CONV =
// valueOf(UkcpChannelOption.class, "UKCP_AUTO_SET_CONV");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_DEAD_LINK =
// valueOf(UkcpChannelOption.class, "UKCP_DEAD_LINK");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_FAST_FLUSH =
// valueOf(UkcpChannelOption.class, "UKCP_FAST_FLUSH");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_FAST_LIMIT =
// valueOf(UkcpChannelOption.class, "UKCP_FAST_LIMIT");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_FAST_RESEND =
// valueOf(UkcpChannelOption.class, "UKCP_FAST_RESEND");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_INTERVAL =
// valueOf(UkcpChannelOption.class, "UKCP_INTERVAL");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_MERGE_SEGMENT_BUF =
// valueOf(UkcpChannelOption.class, "UKCP_MERGE_SEGMENT_BUF");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_MIN_RTO =
// valueOf(UkcpChannelOption.class, "UKCP_MIN_RTO");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_MTU =
// valueOf(UkcpChannelOption.class, "UKCP_MTU");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_NOCWND =
// valueOf(UkcpChannelOption.class, "UKCP_NOCWND");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_NODELAY =
// valueOf(UkcpChannelOption.class, "UKCP_NODELAY");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_RCV_WND =
// valueOf(UkcpChannelOption.class, "UKCP_RCV_WND");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_SND_WND =
// valueOf(UkcpChannelOption.class, "UKCP_SND_WND");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_STREAM =
// valueOf(UkcpChannelOption.class, "UKCP_STREAM");
| import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_AUTO_SET_CONV;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_DEAD_LINK;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_FAST_FLUSH;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_FAST_LIMIT;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_FAST_RESEND;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_INTERVAL;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_MERGE_SEGMENT_BUF;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_MIN_RTO;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_MTU;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_NOCWND;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_NODELAY;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_RCV_WND;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_SND_WND;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_STREAM;
import java.util.Map;
import java.util.Objects;
import io.netty.buffer.ByteBufAllocator;
import io.netty.channel.ChannelOption;
import io.netty.channel.DefaultChannelConfig;
import io.netty.channel.FixedRecvByteBufAllocator;
import io.netty.channel.MessageSizeEstimator;
import io.netty.channel.RecvByteBufAllocator;
import io.netty.channel.WriteBufferWaterMark; | package io.jpower.kcp.netty;
/**
* @author <a href="mailto:szhnet@gmail.com">szh</a>
*/
public class DefaultUkcpServerChildChannelConfig extends DefaultChannelConfig implements UkcpChannelConfig {
private final Ukcp ukcp;
public DefaultUkcpServerChildChannelConfig(UkcpServerChildChannel channel, Ukcp ukcp) {
super(channel, new FixedRecvByteBufAllocator(Consts.FIXED_RECV_BYTEBUF_ALLOCATE_SIZE));
this.ukcp = Objects.requireNonNull(ukcp, "ukcp");
}
@Override
@SuppressWarnings("deprecation")
public Map<ChannelOption<?>, Object> getOptions() {
return getOptions(
super.getOptions(), | // Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_AUTO_SET_CONV =
// valueOf(UkcpChannelOption.class, "UKCP_AUTO_SET_CONV");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_DEAD_LINK =
// valueOf(UkcpChannelOption.class, "UKCP_DEAD_LINK");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_FAST_FLUSH =
// valueOf(UkcpChannelOption.class, "UKCP_FAST_FLUSH");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_FAST_LIMIT =
// valueOf(UkcpChannelOption.class, "UKCP_FAST_LIMIT");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_FAST_RESEND =
// valueOf(UkcpChannelOption.class, "UKCP_FAST_RESEND");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_INTERVAL =
// valueOf(UkcpChannelOption.class, "UKCP_INTERVAL");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_MERGE_SEGMENT_BUF =
// valueOf(UkcpChannelOption.class, "UKCP_MERGE_SEGMENT_BUF");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_MIN_RTO =
// valueOf(UkcpChannelOption.class, "UKCP_MIN_RTO");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_MTU =
// valueOf(UkcpChannelOption.class, "UKCP_MTU");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_NOCWND =
// valueOf(UkcpChannelOption.class, "UKCP_NOCWND");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_NODELAY =
// valueOf(UkcpChannelOption.class, "UKCP_NODELAY");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_RCV_WND =
// valueOf(UkcpChannelOption.class, "UKCP_RCV_WND");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_SND_WND =
// valueOf(UkcpChannelOption.class, "UKCP_SND_WND");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_STREAM =
// valueOf(UkcpChannelOption.class, "UKCP_STREAM");
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/DefaultUkcpServerChildChannelConfig.java
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_AUTO_SET_CONV;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_DEAD_LINK;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_FAST_FLUSH;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_FAST_LIMIT;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_FAST_RESEND;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_INTERVAL;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_MERGE_SEGMENT_BUF;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_MIN_RTO;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_MTU;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_NOCWND;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_NODELAY;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_RCV_WND;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_SND_WND;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_STREAM;
import java.util.Map;
import java.util.Objects;
import io.netty.buffer.ByteBufAllocator;
import io.netty.channel.ChannelOption;
import io.netty.channel.DefaultChannelConfig;
import io.netty.channel.FixedRecvByteBufAllocator;
import io.netty.channel.MessageSizeEstimator;
import io.netty.channel.RecvByteBufAllocator;
import io.netty.channel.WriteBufferWaterMark;
package io.jpower.kcp.netty;
/**
* @author <a href="mailto:szhnet@gmail.com">szh</a>
*/
public class DefaultUkcpServerChildChannelConfig extends DefaultChannelConfig implements UkcpChannelConfig {
private final Ukcp ukcp;
public DefaultUkcpServerChildChannelConfig(UkcpServerChildChannel channel, Ukcp ukcp) {
super(channel, new FixedRecvByteBufAllocator(Consts.FIXED_RECV_BYTEBUF_ALLOCATE_SIZE));
this.ukcp = Objects.requireNonNull(ukcp, "ukcp");
}
@Override
@SuppressWarnings("deprecation")
public Map<ChannelOption<?>, Object> getOptions() {
return getOptions(
super.getOptions(), | UKCP_NODELAY, UKCP_INTERVAL, UKCP_FAST_RESEND, UKCP_FAST_LIMIT, UKCP_NOCWND, UKCP_MIN_RTO, UKCP_MTU, |
szhnet/kcp-netty | kcp-netty/src/main/java/io/jpower/kcp/netty/DefaultUkcpServerChildChannelConfig.java | // Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_AUTO_SET_CONV =
// valueOf(UkcpChannelOption.class, "UKCP_AUTO_SET_CONV");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_DEAD_LINK =
// valueOf(UkcpChannelOption.class, "UKCP_DEAD_LINK");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_FAST_FLUSH =
// valueOf(UkcpChannelOption.class, "UKCP_FAST_FLUSH");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_FAST_LIMIT =
// valueOf(UkcpChannelOption.class, "UKCP_FAST_LIMIT");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_FAST_RESEND =
// valueOf(UkcpChannelOption.class, "UKCP_FAST_RESEND");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_INTERVAL =
// valueOf(UkcpChannelOption.class, "UKCP_INTERVAL");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_MERGE_SEGMENT_BUF =
// valueOf(UkcpChannelOption.class, "UKCP_MERGE_SEGMENT_BUF");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_MIN_RTO =
// valueOf(UkcpChannelOption.class, "UKCP_MIN_RTO");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_MTU =
// valueOf(UkcpChannelOption.class, "UKCP_MTU");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_NOCWND =
// valueOf(UkcpChannelOption.class, "UKCP_NOCWND");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_NODELAY =
// valueOf(UkcpChannelOption.class, "UKCP_NODELAY");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_RCV_WND =
// valueOf(UkcpChannelOption.class, "UKCP_RCV_WND");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_SND_WND =
// valueOf(UkcpChannelOption.class, "UKCP_SND_WND");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_STREAM =
// valueOf(UkcpChannelOption.class, "UKCP_STREAM");
| import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_AUTO_SET_CONV;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_DEAD_LINK;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_FAST_FLUSH;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_FAST_LIMIT;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_FAST_RESEND;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_INTERVAL;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_MERGE_SEGMENT_BUF;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_MIN_RTO;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_MTU;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_NOCWND;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_NODELAY;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_RCV_WND;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_SND_WND;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_STREAM;
import java.util.Map;
import java.util.Objects;
import io.netty.buffer.ByteBufAllocator;
import io.netty.channel.ChannelOption;
import io.netty.channel.DefaultChannelConfig;
import io.netty.channel.FixedRecvByteBufAllocator;
import io.netty.channel.MessageSizeEstimator;
import io.netty.channel.RecvByteBufAllocator;
import io.netty.channel.WriteBufferWaterMark; | package io.jpower.kcp.netty;
/**
* @author <a href="mailto:szhnet@gmail.com">szh</a>
*/
public class DefaultUkcpServerChildChannelConfig extends DefaultChannelConfig implements UkcpChannelConfig {
private final Ukcp ukcp;
public DefaultUkcpServerChildChannelConfig(UkcpServerChildChannel channel, Ukcp ukcp) {
super(channel, new FixedRecvByteBufAllocator(Consts.FIXED_RECV_BYTEBUF_ALLOCATE_SIZE));
this.ukcp = Objects.requireNonNull(ukcp, "ukcp");
}
@Override
@SuppressWarnings("deprecation")
public Map<ChannelOption<?>, Object> getOptions() {
return getOptions(
super.getOptions(), | // Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_AUTO_SET_CONV =
// valueOf(UkcpChannelOption.class, "UKCP_AUTO_SET_CONV");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_DEAD_LINK =
// valueOf(UkcpChannelOption.class, "UKCP_DEAD_LINK");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_FAST_FLUSH =
// valueOf(UkcpChannelOption.class, "UKCP_FAST_FLUSH");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_FAST_LIMIT =
// valueOf(UkcpChannelOption.class, "UKCP_FAST_LIMIT");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_FAST_RESEND =
// valueOf(UkcpChannelOption.class, "UKCP_FAST_RESEND");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_INTERVAL =
// valueOf(UkcpChannelOption.class, "UKCP_INTERVAL");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_MERGE_SEGMENT_BUF =
// valueOf(UkcpChannelOption.class, "UKCP_MERGE_SEGMENT_BUF");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_MIN_RTO =
// valueOf(UkcpChannelOption.class, "UKCP_MIN_RTO");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_MTU =
// valueOf(UkcpChannelOption.class, "UKCP_MTU");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_NOCWND =
// valueOf(UkcpChannelOption.class, "UKCP_NOCWND");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_NODELAY =
// valueOf(UkcpChannelOption.class, "UKCP_NODELAY");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_RCV_WND =
// valueOf(UkcpChannelOption.class, "UKCP_RCV_WND");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_SND_WND =
// valueOf(UkcpChannelOption.class, "UKCP_SND_WND");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_STREAM =
// valueOf(UkcpChannelOption.class, "UKCP_STREAM");
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/DefaultUkcpServerChildChannelConfig.java
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_AUTO_SET_CONV;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_DEAD_LINK;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_FAST_FLUSH;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_FAST_LIMIT;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_FAST_RESEND;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_INTERVAL;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_MERGE_SEGMENT_BUF;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_MIN_RTO;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_MTU;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_NOCWND;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_NODELAY;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_RCV_WND;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_SND_WND;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_STREAM;
import java.util.Map;
import java.util.Objects;
import io.netty.buffer.ByteBufAllocator;
import io.netty.channel.ChannelOption;
import io.netty.channel.DefaultChannelConfig;
import io.netty.channel.FixedRecvByteBufAllocator;
import io.netty.channel.MessageSizeEstimator;
import io.netty.channel.RecvByteBufAllocator;
import io.netty.channel.WriteBufferWaterMark;
package io.jpower.kcp.netty;
/**
* @author <a href="mailto:szhnet@gmail.com">szh</a>
*/
public class DefaultUkcpServerChildChannelConfig extends DefaultChannelConfig implements UkcpChannelConfig {
private final Ukcp ukcp;
public DefaultUkcpServerChildChannelConfig(UkcpServerChildChannel channel, Ukcp ukcp) {
super(channel, new FixedRecvByteBufAllocator(Consts.FIXED_RECV_BYTEBUF_ALLOCATE_SIZE));
this.ukcp = Objects.requireNonNull(ukcp, "ukcp");
}
@Override
@SuppressWarnings("deprecation")
public Map<ChannelOption<?>, Object> getOptions() {
return getOptions(
super.getOptions(), | UKCP_NODELAY, UKCP_INTERVAL, UKCP_FAST_RESEND, UKCP_FAST_LIMIT, UKCP_NOCWND, UKCP_MIN_RTO, UKCP_MTU, |
szhnet/kcp-netty | kcp-netty/src/main/java/io/jpower/kcp/netty/DefaultUkcpServerChildChannelConfig.java | // Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_AUTO_SET_CONV =
// valueOf(UkcpChannelOption.class, "UKCP_AUTO_SET_CONV");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_DEAD_LINK =
// valueOf(UkcpChannelOption.class, "UKCP_DEAD_LINK");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_FAST_FLUSH =
// valueOf(UkcpChannelOption.class, "UKCP_FAST_FLUSH");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_FAST_LIMIT =
// valueOf(UkcpChannelOption.class, "UKCP_FAST_LIMIT");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_FAST_RESEND =
// valueOf(UkcpChannelOption.class, "UKCP_FAST_RESEND");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_INTERVAL =
// valueOf(UkcpChannelOption.class, "UKCP_INTERVAL");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_MERGE_SEGMENT_BUF =
// valueOf(UkcpChannelOption.class, "UKCP_MERGE_SEGMENT_BUF");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_MIN_RTO =
// valueOf(UkcpChannelOption.class, "UKCP_MIN_RTO");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_MTU =
// valueOf(UkcpChannelOption.class, "UKCP_MTU");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_NOCWND =
// valueOf(UkcpChannelOption.class, "UKCP_NOCWND");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_NODELAY =
// valueOf(UkcpChannelOption.class, "UKCP_NODELAY");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_RCV_WND =
// valueOf(UkcpChannelOption.class, "UKCP_RCV_WND");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_SND_WND =
// valueOf(UkcpChannelOption.class, "UKCP_SND_WND");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_STREAM =
// valueOf(UkcpChannelOption.class, "UKCP_STREAM");
| import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_AUTO_SET_CONV;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_DEAD_LINK;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_FAST_FLUSH;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_FAST_LIMIT;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_FAST_RESEND;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_INTERVAL;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_MERGE_SEGMENT_BUF;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_MIN_RTO;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_MTU;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_NOCWND;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_NODELAY;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_RCV_WND;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_SND_WND;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_STREAM;
import java.util.Map;
import java.util.Objects;
import io.netty.buffer.ByteBufAllocator;
import io.netty.channel.ChannelOption;
import io.netty.channel.DefaultChannelConfig;
import io.netty.channel.FixedRecvByteBufAllocator;
import io.netty.channel.MessageSizeEstimator;
import io.netty.channel.RecvByteBufAllocator;
import io.netty.channel.WriteBufferWaterMark; | package io.jpower.kcp.netty;
/**
* @author <a href="mailto:szhnet@gmail.com">szh</a>
*/
public class DefaultUkcpServerChildChannelConfig extends DefaultChannelConfig implements UkcpChannelConfig {
private final Ukcp ukcp;
public DefaultUkcpServerChildChannelConfig(UkcpServerChildChannel channel, Ukcp ukcp) {
super(channel, new FixedRecvByteBufAllocator(Consts.FIXED_RECV_BYTEBUF_ALLOCATE_SIZE));
this.ukcp = Objects.requireNonNull(ukcp, "ukcp");
}
@Override
@SuppressWarnings("deprecation")
public Map<ChannelOption<?>, Object> getOptions() {
return getOptions(
super.getOptions(), | // Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_AUTO_SET_CONV =
// valueOf(UkcpChannelOption.class, "UKCP_AUTO_SET_CONV");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_DEAD_LINK =
// valueOf(UkcpChannelOption.class, "UKCP_DEAD_LINK");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_FAST_FLUSH =
// valueOf(UkcpChannelOption.class, "UKCP_FAST_FLUSH");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_FAST_LIMIT =
// valueOf(UkcpChannelOption.class, "UKCP_FAST_LIMIT");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_FAST_RESEND =
// valueOf(UkcpChannelOption.class, "UKCP_FAST_RESEND");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_INTERVAL =
// valueOf(UkcpChannelOption.class, "UKCP_INTERVAL");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_MERGE_SEGMENT_BUF =
// valueOf(UkcpChannelOption.class, "UKCP_MERGE_SEGMENT_BUF");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_MIN_RTO =
// valueOf(UkcpChannelOption.class, "UKCP_MIN_RTO");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_MTU =
// valueOf(UkcpChannelOption.class, "UKCP_MTU");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_NOCWND =
// valueOf(UkcpChannelOption.class, "UKCP_NOCWND");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_NODELAY =
// valueOf(UkcpChannelOption.class, "UKCP_NODELAY");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_RCV_WND =
// valueOf(UkcpChannelOption.class, "UKCP_RCV_WND");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_SND_WND =
// valueOf(UkcpChannelOption.class, "UKCP_SND_WND");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_STREAM =
// valueOf(UkcpChannelOption.class, "UKCP_STREAM");
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/DefaultUkcpServerChildChannelConfig.java
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_AUTO_SET_CONV;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_DEAD_LINK;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_FAST_FLUSH;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_FAST_LIMIT;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_FAST_RESEND;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_INTERVAL;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_MERGE_SEGMENT_BUF;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_MIN_RTO;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_MTU;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_NOCWND;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_NODELAY;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_RCV_WND;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_SND_WND;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_STREAM;
import java.util.Map;
import java.util.Objects;
import io.netty.buffer.ByteBufAllocator;
import io.netty.channel.ChannelOption;
import io.netty.channel.DefaultChannelConfig;
import io.netty.channel.FixedRecvByteBufAllocator;
import io.netty.channel.MessageSizeEstimator;
import io.netty.channel.RecvByteBufAllocator;
import io.netty.channel.WriteBufferWaterMark;
package io.jpower.kcp.netty;
/**
* @author <a href="mailto:szhnet@gmail.com">szh</a>
*/
public class DefaultUkcpServerChildChannelConfig extends DefaultChannelConfig implements UkcpChannelConfig {
private final Ukcp ukcp;
public DefaultUkcpServerChildChannelConfig(UkcpServerChildChannel channel, Ukcp ukcp) {
super(channel, new FixedRecvByteBufAllocator(Consts.FIXED_RECV_BYTEBUF_ALLOCATE_SIZE));
this.ukcp = Objects.requireNonNull(ukcp, "ukcp");
}
@Override
@SuppressWarnings("deprecation")
public Map<ChannelOption<?>, Object> getOptions() {
return getOptions(
super.getOptions(), | UKCP_NODELAY, UKCP_INTERVAL, UKCP_FAST_RESEND, UKCP_FAST_LIMIT, UKCP_NOCWND, UKCP_MIN_RTO, UKCP_MTU, |
szhnet/kcp-netty | kcp-netty/src/main/java/io/jpower/kcp/netty/DefaultUkcpServerChildChannelConfig.java | // Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_AUTO_SET_CONV =
// valueOf(UkcpChannelOption.class, "UKCP_AUTO_SET_CONV");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_DEAD_LINK =
// valueOf(UkcpChannelOption.class, "UKCP_DEAD_LINK");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_FAST_FLUSH =
// valueOf(UkcpChannelOption.class, "UKCP_FAST_FLUSH");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_FAST_LIMIT =
// valueOf(UkcpChannelOption.class, "UKCP_FAST_LIMIT");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_FAST_RESEND =
// valueOf(UkcpChannelOption.class, "UKCP_FAST_RESEND");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_INTERVAL =
// valueOf(UkcpChannelOption.class, "UKCP_INTERVAL");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_MERGE_SEGMENT_BUF =
// valueOf(UkcpChannelOption.class, "UKCP_MERGE_SEGMENT_BUF");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_MIN_RTO =
// valueOf(UkcpChannelOption.class, "UKCP_MIN_RTO");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_MTU =
// valueOf(UkcpChannelOption.class, "UKCP_MTU");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_NOCWND =
// valueOf(UkcpChannelOption.class, "UKCP_NOCWND");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_NODELAY =
// valueOf(UkcpChannelOption.class, "UKCP_NODELAY");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_RCV_WND =
// valueOf(UkcpChannelOption.class, "UKCP_RCV_WND");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_SND_WND =
// valueOf(UkcpChannelOption.class, "UKCP_SND_WND");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_STREAM =
// valueOf(UkcpChannelOption.class, "UKCP_STREAM");
| import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_AUTO_SET_CONV;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_DEAD_LINK;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_FAST_FLUSH;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_FAST_LIMIT;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_FAST_RESEND;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_INTERVAL;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_MERGE_SEGMENT_BUF;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_MIN_RTO;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_MTU;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_NOCWND;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_NODELAY;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_RCV_WND;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_SND_WND;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_STREAM;
import java.util.Map;
import java.util.Objects;
import io.netty.buffer.ByteBufAllocator;
import io.netty.channel.ChannelOption;
import io.netty.channel.DefaultChannelConfig;
import io.netty.channel.FixedRecvByteBufAllocator;
import io.netty.channel.MessageSizeEstimator;
import io.netty.channel.RecvByteBufAllocator;
import io.netty.channel.WriteBufferWaterMark; | package io.jpower.kcp.netty;
/**
* @author <a href="mailto:szhnet@gmail.com">szh</a>
*/
public class DefaultUkcpServerChildChannelConfig extends DefaultChannelConfig implements UkcpChannelConfig {
private final Ukcp ukcp;
public DefaultUkcpServerChildChannelConfig(UkcpServerChildChannel channel, Ukcp ukcp) {
super(channel, new FixedRecvByteBufAllocator(Consts.FIXED_RECV_BYTEBUF_ALLOCATE_SIZE));
this.ukcp = Objects.requireNonNull(ukcp, "ukcp");
}
@Override
@SuppressWarnings("deprecation")
public Map<ChannelOption<?>, Object> getOptions() {
return getOptions(
super.getOptions(), | // Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_AUTO_SET_CONV =
// valueOf(UkcpChannelOption.class, "UKCP_AUTO_SET_CONV");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_DEAD_LINK =
// valueOf(UkcpChannelOption.class, "UKCP_DEAD_LINK");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_FAST_FLUSH =
// valueOf(UkcpChannelOption.class, "UKCP_FAST_FLUSH");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_FAST_LIMIT =
// valueOf(UkcpChannelOption.class, "UKCP_FAST_LIMIT");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_FAST_RESEND =
// valueOf(UkcpChannelOption.class, "UKCP_FAST_RESEND");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_INTERVAL =
// valueOf(UkcpChannelOption.class, "UKCP_INTERVAL");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_MERGE_SEGMENT_BUF =
// valueOf(UkcpChannelOption.class, "UKCP_MERGE_SEGMENT_BUF");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_MIN_RTO =
// valueOf(UkcpChannelOption.class, "UKCP_MIN_RTO");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_MTU =
// valueOf(UkcpChannelOption.class, "UKCP_MTU");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_NOCWND =
// valueOf(UkcpChannelOption.class, "UKCP_NOCWND");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_NODELAY =
// valueOf(UkcpChannelOption.class, "UKCP_NODELAY");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_RCV_WND =
// valueOf(UkcpChannelOption.class, "UKCP_RCV_WND");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_SND_WND =
// valueOf(UkcpChannelOption.class, "UKCP_SND_WND");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_STREAM =
// valueOf(UkcpChannelOption.class, "UKCP_STREAM");
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/DefaultUkcpServerChildChannelConfig.java
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_AUTO_SET_CONV;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_DEAD_LINK;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_FAST_FLUSH;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_FAST_LIMIT;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_FAST_RESEND;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_INTERVAL;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_MERGE_SEGMENT_BUF;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_MIN_RTO;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_MTU;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_NOCWND;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_NODELAY;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_RCV_WND;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_SND_WND;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_STREAM;
import java.util.Map;
import java.util.Objects;
import io.netty.buffer.ByteBufAllocator;
import io.netty.channel.ChannelOption;
import io.netty.channel.DefaultChannelConfig;
import io.netty.channel.FixedRecvByteBufAllocator;
import io.netty.channel.MessageSizeEstimator;
import io.netty.channel.RecvByteBufAllocator;
import io.netty.channel.WriteBufferWaterMark;
package io.jpower.kcp.netty;
/**
* @author <a href="mailto:szhnet@gmail.com">szh</a>
*/
public class DefaultUkcpServerChildChannelConfig extends DefaultChannelConfig implements UkcpChannelConfig {
private final Ukcp ukcp;
public DefaultUkcpServerChildChannelConfig(UkcpServerChildChannel channel, Ukcp ukcp) {
super(channel, new FixedRecvByteBufAllocator(Consts.FIXED_RECV_BYTEBUF_ALLOCATE_SIZE));
this.ukcp = Objects.requireNonNull(ukcp, "ukcp");
}
@Override
@SuppressWarnings("deprecation")
public Map<ChannelOption<?>, Object> getOptions() {
return getOptions(
super.getOptions(), | UKCP_NODELAY, UKCP_INTERVAL, UKCP_FAST_RESEND, UKCP_FAST_LIMIT, UKCP_NOCWND, UKCP_MIN_RTO, UKCP_MTU, |
szhnet/kcp-netty | kcp-netty/src/main/java/io/jpower/kcp/netty/DefaultUkcpServerChildChannelConfig.java | // Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_AUTO_SET_CONV =
// valueOf(UkcpChannelOption.class, "UKCP_AUTO_SET_CONV");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_DEAD_LINK =
// valueOf(UkcpChannelOption.class, "UKCP_DEAD_LINK");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_FAST_FLUSH =
// valueOf(UkcpChannelOption.class, "UKCP_FAST_FLUSH");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_FAST_LIMIT =
// valueOf(UkcpChannelOption.class, "UKCP_FAST_LIMIT");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_FAST_RESEND =
// valueOf(UkcpChannelOption.class, "UKCP_FAST_RESEND");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_INTERVAL =
// valueOf(UkcpChannelOption.class, "UKCP_INTERVAL");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_MERGE_SEGMENT_BUF =
// valueOf(UkcpChannelOption.class, "UKCP_MERGE_SEGMENT_BUF");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_MIN_RTO =
// valueOf(UkcpChannelOption.class, "UKCP_MIN_RTO");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_MTU =
// valueOf(UkcpChannelOption.class, "UKCP_MTU");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_NOCWND =
// valueOf(UkcpChannelOption.class, "UKCP_NOCWND");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_NODELAY =
// valueOf(UkcpChannelOption.class, "UKCP_NODELAY");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_RCV_WND =
// valueOf(UkcpChannelOption.class, "UKCP_RCV_WND");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_SND_WND =
// valueOf(UkcpChannelOption.class, "UKCP_SND_WND");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_STREAM =
// valueOf(UkcpChannelOption.class, "UKCP_STREAM");
| import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_AUTO_SET_CONV;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_DEAD_LINK;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_FAST_FLUSH;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_FAST_LIMIT;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_FAST_RESEND;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_INTERVAL;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_MERGE_SEGMENT_BUF;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_MIN_RTO;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_MTU;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_NOCWND;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_NODELAY;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_RCV_WND;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_SND_WND;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_STREAM;
import java.util.Map;
import java.util.Objects;
import io.netty.buffer.ByteBufAllocator;
import io.netty.channel.ChannelOption;
import io.netty.channel.DefaultChannelConfig;
import io.netty.channel.FixedRecvByteBufAllocator;
import io.netty.channel.MessageSizeEstimator;
import io.netty.channel.RecvByteBufAllocator;
import io.netty.channel.WriteBufferWaterMark; | package io.jpower.kcp.netty;
/**
* @author <a href="mailto:szhnet@gmail.com">szh</a>
*/
public class DefaultUkcpServerChildChannelConfig extends DefaultChannelConfig implements UkcpChannelConfig {
private final Ukcp ukcp;
public DefaultUkcpServerChildChannelConfig(UkcpServerChildChannel channel, Ukcp ukcp) {
super(channel, new FixedRecvByteBufAllocator(Consts.FIXED_RECV_BYTEBUF_ALLOCATE_SIZE));
this.ukcp = Objects.requireNonNull(ukcp, "ukcp");
}
@Override
@SuppressWarnings("deprecation")
public Map<ChannelOption<?>, Object> getOptions() {
return getOptions(
super.getOptions(), | // Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_AUTO_SET_CONV =
// valueOf(UkcpChannelOption.class, "UKCP_AUTO_SET_CONV");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_DEAD_LINK =
// valueOf(UkcpChannelOption.class, "UKCP_DEAD_LINK");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_FAST_FLUSH =
// valueOf(UkcpChannelOption.class, "UKCP_FAST_FLUSH");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_FAST_LIMIT =
// valueOf(UkcpChannelOption.class, "UKCP_FAST_LIMIT");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_FAST_RESEND =
// valueOf(UkcpChannelOption.class, "UKCP_FAST_RESEND");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_INTERVAL =
// valueOf(UkcpChannelOption.class, "UKCP_INTERVAL");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_MERGE_SEGMENT_BUF =
// valueOf(UkcpChannelOption.class, "UKCP_MERGE_SEGMENT_BUF");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_MIN_RTO =
// valueOf(UkcpChannelOption.class, "UKCP_MIN_RTO");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_MTU =
// valueOf(UkcpChannelOption.class, "UKCP_MTU");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_NOCWND =
// valueOf(UkcpChannelOption.class, "UKCP_NOCWND");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_NODELAY =
// valueOf(UkcpChannelOption.class, "UKCP_NODELAY");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_RCV_WND =
// valueOf(UkcpChannelOption.class, "UKCP_RCV_WND");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_SND_WND =
// valueOf(UkcpChannelOption.class, "UKCP_SND_WND");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_STREAM =
// valueOf(UkcpChannelOption.class, "UKCP_STREAM");
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/DefaultUkcpServerChildChannelConfig.java
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_AUTO_SET_CONV;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_DEAD_LINK;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_FAST_FLUSH;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_FAST_LIMIT;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_FAST_RESEND;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_INTERVAL;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_MERGE_SEGMENT_BUF;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_MIN_RTO;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_MTU;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_NOCWND;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_NODELAY;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_RCV_WND;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_SND_WND;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_STREAM;
import java.util.Map;
import java.util.Objects;
import io.netty.buffer.ByteBufAllocator;
import io.netty.channel.ChannelOption;
import io.netty.channel.DefaultChannelConfig;
import io.netty.channel.FixedRecvByteBufAllocator;
import io.netty.channel.MessageSizeEstimator;
import io.netty.channel.RecvByteBufAllocator;
import io.netty.channel.WriteBufferWaterMark;
package io.jpower.kcp.netty;
/**
* @author <a href="mailto:szhnet@gmail.com">szh</a>
*/
public class DefaultUkcpServerChildChannelConfig extends DefaultChannelConfig implements UkcpChannelConfig {
private final Ukcp ukcp;
public DefaultUkcpServerChildChannelConfig(UkcpServerChildChannel channel, Ukcp ukcp) {
super(channel, new FixedRecvByteBufAllocator(Consts.FIXED_RECV_BYTEBUF_ALLOCATE_SIZE));
this.ukcp = Objects.requireNonNull(ukcp, "ukcp");
}
@Override
@SuppressWarnings("deprecation")
public Map<ChannelOption<?>, Object> getOptions() {
return getOptions(
super.getOptions(), | UKCP_NODELAY, UKCP_INTERVAL, UKCP_FAST_RESEND, UKCP_FAST_LIMIT, UKCP_NOCWND, UKCP_MIN_RTO, UKCP_MTU, |
szhnet/kcp-netty | kcp-netty/src/main/java/io/jpower/kcp/netty/DefaultUkcpServerChildChannelConfig.java | // Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_AUTO_SET_CONV =
// valueOf(UkcpChannelOption.class, "UKCP_AUTO_SET_CONV");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_DEAD_LINK =
// valueOf(UkcpChannelOption.class, "UKCP_DEAD_LINK");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_FAST_FLUSH =
// valueOf(UkcpChannelOption.class, "UKCP_FAST_FLUSH");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_FAST_LIMIT =
// valueOf(UkcpChannelOption.class, "UKCP_FAST_LIMIT");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_FAST_RESEND =
// valueOf(UkcpChannelOption.class, "UKCP_FAST_RESEND");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_INTERVAL =
// valueOf(UkcpChannelOption.class, "UKCP_INTERVAL");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_MERGE_SEGMENT_BUF =
// valueOf(UkcpChannelOption.class, "UKCP_MERGE_SEGMENT_BUF");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_MIN_RTO =
// valueOf(UkcpChannelOption.class, "UKCP_MIN_RTO");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_MTU =
// valueOf(UkcpChannelOption.class, "UKCP_MTU");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_NOCWND =
// valueOf(UkcpChannelOption.class, "UKCP_NOCWND");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_NODELAY =
// valueOf(UkcpChannelOption.class, "UKCP_NODELAY");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_RCV_WND =
// valueOf(UkcpChannelOption.class, "UKCP_RCV_WND");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_SND_WND =
// valueOf(UkcpChannelOption.class, "UKCP_SND_WND");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_STREAM =
// valueOf(UkcpChannelOption.class, "UKCP_STREAM");
| import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_AUTO_SET_CONV;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_DEAD_LINK;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_FAST_FLUSH;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_FAST_LIMIT;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_FAST_RESEND;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_INTERVAL;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_MERGE_SEGMENT_BUF;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_MIN_RTO;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_MTU;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_NOCWND;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_NODELAY;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_RCV_WND;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_SND_WND;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_STREAM;
import java.util.Map;
import java.util.Objects;
import io.netty.buffer.ByteBufAllocator;
import io.netty.channel.ChannelOption;
import io.netty.channel.DefaultChannelConfig;
import io.netty.channel.FixedRecvByteBufAllocator;
import io.netty.channel.MessageSizeEstimator;
import io.netty.channel.RecvByteBufAllocator;
import io.netty.channel.WriteBufferWaterMark; | package io.jpower.kcp.netty;
/**
* @author <a href="mailto:szhnet@gmail.com">szh</a>
*/
public class DefaultUkcpServerChildChannelConfig extends DefaultChannelConfig implements UkcpChannelConfig {
private final Ukcp ukcp;
public DefaultUkcpServerChildChannelConfig(UkcpServerChildChannel channel, Ukcp ukcp) {
super(channel, new FixedRecvByteBufAllocator(Consts.FIXED_RECV_BYTEBUF_ALLOCATE_SIZE));
this.ukcp = Objects.requireNonNull(ukcp, "ukcp");
}
@Override
@SuppressWarnings("deprecation")
public Map<ChannelOption<?>, Object> getOptions() {
return getOptions(
super.getOptions(), | // Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_AUTO_SET_CONV =
// valueOf(UkcpChannelOption.class, "UKCP_AUTO_SET_CONV");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_DEAD_LINK =
// valueOf(UkcpChannelOption.class, "UKCP_DEAD_LINK");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_FAST_FLUSH =
// valueOf(UkcpChannelOption.class, "UKCP_FAST_FLUSH");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_FAST_LIMIT =
// valueOf(UkcpChannelOption.class, "UKCP_FAST_LIMIT");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_FAST_RESEND =
// valueOf(UkcpChannelOption.class, "UKCP_FAST_RESEND");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_INTERVAL =
// valueOf(UkcpChannelOption.class, "UKCP_INTERVAL");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_MERGE_SEGMENT_BUF =
// valueOf(UkcpChannelOption.class, "UKCP_MERGE_SEGMENT_BUF");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_MIN_RTO =
// valueOf(UkcpChannelOption.class, "UKCP_MIN_RTO");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_MTU =
// valueOf(UkcpChannelOption.class, "UKCP_MTU");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_NOCWND =
// valueOf(UkcpChannelOption.class, "UKCP_NOCWND");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_NODELAY =
// valueOf(UkcpChannelOption.class, "UKCP_NODELAY");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_RCV_WND =
// valueOf(UkcpChannelOption.class, "UKCP_RCV_WND");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_SND_WND =
// valueOf(UkcpChannelOption.class, "UKCP_SND_WND");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_STREAM =
// valueOf(UkcpChannelOption.class, "UKCP_STREAM");
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/DefaultUkcpServerChildChannelConfig.java
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_AUTO_SET_CONV;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_DEAD_LINK;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_FAST_FLUSH;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_FAST_LIMIT;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_FAST_RESEND;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_INTERVAL;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_MERGE_SEGMENT_BUF;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_MIN_RTO;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_MTU;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_NOCWND;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_NODELAY;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_RCV_WND;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_SND_WND;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_STREAM;
import java.util.Map;
import java.util.Objects;
import io.netty.buffer.ByteBufAllocator;
import io.netty.channel.ChannelOption;
import io.netty.channel.DefaultChannelConfig;
import io.netty.channel.FixedRecvByteBufAllocator;
import io.netty.channel.MessageSizeEstimator;
import io.netty.channel.RecvByteBufAllocator;
import io.netty.channel.WriteBufferWaterMark;
package io.jpower.kcp.netty;
/**
* @author <a href="mailto:szhnet@gmail.com">szh</a>
*/
public class DefaultUkcpServerChildChannelConfig extends DefaultChannelConfig implements UkcpChannelConfig {
private final Ukcp ukcp;
public DefaultUkcpServerChildChannelConfig(UkcpServerChildChannel channel, Ukcp ukcp) {
super(channel, new FixedRecvByteBufAllocator(Consts.FIXED_RECV_BYTEBUF_ALLOCATE_SIZE));
this.ukcp = Objects.requireNonNull(ukcp, "ukcp");
}
@Override
@SuppressWarnings("deprecation")
public Map<ChannelOption<?>, Object> getOptions() {
return getOptions(
super.getOptions(), | UKCP_NODELAY, UKCP_INTERVAL, UKCP_FAST_RESEND, UKCP_FAST_LIMIT, UKCP_NOCWND, UKCP_MIN_RTO, UKCP_MTU, |
szhnet/kcp-netty | kcp-netty/src/main/java/io/jpower/kcp/netty/DefaultUkcpServerChildChannelConfig.java | // Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_AUTO_SET_CONV =
// valueOf(UkcpChannelOption.class, "UKCP_AUTO_SET_CONV");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_DEAD_LINK =
// valueOf(UkcpChannelOption.class, "UKCP_DEAD_LINK");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_FAST_FLUSH =
// valueOf(UkcpChannelOption.class, "UKCP_FAST_FLUSH");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_FAST_LIMIT =
// valueOf(UkcpChannelOption.class, "UKCP_FAST_LIMIT");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_FAST_RESEND =
// valueOf(UkcpChannelOption.class, "UKCP_FAST_RESEND");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_INTERVAL =
// valueOf(UkcpChannelOption.class, "UKCP_INTERVAL");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_MERGE_SEGMENT_BUF =
// valueOf(UkcpChannelOption.class, "UKCP_MERGE_SEGMENT_BUF");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_MIN_RTO =
// valueOf(UkcpChannelOption.class, "UKCP_MIN_RTO");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_MTU =
// valueOf(UkcpChannelOption.class, "UKCP_MTU");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_NOCWND =
// valueOf(UkcpChannelOption.class, "UKCP_NOCWND");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_NODELAY =
// valueOf(UkcpChannelOption.class, "UKCP_NODELAY");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_RCV_WND =
// valueOf(UkcpChannelOption.class, "UKCP_RCV_WND");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_SND_WND =
// valueOf(UkcpChannelOption.class, "UKCP_SND_WND");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_STREAM =
// valueOf(UkcpChannelOption.class, "UKCP_STREAM");
| import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_AUTO_SET_CONV;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_DEAD_LINK;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_FAST_FLUSH;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_FAST_LIMIT;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_FAST_RESEND;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_INTERVAL;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_MERGE_SEGMENT_BUF;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_MIN_RTO;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_MTU;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_NOCWND;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_NODELAY;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_RCV_WND;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_SND_WND;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_STREAM;
import java.util.Map;
import java.util.Objects;
import io.netty.buffer.ByteBufAllocator;
import io.netty.channel.ChannelOption;
import io.netty.channel.DefaultChannelConfig;
import io.netty.channel.FixedRecvByteBufAllocator;
import io.netty.channel.MessageSizeEstimator;
import io.netty.channel.RecvByteBufAllocator;
import io.netty.channel.WriteBufferWaterMark; | package io.jpower.kcp.netty;
/**
* @author <a href="mailto:szhnet@gmail.com">szh</a>
*/
public class DefaultUkcpServerChildChannelConfig extends DefaultChannelConfig implements UkcpChannelConfig {
private final Ukcp ukcp;
public DefaultUkcpServerChildChannelConfig(UkcpServerChildChannel channel, Ukcp ukcp) {
super(channel, new FixedRecvByteBufAllocator(Consts.FIXED_RECV_BYTEBUF_ALLOCATE_SIZE));
this.ukcp = Objects.requireNonNull(ukcp, "ukcp");
}
@Override
@SuppressWarnings("deprecation")
public Map<ChannelOption<?>, Object> getOptions() {
return getOptions(
super.getOptions(), | // Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_AUTO_SET_CONV =
// valueOf(UkcpChannelOption.class, "UKCP_AUTO_SET_CONV");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_DEAD_LINK =
// valueOf(UkcpChannelOption.class, "UKCP_DEAD_LINK");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_FAST_FLUSH =
// valueOf(UkcpChannelOption.class, "UKCP_FAST_FLUSH");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_FAST_LIMIT =
// valueOf(UkcpChannelOption.class, "UKCP_FAST_LIMIT");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_FAST_RESEND =
// valueOf(UkcpChannelOption.class, "UKCP_FAST_RESEND");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_INTERVAL =
// valueOf(UkcpChannelOption.class, "UKCP_INTERVAL");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_MERGE_SEGMENT_BUF =
// valueOf(UkcpChannelOption.class, "UKCP_MERGE_SEGMENT_BUF");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_MIN_RTO =
// valueOf(UkcpChannelOption.class, "UKCP_MIN_RTO");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_MTU =
// valueOf(UkcpChannelOption.class, "UKCP_MTU");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_NOCWND =
// valueOf(UkcpChannelOption.class, "UKCP_NOCWND");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_NODELAY =
// valueOf(UkcpChannelOption.class, "UKCP_NODELAY");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_RCV_WND =
// valueOf(UkcpChannelOption.class, "UKCP_RCV_WND");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_SND_WND =
// valueOf(UkcpChannelOption.class, "UKCP_SND_WND");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_STREAM =
// valueOf(UkcpChannelOption.class, "UKCP_STREAM");
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/DefaultUkcpServerChildChannelConfig.java
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_AUTO_SET_CONV;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_DEAD_LINK;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_FAST_FLUSH;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_FAST_LIMIT;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_FAST_RESEND;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_INTERVAL;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_MERGE_SEGMENT_BUF;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_MIN_RTO;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_MTU;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_NOCWND;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_NODELAY;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_RCV_WND;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_SND_WND;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_STREAM;
import java.util.Map;
import java.util.Objects;
import io.netty.buffer.ByteBufAllocator;
import io.netty.channel.ChannelOption;
import io.netty.channel.DefaultChannelConfig;
import io.netty.channel.FixedRecvByteBufAllocator;
import io.netty.channel.MessageSizeEstimator;
import io.netty.channel.RecvByteBufAllocator;
import io.netty.channel.WriteBufferWaterMark;
package io.jpower.kcp.netty;
/**
* @author <a href="mailto:szhnet@gmail.com">szh</a>
*/
public class DefaultUkcpServerChildChannelConfig extends DefaultChannelConfig implements UkcpChannelConfig {
private final Ukcp ukcp;
public DefaultUkcpServerChildChannelConfig(UkcpServerChildChannel channel, Ukcp ukcp) {
super(channel, new FixedRecvByteBufAllocator(Consts.FIXED_RECV_BYTEBUF_ALLOCATE_SIZE));
this.ukcp = Objects.requireNonNull(ukcp, "ukcp");
}
@Override
@SuppressWarnings("deprecation")
public Map<ChannelOption<?>, Object> getOptions() {
return getOptions(
super.getOptions(), | UKCP_NODELAY, UKCP_INTERVAL, UKCP_FAST_RESEND, UKCP_FAST_LIMIT, UKCP_NOCWND, UKCP_MIN_RTO, UKCP_MTU, |
szhnet/kcp-netty | kcp-netty/src/main/java/io/jpower/kcp/netty/DefaultUkcpServerChildChannelConfig.java | // Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_AUTO_SET_CONV =
// valueOf(UkcpChannelOption.class, "UKCP_AUTO_SET_CONV");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_DEAD_LINK =
// valueOf(UkcpChannelOption.class, "UKCP_DEAD_LINK");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_FAST_FLUSH =
// valueOf(UkcpChannelOption.class, "UKCP_FAST_FLUSH");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_FAST_LIMIT =
// valueOf(UkcpChannelOption.class, "UKCP_FAST_LIMIT");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_FAST_RESEND =
// valueOf(UkcpChannelOption.class, "UKCP_FAST_RESEND");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_INTERVAL =
// valueOf(UkcpChannelOption.class, "UKCP_INTERVAL");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_MERGE_SEGMENT_BUF =
// valueOf(UkcpChannelOption.class, "UKCP_MERGE_SEGMENT_BUF");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_MIN_RTO =
// valueOf(UkcpChannelOption.class, "UKCP_MIN_RTO");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_MTU =
// valueOf(UkcpChannelOption.class, "UKCP_MTU");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_NOCWND =
// valueOf(UkcpChannelOption.class, "UKCP_NOCWND");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_NODELAY =
// valueOf(UkcpChannelOption.class, "UKCP_NODELAY");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_RCV_WND =
// valueOf(UkcpChannelOption.class, "UKCP_RCV_WND");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_SND_WND =
// valueOf(UkcpChannelOption.class, "UKCP_SND_WND");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_STREAM =
// valueOf(UkcpChannelOption.class, "UKCP_STREAM");
| import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_AUTO_SET_CONV;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_DEAD_LINK;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_FAST_FLUSH;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_FAST_LIMIT;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_FAST_RESEND;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_INTERVAL;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_MERGE_SEGMENT_BUF;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_MIN_RTO;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_MTU;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_NOCWND;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_NODELAY;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_RCV_WND;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_SND_WND;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_STREAM;
import java.util.Map;
import java.util.Objects;
import io.netty.buffer.ByteBufAllocator;
import io.netty.channel.ChannelOption;
import io.netty.channel.DefaultChannelConfig;
import io.netty.channel.FixedRecvByteBufAllocator;
import io.netty.channel.MessageSizeEstimator;
import io.netty.channel.RecvByteBufAllocator;
import io.netty.channel.WriteBufferWaterMark; | package io.jpower.kcp.netty;
/**
* @author <a href="mailto:szhnet@gmail.com">szh</a>
*/
public class DefaultUkcpServerChildChannelConfig extends DefaultChannelConfig implements UkcpChannelConfig {
private final Ukcp ukcp;
public DefaultUkcpServerChildChannelConfig(UkcpServerChildChannel channel, Ukcp ukcp) {
super(channel, new FixedRecvByteBufAllocator(Consts.FIXED_RECV_BYTEBUF_ALLOCATE_SIZE));
this.ukcp = Objects.requireNonNull(ukcp, "ukcp");
}
@Override
@SuppressWarnings("deprecation")
public Map<ChannelOption<?>, Object> getOptions() {
return getOptions(
super.getOptions(),
UKCP_NODELAY, UKCP_INTERVAL, UKCP_FAST_RESEND, UKCP_FAST_LIMIT, UKCP_NOCWND, UKCP_MIN_RTO, UKCP_MTU, | // Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_AUTO_SET_CONV =
// valueOf(UkcpChannelOption.class, "UKCP_AUTO_SET_CONV");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_DEAD_LINK =
// valueOf(UkcpChannelOption.class, "UKCP_DEAD_LINK");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_FAST_FLUSH =
// valueOf(UkcpChannelOption.class, "UKCP_FAST_FLUSH");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_FAST_LIMIT =
// valueOf(UkcpChannelOption.class, "UKCP_FAST_LIMIT");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_FAST_RESEND =
// valueOf(UkcpChannelOption.class, "UKCP_FAST_RESEND");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_INTERVAL =
// valueOf(UkcpChannelOption.class, "UKCP_INTERVAL");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_MERGE_SEGMENT_BUF =
// valueOf(UkcpChannelOption.class, "UKCP_MERGE_SEGMENT_BUF");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_MIN_RTO =
// valueOf(UkcpChannelOption.class, "UKCP_MIN_RTO");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_MTU =
// valueOf(UkcpChannelOption.class, "UKCP_MTU");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_NOCWND =
// valueOf(UkcpChannelOption.class, "UKCP_NOCWND");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_NODELAY =
// valueOf(UkcpChannelOption.class, "UKCP_NODELAY");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_RCV_WND =
// valueOf(UkcpChannelOption.class, "UKCP_RCV_WND");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_SND_WND =
// valueOf(UkcpChannelOption.class, "UKCP_SND_WND");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_STREAM =
// valueOf(UkcpChannelOption.class, "UKCP_STREAM");
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/DefaultUkcpServerChildChannelConfig.java
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_AUTO_SET_CONV;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_DEAD_LINK;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_FAST_FLUSH;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_FAST_LIMIT;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_FAST_RESEND;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_INTERVAL;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_MERGE_SEGMENT_BUF;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_MIN_RTO;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_MTU;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_NOCWND;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_NODELAY;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_RCV_WND;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_SND_WND;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_STREAM;
import java.util.Map;
import java.util.Objects;
import io.netty.buffer.ByteBufAllocator;
import io.netty.channel.ChannelOption;
import io.netty.channel.DefaultChannelConfig;
import io.netty.channel.FixedRecvByteBufAllocator;
import io.netty.channel.MessageSizeEstimator;
import io.netty.channel.RecvByteBufAllocator;
import io.netty.channel.WriteBufferWaterMark;
package io.jpower.kcp.netty;
/**
* @author <a href="mailto:szhnet@gmail.com">szh</a>
*/
public class DefaultUkcpServerChildChannelConfig extends DefaultChannelConfig implements UkcpChannelConfig {
private final Ukcp ukcp;
public DefaultUkcpServerChildChannelConfig(UkcpServerChildChannel channel, Ukcp ukcp) {
super(channel, new FixedRecvByteBufAllocator(Consts.FIXED_RECV_BYTEBUF_ALLOCATE_SIZE));
this.ukcp = Objects.requireNonNull(ukcp, "ukcp");
}
@Override
@SuppressWarnings("deprecation")
public Map<ChannelOption<?>, Object> getOptions() {
return getOptions(
super.getOptions(),
UKCP_NODELAY, UKCP_INTERVAL, UKCP_FAST_RESEND, UKCP_FAST_LIMIT, UKCP_NOCWND, UKCP_MIN_RTO, UKCP_MTU, | UKCP_RCV_WND, UKCP_SND_WND, UKCP_STREAM, UKCP_DEAD_LINK, UKCP_AUTO_SET_CONV, UKCP_FAST_FLUSH, |
szhnet/kcp-netty | kcp-netty/src/main/java/io/jpower/kcp/netty/DefaultUkcpServerChildChannelConfig.java | // Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_AUTO_SET_CONV =
// valueOf(UkcpChannelOption.class, "UKCP_AUTO_SET_CONV");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_DEAD_LINK =
// valueOf(UkcpChannelOption.class, "UKCP_DEAD_LINK");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_FAST_FLUSH =
// valueOf(UkcpChannelOption.class, "UKCP_FAST_FLUSH");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_FAST_LIMIT =
// valueOf(UkcpChannelOption.class, "UKCP_FAST_LIMIT");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_FAST_RESEND =
// valueOf(UkcpChannelOption.class, "UKCP_FAST_RESEND");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_INTERVAL =
// valueOf(UkcpChannelOption.class, "UKCP_INTERVAL");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_MERGE_SEGMENT_BUF =
// valueOf(UkcpChannelOption.class, "UKCP_MERGE_SEGMENT_BUF");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_MIN_RTO =
// valueOf(UkcpChannelOption.class, "UKCP_MIN_RTO");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_MTU =
// valueOf(UkcpChannelOption.class, "UKCP_MTU");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_NOCWND =
// valueOf(UkcpChannelOption.class, "UKCP_NOCWND");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_NODELAY =
// valueOf(UkcpChannelOption.class, "UKCP_NODELAY");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_RCV_WND =
// valueOf(UkcpChannelOption.class, "UKCP_RCV_WND");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_SND_WND =
// valueOf(UkcpChannelOption.class, "UKCP_SND_WND");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_STREAM =
// valueOf(UkcpChannelOption.class, "UKCP_STREAM");
| import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_AUTO_SET_CONV;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_DEAD_LINK;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_FAST_FLUSH;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_FAST_LIMIT;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_FAST_RESEND;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_INTERVAL;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_MERGE_SEGMENT_BUF;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_MIN_RTO;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_MTU;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_NOCWND;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_NODELAY;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_RCV_WND;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_SND_WND;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_STREAM;
import java.util.Map;
import java.util.Objects;
import io.netty.buffer.ByteBufAllocator;
import io.netty.channel.ChannelOption;
import io.netty.channel.DefaultChannelConfig;
import io.netty.channel.FixedRecvByteBufAllocator;
import io.netty.channel.MessageSizeEstimator;
import io.netty.channel.RecvByteBufAllocator;
import io.netty.channel.WriteBufferWaterMark; | package io.jpower.kcp.netty;
/**
* @author <a href="mailto:szhnet@gmail.com">szh</a>
*/
public class DefaultUkcpServerChildChannelConfig extends DefaultChannelConfig implements UkcpChannelConfig {
private final Ukcp ukcp;
public DefaultUkcpServerChildChannelConfig(UkcpServerChildChannel channel, Ukcp ukcp) {
super(channel, new FixedRecvByteBufAllocator(Consts.FIXED_RECV_BYTEBUF_ALLOCATE_SIZE));
this.ukcp = Objects.requireNonNull(ukcp, "ukcp");
}
@Override
@SuppressWarnings("deprecation")
public Map<ChannelOption<?>, Object> getOptions() {
return getOptions(
super.getOptions(),
UKCP_NODELAY, UKCP_INTERVAL, UKCP_FAST_RESEND, UKCP_FAST_LIMIT, UKCP_NOCWND, UKCP_MIN_RTO, UKCP_MTU, | // Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_AUTO_SET_CONV =
// valueOf(UkcpChannelOption.class, "UKCP_AUTO_SET_CONV");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_DEAD_LINK =
// valueOf(UkcpChannelOption.class, "UKCP_DEAD_LINK");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_FAST_FLUSH =
// valueOf(UkcpChannelOption.class, "UKCP_FAST_FLUSH");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_FAST_LIMIT =
// valueOf(UkcpChannelOption.class, "UKCP_FAST_LIMIT");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_FAST_RESEND =
// valueOf(UkcpChannelOption.class, "UKCP_FAST_RESEND");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_INTERVAL =
// valueOf(UkcpChannelOption.class, "UKCP_INTERVAL");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_MERGE_SEGMENT_BUF =
// valueOf(UkcpChannelOption.class, "UKCP_MERGE_SEGMENT_BUF");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_MIN_RTO =
// valueOf(UkcpChannelOption.class, "UKCP_MIN_RTO");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_MTU =
// valueOf(UkcpChannelOption.class, "UKCP_MTU");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_NOCWND =
// valueOf(UkcpChannelOption.class, "UKCP_NOCWND");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_NODELAY =
// valueOf(UkcpChannelOption.class, "UKCP_NODELAY");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_RCV_WND =
// valueOf(UkcpChannelOption.class, "UKCP_RCV_WND");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_SND_WND =
// valueOf(UkcpChannelOption.class, "UKCP_SND_WND");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_STREAM =
// valueOf(UkcpChannelOption.class, "UKCP_STREAM");
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/DefaultUkcpServerChildChannelConfig.java
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_AUTO_SET_CONV;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_DEAD_LINK;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_FAST_FLUSH;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_FAST_LIMIT;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_FAST_RESEND;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_INTERVAL;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_MERGE_SEGMENT_BUF;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_MIN_RTO;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_MTU;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_NOCWND;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_NODELAY;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_RCV_WND;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_SND_WND;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_STREAM;
import java.util.Map;
import java.util.Objects;
import io.netty.buffer.ByteBufAllocator;
import io.netty.channel.ChannelOption;
import io.netty.channel.DefaultChannelConfig;
import io.netty.channel.FixedRecvByteBufAllocator;
import io.netty.channel.MessageSizeEstimator;
import io.netty.channel.RecvByteBufAllocator;
import io.netty.channel.WriteBufferWaterMark;
package io.jpower.kcp.netty;
/**
* @author <a href="mailto:szhnet@gmail.com">szh</a>
*/
public class DefaultUkcpServerChildChannelConfig extends DefaultChannelConfig implements UkcpChannelConfig {
private final Ukcp ukcp;
public DefaultUkcpServerChildChannelConfig(UkcpServerChildChannel channel, Ukcp ukcp) {
super(channel, new FixedRecvByteBufAllocator(Consts.FIXED_RECV_BYTEBUF_ALLOCATE_SIZE));
this.ukcp = Objects.requireNonNull(ukcp, "ukcp");
}
@Override
@SuppressWarnings("deprecation")
public Map<ChannelOption<?>, Object> getOptions() {
return getOptions(
super.getOptions(),
UKCP_NODELAY, UKCP_INTERVAL, UKCP_FAST_RESEND, UKCP_FAST_LIMIT, UKCP_NOCWND, UKCP_MIN_RTO, UKCP_MTU, | UKCP_RCV_WND, UKCP_SND_WND, UKCP_STREAM, UKCP_DEAD_LINK, UKCP_AUTO_SET_CONV, UKCP_FAST_FLUSH, |
szhnet/kcp-netty | kcp-netty/src/main/java/io/jpower/kcp/netty/DefaultUkcpServerChildChannelConfig.java | // Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_AUTO_SET_CONV =
// valueOf(UkcpChannelOption.class, "UKCP_AUTO_SET_CONV");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_DEAD_LINK =
// valueOf(UkcpChannelOption.class, "UKCP_DEAD_LINK");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_FAST_FLUSH =
// valueOf(UkcpChannelOption.class, "UKCP_FAST_FLUSH");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_FAST_LIMIT =
// valueOf(UkcpChannelOption.class, "UKCP_FAST_LIMIT");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_FAST_RESEND =
// valueOf(UkcpChannelOption.class, "UKCP_FAST_RESEND");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_INTERVAL =
// valueOf(UkcpChannelOption.class, "UKCP_INTERVAL");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_MERGE_SEGMENT_BUF =
// valueOf(UkcpChannelOption.class, "UKCP_MERGE_SEGMENT_BUF");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_MIN_RTO =
// valueOf(UkcpChannelOption.class, "UKCP_MIN_RTO");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_MTU =
// valueOf(UkcpChannelOption.class, "UKCP_MTU");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_NOCWND =
// valueOf(UkcpChannelOption.class, "UKCP_NOCWND");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_NODELAY =
// valueOf(UkcpChannelOption.class, "UKCP_NODELAY");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_RCV_WND =
// valueOf(UkcpChannelOption.class, "UKCP_RCV_WND");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_SND_WND =
// valueOf(UkcpChannelOption.class, "UKCP_SND_WND");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_STREAM =
// valueOf(UkcpChannelOption.class, "UKCP_STREAM");
| import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_AUTO_SET_CONV;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_DEAD_LINK;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_FAST_FLUSH;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_FAST_LIMIT;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_FAST_RESEND;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_INTERVAL;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_MERGE_SEGMENT_BUF;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_MIN_RTO;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_MTU;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_NOCWND;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_NODELAY;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_RCV_WND;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_SND_WND;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_STREAM;
import java.util.Map;
import java.util.Objects;
import io.netty.buffer.ByteBufAllocator;
import io.netty.channel.ChannelOption;
import io.netty.channel.DefaultChannelConfig;
import io.netty.channel.FixedRecvByteBufAllocator;
import io.netty.channel.MessageSizeEstimator;
import io.netty.channel.RecvByteBufAllocator;
import io.netty.channel.WriteBufferWaterMark; | package io.jpower.kcp.netty;
/**
* @author <a href="mailto:szhnet@gmail.com">szh</a>
*/
public class DefaultUkcpServerChildChannelConfig extends DefaultChannelConfig implements UkcpChannelConfig {
private final Ukcp ukcp;
public DefaultUkcpServerChildChannelConfig(UkcpServerChildChannel channel, Ukcp ukcp) {
super(channel, new FixedRecvByteBufAllocator(Consts.FIXED_RECV_BYTEBUF_ALLOCATE_SIZE));
this.ukcp = Objects.requireNonNull(ukcp, "ukcp");
}
@Override
@SuppressWarnings("deprecation")
public Map<ChannelOption<?>, Object> getOptions() {
return getOptions(
super.getOptions(),
UKCP_NODELAY, UKCP_INTERVAL, UKCP_FAST_RESEND, UKCP_FAST_LIMIT, UKCP_NOCWND, UKCP_MIN_RTO, UKCP_MTU, | // Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_AUTO_SET_CONV =
// valueOf(UkcpChannelOption.class, "UKCP_AUTO_SET_CONV");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_DEAD_LINK =
// valueOf(UkcpChannelOption.class, "UKCP_DEAD_LINK");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_FAST_FLUSH =
// valueOf(UkcpChannelOption.class, "UKCP_FAST_FLUSH");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_FAST_LIMIT =
// valueOf(UkcpChannelOption.class, "UKCP_FAST_LIMIT");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_FAST_RESEND =
// valueOf(UkcpChannelOption.class, "UKCP_FAST_RESEND");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_INTERVAL =
// valueOf(UkcpChannelOption.class, "UKCP_INTERVAL");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_MERGE_SEGMENT_BUF =
// valueOf(UkcpChannelOption.class, "UKCP_MERGE_SEGMENT_BUF");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_MIN_RTO =
// valueOf(UkcpChannelOption.class, "UKCP_MIN_RTO");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_MTU =
// valueOf(UkcpChannelOption.class, "UKCP_MTU");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_NOCWND =
// valueOf(UkcpChannelOption.class, "UKCP_NOCWND");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_NODELAY =
// valueOf(UkcpChannelOption.class, "UKCP_NODELAY");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_RCV_WND =
// valueOf(UkcpChannelOption.class, "UKCP_RCV_WND");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_SND_WND =
// valueOf(UkcpChannelOption.class, "UKCP_SND_WND");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_STREAM =
// valueOf(UkcpChannelOption.class, "UKCP_STREAM");
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/DefaultUkcpServerChildChannelConfig.java
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_AUTO_SET_CONV;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_DEAD_LINK;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_FAST_FLUSH;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_FAST_LIMIT;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_FAST_RESEND;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_INTERVAL;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_MERGE_SEGMENT_BUF;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_MIN_RTO;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_MTU;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_NOCWND;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_NODELAY;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_RCV_WND;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_SND_WND;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_STREAM;
import java.util.Map;
import java.util.Objects;
import io.netty.buffer.ByteBufAllocator;
import io.netty.channel.ChannelOption;
import io.netty.channel.DefaultChannelConfig;
import io.netty.channel.FixedRecvByteBufAllocator;
import io.netty.channel.MessageSizeEstimator;
import io.netty.channel.RecvByteBufAllocator;
import io.netty.channel.WriteBufferWaterMark;
package io.jpower.kcp.netty;
/**
* @author <a href="mailto:szhnet@gmail.com">szh</a>
*/
public class DefaultUkcpServerChildChannelConfig extends DefaultChannelConfig implements UkcpChannelConfig {
private final Ukcp ukcp;
public DefaultUkcpServerChildChannelConfig(UkcpServerChildChannel channel, Ukcp ukcp) {
super(channel, new FixedRecvByteBufAllocator(Consts.FIXED_RECV_BYTEBUF_ALLOCATE_SIZE));
this.ukcp = Objects.requireNonNull(ukcp, "ukcp");
}
@Override
@SuppressWarnings("deprecation")
public Map<ChannelOption<?>, Object> getOptions() {
return getOptions(
super.getOptions(),
UKCP_NODELAY, UKCP_INTERVAL, UKCP_FAST_RESEND, UKCP_FAST_LIMIT, UKCP_NOCWND, UKCP_MIN_RTO, UKCP_MTU, | UKCP_RCV_WND, UKCP_SND_WND, UKCP_STREAM, UKCP_DEAD_LINK, UKCP_AUTO_SET_CONV, UKCP_FAST_FLUSH, |
szhnet/kcp-netty | kcp-netty/src/main/java/io/jpower/kcp/netty/DefaultUkcpServerChildChannelConfig.java | // Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_AUTO_SET_CONV =
// valueOf(UkcpChannelOption.class, "UKCP_AUTO_SET_CONV");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_DEAD_LINK =
// valueOf(UkcpChannelOption.class, "UKCP_DEAD_LINK");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_FAST_FLUSH =
// valueOf(UkcpChannelOption.class, "UKCP_FAST_FLUSH");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_FAST_LIMIT =
// valueOf(UkcpChannelOption.class, "UKCP_FAST_LIMIT");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_FAST_RESEND =
// valueOf(UkcpChannelOption.class, "UKCP_FAST_RESEND");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_INTERVAL =
// valueOf(UkcpChannelOption.class, "UKCP_INTERVAL");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_MERGE_SEGMENT_BUF =
// valueOf(UkcpChannelOption.class, "UKCP_MERGE_SEGMENT_BUF");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_MIN_RTO =
// valueOf(UkcpChannelOption.class, "UKCP_MIN_RTO");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_MTU =
// valueOf(UkcpChannelOption.class, "UKCP_MTU");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_NOCWND =
// valueOf(UkcpChannelOption.class, "UKCP_NOCWND");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_NODELAY =
// valueOf(UkcpChannelOption.class, "UKCP_NODELAY");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_RCV_WND =
// valueOf(UkcpChannelOption.class, "UKCP_RCV_WND");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_SND_WND =
// valueOf(UkcpChannelOption.class, "UKCP_SND_WND");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_STREAM =
// valueOf(UkcpChannelOption.class, "UKCP_STREAM");
| import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_AUTO_SET_CONV;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_DEAD_LINK;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_FAST_FLUSH;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_FAST_LIMIT;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_FAST_RESEND;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_INTERVAL;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_MERGE_SEGMENT_BUF;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_MIN_RTO;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_MTU;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_NOCWND;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_NODELAY;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_RCV_WND;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_SND_WND;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_STREAM;
import java.util.Map;
import java.util.Objects;
import io.netty.buffer.ByteBufAllocator;
import io.netty.channel.ChannelOption;
import io.netty.channel.DefaultChannelConfig;
import io.netty.channel.FixedRecvByteBufAllocator;
import io.netty.channel.MessageSizeEstimator;
import io.netty.channel.RecvByteBufAllocator;
import io.netty.channel.WriteBufferWaterMark; | package io.jpower.kcp.netty;
/**
* @author <a href="mailto:szhnet@gmail.com">szh</a>
*/
public class DefaultUkcpServerChildChannelConfig extends DefaultChannelConfig implements UkcpChannelConfig {
private final Ukcp ukcp;
public DefaultUkcpServerChildChannelConfig(UkcpServerChildChannel channel, Ukcp ukcp) {
super(channel, new FixedRecvByteBufAllocator(Consts.FIXED_RECV_BYTEBUF_ALLOCATE_SIZE));
this.ukcp = Objects.requireNonNull(ukcp, "ukcp");
}
@Override
@SuppressWarnings("deprecation")
public Map<ChannelOption<?>, Object> getOptions() {
return getOptions(
super.getOptions(),
UKCP_NODELAY, UKCP_INTERVAL, UKCP_FAST_RESEND, UKCP_FAST_LIMIT, UKCP_NOCWND, UKCP_MIN_RTO, UKCP_MTU, | // Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_AUTO_SET_CONV =
// valueOf(UkcpChannelOption.class, "UKCP_AUTO_SET_CONV");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_DEAD_LINK =
// valueOf(UkcpChannelOption.class, "UKCP_DEAD_LINK");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_FAST_FLUSH =
// valueOf(UkcpChannelOption.class, "UKCP_FAST_FLUSH");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_FAST_LIMIT =
// valueOf(UkcpChannelOption.class, "UKCP_FAST_LIMIT");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_FAST_RESEND =
// valueOf(UkcpChannelOption.class, "UKCP_FAST_RESEND");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_INTERVAL =
// valueOf(UkcpChannelOption.class, "UKCP_INTERVAL");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_MERGE_SEGMENT_BUF =
// valueOf(UkcpChannelOption.class, "UKCP_MERGE_SEGMENT_BUF");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_MIN_RTO =
// valueOf(UkcpChannelOption.class, "UKCP_MIN_RTO");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_MTU =
// valueOf(UkcpChannelOption.class, "UKCP_MTU");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_NOCWND =
// valueOf(UkcpChannelOption.class, "UKCP_NOCWND");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_NODELAY =
// valueOf(UkcpChannelOption.class, "UKCP_NODELAY");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_RCV_WND =
// valueOf(UkcpChannelOption.class, "UKCP_RCV_WND");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_SND_WND =
// valueOf(UkcpChannelOption.class, "UKCP_SND_WND");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_STREAM =
// valueOf(UkcpChannelOption.class, "UKCP_STREAM");
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/DefaultUkcpServerChildChannelConfig.java
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_AUTO_SET_CONV;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_DEAD_LINK;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_FAST_FLUSH;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_FAST_LIMIT;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_FAST_RESEND;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_INTERVAL;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_MERGE_SEGMENT_BUF;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_MIN_RTO;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_MTU;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_NOCWND;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_NODELAY;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_RCV_WND;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_SND_WND;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_STREAM;
import java.util.Map;
import java.util.Objects;
import io.netty.buffer.ByteBufAllocator;
import io.netty.channel.ChannelOption;
import io.netty.channel.DefaultChannelConfig;
import io.netty.channel.FixedRecvByteBufAllocator;
import io.netty.channel.MessageSizeEstimator;
import io.netty.channel.RecvByteBufAllocator;
import io.netty.channel.WriteBufferWaterMark;
package io.jpower.kcp.netty;
/**
* @author <a href="mailto:szhnet@gmail.com">szh</a>
*/
public class DefaultUkcpServerChildChannelConfig extends DefaultChannelConfig implements UkcpChannelConfig {
private final Ukcp ukcp;
public DefaultUkcpServerChildChannelConfig(UkcpServerChildChannel channel, Ukcp ukcp) {
super(channel, new FixedRecvByteBufAllocator(Consts.FIXED_RECV_BYTEBUF_ALLOCATE_SIZE));
this.ukcp = Objects.requireNonNull(ukcp, "ukcp");
}
@Override
@SuppressWarnings("deprecation")
public Map<ChannelOption<?>, Object> getOptions() {
return getOptions(
super.getOptions(),
UKCP_NODELAY, UKCP_INTERVAL, UKCP_FAST_RESEND, UKCP_FAST_LIMIT, UKCP_NOCWND, UKCP_MIN_RTO, UKCP_MTU, | UKCP_RCV_WND, UKCP_SND_WND, UKCP_STREAM, UKCP_DEAD_LINK, UKCP_AUTO_SET_CONV, UKCP_FAST_FLUSH, |
szhnet/kcp-netty | kcp-netty/src/main/java/io/jpower/kcp/netty/DefaultUkcpServerChildChannelConfig.java | // Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_AUTO_SET_CONV =
// valueOf(UkcpChannelOption.class, "UKCP_AUTO_SET_CONV");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_DEAD_LINK =
// valueOf(UkcpChannelOption.class, "UKCP_DEAD_LINK");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_FAST_FLUSH =
// valueOf(UkcpChannelOption.class, "UKCP_FAST_FLUSH");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_FAST_LIMIT =
// valueOf(UkcpChannelOption.class, "UKCP_FAST_LIMIT");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_FAST_RESEND =
// valueOf(UkcpChannelOption.class, "UKCP_FAST_RESEND");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_INTERVAL =
// valueOf(UkcpChannelOption.class, "UKCP_INTERVAL");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_MERGE_SEGMENT_BUF =
// valueOf(UkcpChannelOption.class, "UKCP_MERGE_SEGMENT_BUF");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_MIN_RTO =
// valueOf(UkcpChannelOption.class, "UKCP_MIN_RTO");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_MTU =
// valueOf(UkcpChannelOption.class, "UKCP_MTU");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_NOCWND =
// valueOf(UkcpChannelOption.class, "UKCP_NOCWND");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_NODELAY =
// valueOf(UkcpChannelOption.class, "UKCP_NODELAY");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_RCV_WND =
// valueOf(UkcpChannelOption.class, "UKCP_RCV_WND");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_SND_WND =
// valueOf(UkcpChannelOption.class, "UKCP_SND_WND");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_STREAM =
// valueOf(UkcpChannelOption.class, "UKCP_STREAM");
| import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_AUTO_SET_CONV;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_DEAD_LINK;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_FAST_FLUSH;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_FAST_LIMIT;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_FAST_RESEND;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_INTERVAL;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_MERGE_SEGMENT_BUF;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_MIN_RTO;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_MTU;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_NOCWND;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_NODELAY;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_RCV_WND;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_SND_WND;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_STREAM;
import java.util.Map;
import java.util.Objects;
import io.netty.buffer.ByteBufAllocator;
import io.netty.channel.ChannelOption;
import io.netty.channel.DefaultChannelConfig;
import io.netty.channel.FixedRecvByteBufAllocator;
import io.netty.channel.MessageSizeEstimator;
import io.netty.channel.RecvByteBufAllocator;
import io.netty.channel.WriteBufferWaterMark; | package io.jpower.kcp.netty;
/**
* @author <a href="mailto:szhnet@gmail.com">szh</a>
*/
public class DefaultUkcpServerChildChannelConfig extends DefaultChannelConfig implements UkcpChannelConfig {
private final Ukcp ukcp;
public DefaultUkcpServerChildChannelConfig(UkcpServerChildChannel channel, Ukcp ukcp) {
super(channel, new FixedRecvByteBufAllocator(Consts.FIXED_RECV_BYTEBUF_ALLOCATE_SIZE));
this.ukcp = Objects.requireNonNull(ukcp, "ukcp");
}
@Override
@SuppressWarnings("deprecation")
public Map<ChannelOption<?>, Object> getOptions() {
return getOptions(
super.getOptions(),
UKCP_NODELAY, UKCP_INTERVAL, UKCP_FAST_RESEND, UKCP_FAST_LIMIT, UKCP_NOCWND, UKCP_MIN_RTO, UKCP_MTU, | // Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_AUTO_SET_CONV =
// valueOf(UkcpChannelOption.class, "UKCP_AUTO_SET_CONV");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_DEAD_LINK =
// valueOf(UkcpChannelOption.class, "UKCP_DEAD_LINK");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_FAST_FLUSH =
// valueOf(UkcpChannelOption.class, "UKCP_FAST_FLUSH");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_FAST_LIMIT =
// valueOf(UkcpChannelOption.class, "UKCP_FAST_LIMIT");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_FAST_RESEND =
// valueOf(UkcpChannelOption.class, "UKCP_FAST_RESEND");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_INTERVAL =
// valueOf(UkcpChannelOption.class, "UKCP_INTERVAL");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_MERGE_SEGMENT_BUF =
// valueOf(UkcpChannelOption.class, "UKCP_MERGE_SEGMENT_BUF");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_MIN_RTO =
// valueOf(UkcpChannelOption.class, "UKCP_MIN_RTO");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_MTU =
// valueOf(UkcpChannelOption.class, "UKCP_MTU");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_NOCWND =
// valueOf(UkcpChannelOption.class, "UKCP_NOCWND");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_NODELAY =
// valueOf(UkcpChannelOption.class, "UKCP_NODELAY");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_RCV_WND =
// valueOf(UkcpChannelOption.class, "UKCP_RCV_WND");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_SND_WND =
// valueOf(UkcpChannelOption.class, "UKCP_SND_WND");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_STREAM =
// valueOf(UkcpChannelOption.class, "UKCP_STREAM");
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/DefaultUkcpServerChildChannelConfig.java
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_AUTO_SET_CONV;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_DEAD_LINK;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_FAST_FLUSH;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_FAST_LIMIT;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_FAST_RESEND;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_INTERVAL;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_MERGE_SEGMENT_BUF;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_MIN_RTO;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_MTU;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_NOCWND;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_NODELAY;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_RCV_WND;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_SND_WND;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_STREAM;
import java.util.Map;
import java.util.Objects;
import io.netty.buffer.ByteBufAllocator;
import io.netty.channel.ChannelOption;
import io.netty.channel.DefaultChannelConfig;
import io.netty.channel.FixedRecvByteBufAllocator;
import io.netty.channel.MessageSizeEstimator;
import io.netty.channel.RecvByteBufAllocator;
import io.netty.channel.WriteBufferWaterMark;
package io.jpower.kcp.netty;
/**
* @author <a href="mailto:szhnet@gmail.com">szh</a>
*/
public class DefaultUkcpServerChildChannelConfig extends DefaultChannelConfig implements UkcpChannelConfig {
private final Ukcp ukcp;
public DefaultUkcpServerChildChannelConfig(UkcpServerChildChannel channel, Ukcp ukcp) {
super(channel, new FixedRecvByteBufAllocator(Consts.FIXED_RECV_BYTEBUF_ALLOCATE_SIZE));
this.ukcp = Objects.requireNonNull(ukcp, "ukcp");
}
@Override
@SuppressWarnings("deprecation")
public Map<ChannelOption<?>, Object> getOptions() {
return getOptions(
super.getOptions(),
UKCP_NODELAY, UKCP_INTERVAL, UKCP_FAST_RESEND, UKCP_FAST_LIMIT, UKCP_NOCWND, UKCP_MIN_RTO, UKCP_MTU, | UKCP_RCV_WND, UKCP_SND_WND, UKCP_STREAM, UKCP_DEAD_LINK, UKCP_AUTO_SET_CONV, UKCP_FAST_FLUSH, |
szhnet/kcp-netty | kcp-netty/src/main/java/io/jpower/kcp/netty/DefaultUkcpServerChildChannelConfig.java | // Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_AUTO_SET_CONV =
// valueOf(UkcpChannelOption.class, "UKCP_AUTO_SET_CONV");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_DEAD_LINK =
// valueOf(UkcpChannelOption.class, "UKCP_DEAD_LINK");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_FAST_FLUSH =
// valueOf(UkcpChannelOption.class, "UKCP_FAST_FLUSH");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_FAST_LIMIT =
// valueOf(UkcpChannelOption.class, "UKCP_FAST_LIMIT");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_FAST_RESEND =
// valueOf(UkcpChannelOption.class, "UKCP_FAST_RESEND");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_INTERVAL =
// valueOf(UkcpChannelOption.class, "UKCP_INTERVAL");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_MERGE_SEGMENT_BUF =
// valueOf(UkcpChannelOption.class, "UKCP_MERGE_SEGMENT_BUF");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_MIN_RTO =
// valueOf(UkcpChannelOption.class, "UKCP_MIN_RTO");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_MTU =
// valueOf(UkcpChannelOption.class, "UKCP_MTU");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_NOCWND =
// valueOf(UkcpChannelOption.class, "UKCP_NOCWND");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_NODELAY =
// valueOf(UkcpChannelOption.class, "UKCP_NODELAY");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_RCV_WND =
// valueOf(UkcpChannelOption.class, "UKCP_RCV_WND");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_SND_WND =
// valueOf(UkcpChannelOption.class, "UKCP_SND_WND");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_STREAM =
// valueOf(UkcpChannelOption.class, "UKCP_STREAM");
| import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_AUTO_SET_CONV;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_DEAD_LINK;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_FAST_FLUSH;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_FAST_LIMIT;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_FAST_RESEND;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_INTERVAL;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_MERGE_SEGMENT_BUF;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_MIN_RTO;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_MTU;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_NOCWND;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_NODELAY;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_RCV_WND;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_SND_WND;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_STREAM;
import java.util.Map;
import java.util.Objects;
import io.netty.buffer.ByteBufAllocator;
import io.netty.channel.ChannelOption;
import io.netty.channel.DefaultChannelConfig;
import io.netty.channel.FixedRecvByteBufAllocator;
import io.netty.channel.MessageSizeEstimator;
import io.netty.channel.RecvByteBufAllocator;
import io.netty.channel.WriteBufferWaterMark; | package io.jpower.kcp.netty;
/**
* @author <a href="mailto:szhnet@gmail.com">szh</a>
*/
public class DefaultUkcpServerChildChannelConfig extends DefaultChannelConfig implements UkcpChannelConfig {
private final Ukcp ukcp;
public DefaultUkcpServerChildChannelConfig(UkcpServerChildChannel channel, Ukcp ukcp) {
super(channel, new FixedRecvByteBufAllocator(Consts.FIXED_RECV_BYTEBUF_ALLOCATE_SIZE));
this.ukcp = Objects.requireNonNull(ukcp, "ukcp");
}
@Override
@SuppressWarnings("deprecation")
public Map<ChannelOption<?>, Object> getOptions() {
return getOptions(
super.getOptions(),
UKCP_NODELAY, UKCP_INTERVAL, UKCP_FAST_RESEND, UKCP_FAST_LIMIT, UKCP_NOCWND, UKCP_MIN_RTO, UKCP_MTU, | // Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_AUTO_SET_CONV =
// valueOf(UkcpChannelOption.class, "UKCP_AUTO_SET_CONV");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_DEAD_LINK =
// valueOf(UkcpChannelOption.class, "UKCP_DEAD_LINK");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_FAST_FLUSH =
// valueOf(UkcpChannelOption.class, "UKCP_FAST_FLUSH");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_FAST_LIMIT =
// valueOf(UkcpChannelOption.class, "UKCP_FAST_LIMIT");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_FAST_RESEND =
// valueOf(UkcpChannelOption.class, "UKCP_FAST_RESEND");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_INTERVAL =
// valueOf(UkcpChannelOption.class, "UKCP_INTERVAL");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_MERGE_SEGMENT_BUF =
// valueOf(UkcpChannelOption.class, "UKCP_MERGE_SEGMENT_BUF");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_MIN_RTO =
// valueOf(UkcpChannelOption.class, "UKCP_MIN_RTO");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_MTU =
// valueOf(UkcpChannelOption.class, "UKCP_MTU");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_NOCWND =
// valueOf(UkcpChannelOption.class, "UKCP_NOCWND");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_NODELAY =
// valueOf(UkcpChannelOption.class, "UKCP_NODELAY");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_RCV_WND =
// valueOf(UkcpChannelOption.class, "UKCP_RCV_WND");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Integer> UKCP_SND_WND =
// valueOf(UkcpChannelOption.class, "UKCP_SND_WND");
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannelOption.java
// public static final ChannelOption<Boolean> UKCP_STREAM =
// valueOf(UkcpChannelOption.class, "UKCP_STREAM");
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/DefaultUkcpServerChildChannelConfig.java
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_AUTO_SET_CONV;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_DEAD_LINK;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_FAST_FLUSH;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_FAST_LIMIT;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_FAST_RESEND;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_INTERVAL;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_MERGE_SEGMENT_BUF;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_MIN_RTO;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_MTU;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_NOCWND;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_NODELAY;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_RCV_WND;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_SND_WND;
import static io.jpower.kcp.netty.UkcpChannelOption.UKCP_STREAM;
import java.util.Map;
import java.util.Objects;
import io.netty.buffer.ByteBufAllocator;
import io.netty.channel.ChannelOption;
import io.netty.channel.DefaultChannelConfig;
import io.netty.channel.FixedRecvByteBufAllocator;
import io.netty.channel.MessageSizeEstimator;
import io.netty.channel.RecvByteBufAllocator;
import io.netty.channel.WriteBufferWaterMark;
package io.jpower.kcp.netty;
/**
* @author <a href="mailto:szhnet@gmail.com">szh</a>
*/
public class DefaultUkcpServerChildChannelConfig extends DefaultChannelConfig implements UkcpChannelConfig {
private final Ukcp ukcp;
public DefaultUkcpServerChildChannelConfig(UkcpServerChildChannel channel, Ukcp ukcp) {
super(channel, new FixedRecvByteBufAllocator(Consts.FIXED_RECV_BYTEBUF_ALLOCATE_SIZE));
this.ukcp = Objects.requireNonNull(ukcp, "ukcp");
}
@Override
@SuppressWarnings("deprecation")
public Map<ChannelOption<?>, Object> getOptions() {
return getOptions(
super.getOptions(),
UKCP_NODELAY, UKCP_INTERVAL, UKCP_FAST_RESEND, UKCP_FAST_LIMIT, UKCP_NOCWND, UKCP_MIN_RTO, UKCP_MTU, | UKCP_RCV_WND, UKCP_SND_WND, UKCP_STREAM, UKCP_DEAD_LINK, UKCP_AUTO_SET_CONV, UKCP_FAST_FLUSH, |
szhnet/kcp-netty | kcp-example/src/main/java/io/jpower/kcp/example/rtt/KcpRttClientHandler.java | // Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannel.java
// public interface UkcpChannel extends Channel {
//
// int conv();
//
// @Override
// UkcpChannelConfig config();
//
// UkcpChannel conv(int conv);
//
// @Override
// InetSocketAddress localAddress();
//
// @Override
// InetSocketAddress remoteAddress();
//
// }
| import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import io.jpower.kcp.netty.UkcpChannel;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory; | package io.jpower.kcp.example.rtt;
/**
* @author <a href="mailto:szhnet@gmail.com">szh</a>
*/
public class KcpRttClientHandler extends ChannelInboundHandlerAdapter {
private static final Logger log = LoggerFactory.getLogger(KcpRttClientHandler.class);
private final ByteBuf data;
private int[] rtts;
private volatile int count;
private ScheduledExecutorService scheduleSrv;
private ScheduledFuture<?> future = null;
private final long startTime;
/**
* Creates a client-side handler.
*/
public KcpRttClientHandler(int count) {
data = Unpooled.buffer(KcpRttClient.SIZE);
for (int i = 0; i < data.capacity(); i++) {
data.writeByte((byte) i);
}
rtts = new int[count];
for (int i = 0; i < rtts.length; i++) {
rtts[i] = -1;
}
startTime = System.currentTimeMillis();
scheduleSrv = Executors.newSingleThreadScheduledExecutor();
}
@Override
public void channelActive(final ChannelHandlerContext ctx) { | // Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannel.java
// public interface UkcpChannel extends Channel {
//
// int conv();
//
// @Override
// UkcpChannelConfig config();
//
// UkcpChannel conv(int conv);
//
// @Override
// InetSocketAddress localAddress();
//
// @Override
// InetSocketAddress remoteAddress();
//
// }
// Path: kcp-example/src/main/java/io/jpower/kcp/example/rtt/KcpRttClientHandler.java
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import io.jpower.kcp.netty.UkcpChannel;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
package io.jpower.kcp.example.rtt;
/**
* @author <a href="mailto:szhnet@gmail.com">szh</a>
*/
public class KcpRttClientHandler extends ChannelInboundHandlerAdapter {
private static final Logger log = LoggerFactory.getLogger(KcpRttClientHandler.class);
private final ByteBuf data;
private int[] rtts;
private volatile int count;
private ScheduledExecutorService scheduleSrv;
private ScheduledFuture<?> future = null;
private final long startTime;
/**
* Creates a client-side handler.
*/
public KcpRttClientHandler(int count) {
data = Unpooled.buffer(KcpRttClient.SIZE);
for (int i = 0; i < data.capacity(); i++) {
data.writeByte((byte) i);
}
rtts = new int[count];
for (int i = 0; i < rtts.length; i++) {
rtts[i] = -1;
}
startTime = System.currentTimeMillis();
scheduleSrv = Executors.newSingleThreadScheduledExecutor();
}
@Override
public void channelActive(final ChannelHandlerContext ctx) { | UkcpChannel kcpCh = (UkcpChannel) ctx.channel(); |
szhnet/kcp-netty | kcp-netty/src/main/java/io/jpower/kcp/netty/Utils.java | // Path: kcp-netty/src/main/java/io/jpower/kcp/netty/internal/CodecOutputList.java
// @SuppressWarnings({"unchecked", "rawtypes"})
// public class CodecOutputList<T> extends AbstractList<T> implements RandomAccess {
//
// private static final Recycler<CodecOutputList> RECYCLER = new Recycler<CodecOutputList>() {
// @Override
// protected CodecOutputList newObject(Handle<CodecOutputList> handle) {
// return new CodecOutputList(handle);
// }
// };
//
// public static <T> CodecOutputList<T> newInstance() {
// return RECYCLER.get();
// }
//
// private final Recycler.Handle<CodecOutputList<T>> handle;
// private int size;
// // Size of 16 should be good enough for 99 % of all users.
// private Object[] array = new Object[16];
// private boolean insertSinceRecycled;
//
// private CodecOutputList(Recycler.Handle<CodecOutputList<T>> handle) {
// this.handle = handle;
// }
//
// @Override
// public T get(int index) {
// checkIndex(index);
// return (T) array[index];
// }
//
// @Override
// public int size() {
// return size;
// }
//
// @Override
// public boolean add(Object element) {
// checkNotNull(element, "element");
//
// int newSize = size + 1;
// if (newSize > array.length) {
// expandArray();
// }
// insert(size, element);
// size = newSize;
//
// return true;
// }
//
// @Override
// public T set(int index, Object element) {
// checkNotNull(element, "element");
// checkIndex(index);
//
// Object old = array[index];
// insert(index, element);
// return (T) old;
// }
//
// @Override
// public void add(int index, Object element) {
// checkNotNull(element, "element");
// checkIndex(index);
//
// if (size == array.length) {
// expandArray();
// }
//
// if (index != size - 1) {
// System.arraycopy(array, index, array, index + 1, size - index);
// }
//
// insert(index, element);
// ++size;
// }
//
// @Override
// public T remove(int index) {
// checkIndex(index);
// Object old = array[index];
//
// int len = size - index - 1;
// if (len > 0) {
// System.arraycopy(array, index + 1, array, index, len);
// }
// array[--size] = null;
//
// return (T) old;
// }
//
// @Override
// public void clear() {
// // We only set the size to 0 and not null out the array. Null out the array will explicit requested by
// // calling recycle()
// size = 0;
// }
//
// /**
// * Returns {@code true} if any elements where added or set. This will be reset once {@link #recycle()} was called.
// */
// boolean insertSinceRecycled() {
// return insertSinceRecycled;
// }
//
// /**
// * Recycle the array which will clear it and null out all entries in the internal storage.
// */
// public void recycle() {
// for (int i = 0; i < size; i++) {
// array[i] = null;
// }
// clear();
// insertSinceRecycled = false;
// handle.recycle(this);
// }
//
// /**
// * Returns the element on the given index. This operation will not do any range-checks and so is considered unsafe.
// */
// public T getUnsafe(int index) {
// return (T) array[index];
// }
//
// private void checkIndex(int index) {
// if (index >= size) {
// throw new IndexOutOfBoundsException();
// }
// }
//
// private void insert(int index, Object element) {
// array[index] = element;
// insertSinceRecycled = true;
// }
//
// private void expandArray() {
// // double capacity
// int newCapacity = array.length << 1;
//
// if (newCapacity < 0) {
// throw new OutOfMemoryError();
// }
//
// Object[] newArray = new Object[newCapacity];
// System.arraycopy(array, 0, newArray, 0, array.length);
//
// array = newArray;
// }
//
// }
| import java.util.concurrent.TimeUnit;
import io.jpower.kcp.netty.internal.CodecOutputList;
import io.netty.buffer.ByteBuf;
import io.netty.channel.Channel;
import io.netty.channel.ChannelPipeline; | package io.jpower.kcp.netty;
/**
* @author <a href="mailto:szhnet@gmail.com">szh</a>
*/
class Utils {
static int milliSeconds() {
return (int) TimeUnit.NANOSECONDS.toMillis(System.nanoTime());
}
static int itimediff(int later, int earlier) {
return later - earlier;
}
static void fireExceptionAndClose(Channel channel, Throwable t, boolean close) {
channel.pipeline().fireExceptionCaught(t);
if (channel.isActive()) {
Channel.Unsafe unsafe = channel.unsafe();
unsafe.close(unsafe.voidPromise());
}
}
| // Path: kcp-netty/src/main/java/io/jpower/kcp/netty/internal/CodecOutputList.java
// @SuppressWarnings({"unchecked", "rawtypes"})
// public class CodecOutputList<T> extends AbstractList<T> implements RandomAccess {
//
// private static final Recycler<CodecOutputList> RECYCLER = new Recycler<CodecOutputList>() {
// @Override
// protected CodecOutputList newObject(Handle<CodecOutputList> handle) {
// return new CodecOutputList(handle);
// }
// };
//
// public static <T> CodecOutputList<T> newInstance() {
// return RECYCLER.get();
// }
//
// private final Recycler.Handle<CodecOutputList<T>> handle;
// private int size;
// // Size of 16 should be good enough for 99 % of all users.
// private Object[] array = new Object[16];
// private boolean insertSinceRecycled;
//
// private CodecOutputList(Recycler.Handle<CodecOutputList<T>> handle) {
// this.handle = handle;
// }
//
// @Override
// public T get(int index) {
// checkIndex(index);
// return (T) array[index];
// }
//
// @Override
// public int size() {
// return size;
// }
//
// @Override
// public boolean add(Object element) {
// checkNotNull(element, "element");
//
// int newSize = size + 1;
// if (newSize > array.length) {
// expandArray();
// }
// insert(size, element);
// size = newSize;
//
// return true;
// }
//
// @Override
// public T set(int index, Object element) {
// checkNotNull(element, "element");
// checkIndex(index);
//
// Object old = array[index];
// insert(index, element);
// return (T) old;
// }
//
// @Override
// public void add(int index, Object element) {
// checkNotNull(element, "element");
// checkIndex(index);
//
// if (size == array.length) {
// expandArray();
// }
//
// if (index != size - 1) {
// System.arraycopy(array, index, array, index + 1, size - index);
// }
//
// insert(index, element);
// ++size;
// }
//
// @Override
// public T remove(int index) {
// checkIndex(index);
// Object old = array[index];
//
// int len = size - index - 1;
// if (len > 0) {
// System.arraycopy(array, index + 1, array, index, len);
// }
// array[--size] = null;
//
// return (T) old;
// }
//
// @Override
// public void clear() {
// // We only set the size to 0 and not null out the array. Null out the array will explicit requested by
// // calling recycle()
// size = 0;
// }
//
// /**
// * Returns {@code true} if any elements where added or set. This will be reset once {@link #recycle()} was called.
// */
// boolean insertSinceRecycled() {
// return insertSinceRecycled;
// }
//
// /**
// * Recycle the array which will clear it and null out all entries in the internal storage.
// */
// public void recycle() {
// for (int i = 0; i < size; i++) {
// array[i] = null;
// }
// clear();
// insertSinceRecycled = false;
// handle.recycle(this);
// }
//
// /**
// * Returns the element on the given index. This operation will not do any range-checks and so is considered unsafe.
// */
// public T getUnsafe(int index) {
// return (T) array[index];
// }
//
// private void checkIndex(int index) {
// if (index >= size) {
// throw new IndexOutOfBoundsException();
// }
// }
//
// private void insert(int index, Object element) {
// array[index] = element;
// insertSinceRecycled = true;
// }
//
// private void expandArray() {
// // double capacity
// int newCapacity = array.length << 1;
//
// if (newCapacity < 0) {
// throw new OutOfMemoryError();
// }
//
// Object[] newArray = new Object[newCapacity];
// System.arraycopy(array, 0, newArray, 0, array.length);
//
// array = newArray;
// }
//
// }
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/Utils.java
import java.util.concurrent.TimeUnit;
import io.jpower.kcp.netty.internal.CodecOutputList;
import io.netty.buffer.ByteBuf;
import io.netty.channel.Channel;
import io.netty.channel.ChannelPipeline;
package io.jpower.kcp.netty;
/**
* @author <a href="mailto:szhnet@gmail.com">szh</a>
*/
class Utils {
static int milliSeconds() {
return (int) TimeUnit.NANOSECONDS.toMillis(System.nanoTime());
}
static int itimediff(int later, int earlier) {
return later - earlier;
}
static void fireExceptionAndClose(Channel channel, Throwable t, boolean close) {
channel.pipeline().fireExceptionCaught(t);
if (channel.isActive()) {
Channel.Unsafe unsafe = channel.unsafe();
unsafe.close(unsafe.voidPromise());
}
}
| static void fireChannelRead(Channel ch, CodecOutputList<ByteBuf> bufList) { |
szhnet/kcp-netty | kcp-example/src/main/java/io/jpower/kcp/example/rtt/KcpRttServerHandler.java | // Path: kcp-example/src/main/java/io/jpower/kcp/example/echo/EchoServerHandler.java
// public class EchoServerHandler extends ChannelInboundHandlerAdapter {
//
// @Override
// public void channelActive(ChannelHandlerContext ctx) throws Exception {
// UkcpChannel kcpCh = (UkcpChannel) ctx.channel();
// kcpCh.conv(EchoServer.CONV);
// }
//
// @Override
// public void channelRead(ChannelHandlerContext ctx, Object msg) {
// ctx.write(msg);
// }
//
// @Override
// public void channelReadComplete(ChannelHandlerContext ctx) {
// ctx.flush();
// }
//
// @Override
// public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
// // Close the connection when an exception is raised.
// cause.printStackTrace();
// ctx.close();
// }
//
// }
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannel.java
// public interface UkcpChannel extends Channel {
//
// int conv();
//
// @Override
// UkcpChannelConfig config();
//
// UkcpChannel conv(int conv);
//
// @Override
// InetSocketAddress localAddress();
//
// @Override
// InetSocketAddress remoteAddress();
//
// }
| import io.jpower.kcp.example.echo.EchoServerHandler;
import io.jpower.kcp.netty.UkcpChannel;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory; | package io.jpower.kcp.example.rtt;
/**
* @author <a href="mailto:szhnet@gmail.com">szh</a>
*/
public class KcpRttServerHandler extends ChannelInboundHandlerAdapter {
private static Logger log = LoggerFactory.getLogger(EchoServerHandler.class);
@Override
public void channelActive(ChannelHandlerContext ctx) throws Exception { | // Path: kcp-example/src/main/java/io/jpower/kcp/example/echo/EchoServerHandler.java
// public class EchoServerHandler extends ChannelInboundHandlerAdapter {
//
// @Override
// public void channelActive(ChannelHandlerContext ctx) throws Exception {
// UkcpChannel kcpCh = (UkcpChannel) ctx.channel();
// kcpCh.conv(EchoServer.CONV);
// }
//
// @Override
// public void channelRead(ChannelHandlerContext ctx, Object msg) {
// ctx.write(msg);
// }
//
// @Override
// public void channelReadComplete(ChannelHandlerContext ctx) {
// ctx.flush();
// }
//
// @Override
// public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
// // Close the connection when an exception is raised.
// cause.printStackTrace();
// ctx.close();
// }
//
// }
//
// Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannel.java
// public interface UkcpChannel extends Channel {
//
// int conv();
//
// @Override
// UkcpChannelConfig config();
//
// UkcpChannel conv(int conv);
//
// @Override
// InetSocketAddress localAddress();
//
// @Override
// InetSocketAddress remoteAddress();
//
// }
// Path: kcp-example/src/main/java/io/jpower/kcp/example/rtt/KcpRttServerHandler.java
import io.jpower.kcp.example.echo.EchoServerHandler;
import io.jpower.kcp.netty.UkcpChannel;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
package io.jpower.kcp.example.rtt;
/**
* @author <a href="mailto:szhnet@gmail.com">szh</a>
*/
public class KcpRttServerHandler extends ChannelInboundHandlerAdapter {
private static Logger log = LoggerFactory.getLogger(EchoServerHandler.class);
@Override
public void channelActive(ChannelHandlerContext ctx) throws Exception { | UkcpChannel kcpCh = (UkcpChannel) ctx.channel(); |
szhnet/kcp-netty | kcp-example/src/main/java/io/jpower/kcp/example/echo/EchoServerHandler.java | // Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannel.java
// public interface UkcpChannel extends Channel {
//
// int conv();
//
// @Override
// UkcpChannelConfig config();
//
// UkcpChannel conv(int conv);
//
// @Override
// InetSocketAddress localAddress();
//
// @Override
// InetSocketAddress remoteAddress();
//
// }
| import io.jpower.kcp.netty.UkcpChannel;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter; | package io.jpower.kcp.example.echo;
/**
* Handler implementation for the echo server.
*
* @author <a href="mailto:szhnet@gmail.com">szh</a>
*/
public class EchoServerHandler extends ChannelInboundHandlerAdapter {
@Override
public void channelActive(ChannelHandlerContext ctx) throws Exception { | // Path: kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpChannel.java
// public interface UkcpChannel extends Channel {
//
// int conv();
//
// @Override
// UkcpChannelConfig config();
//
// UkcpChannel conv(int conv);
//
// @Override
// InetSocketAddress localAddress();
//
// @Override
// InetSocketAddress remoteAddress();
//
// }
// Path: kcp-example/src/main/java/io/jpower/kcp/example/echo/EchoServerHandler.java
import io.jpower.kcp.netty.UkcpChannel;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
package io.jpower.kcp.example.echo;
/**
* Handler implementation for the echo server.
*
* @author <a href="mailto:szhnet@gmail.com">szh</a>
*/
public class EchoServerHandler extends ChannelInboundHandlerAdapter {
@Override
public void channelActive(ChannelHandlerContext ctx) throws Exception { | UkcpChannel kcpCh = (UkcpChannel) ctx.channel(); |
sky-uk/cqlmigrate | src/main/java/uk/sky/cqlmigrate/CassandraLockingMechanism.java | // Path: src/main/java/uk/sky/cqlmigrate/exception/CannotAcquireLockException.java
// public class CannotAcquireLockException extends LockException {
//
// public CannotAcquireLockException(String message) {
// super(message);
// }
//
// public CannotAcquireLockException(String message, Throwable cause) {
// super(message, cause);
// }
// }
//
// Path: src/main/java/uk/sky/cqlmigrate/exception/CannotReleaseLockException.java
// public class CannotReleaseLockException extends LockException {
//
// public CannotReleaseLockException(String message, Throwable cause) {
// super(message, cause);
// }
//
// public CannotReleaseLockException(String message) {
// super(message);
// }
// }
| import com.datastax.oss.driver.api.core.ConsistencyLevel;
import com.datastax.oss.driver.api.core.CqlSession;
import com.datastax.oss.driver.api.core.DriverException;
import com.datastax.oss.driver.api.core.cql.PreparedStatement;
import com.datastax.oss.driver.api.core.cql.ResultSet;
import com.datastax.oss.driver.api.core.cql.Row;
import com.datastax.oss.driver.api.core.cql.SimpleStatement;
import com.datastax.oss.driver.api.core.servererrors.WriteTimeoutException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import uk.sky.cqlmigrate.exception.CannotAcquireLockException;
import uk.sky.cqlmigrate.exception.CannotReleaseLockException;
import static java.lang.String.format; | package uk.sky.cqlmigrate;
class CassandraLockingMechanism extends LockingMechanism {
private static final Logger log = LoggerFactory.getLogger(CassandraLockingMechanism.class);
private final CqlSession session;
private final ConsistencyLevel consistencyLevel;
private final String lockKeyspace;
private PreparedStatement selectLockQuery;
private PreparedStatement insertLockQuery;
private PreparedStatement deleteLockQuery;
private boolean isRetryAfterWriteTimeout;
public CassandraLockingMechanism(CqlSession session, String keyspace, ConsistencyLevel consistencyLevel, String lockKeyspace) {
super(keyspace + ".schema_migration");
this.session = session;
this.consistencyLevel = consistencyLevel;
this.lockKeyspace = lockKeyspace;
}
/**
* Prepares queries for acquiring and releasing lock.
*
* @throws CannotAcquireLockException if any DriverException thrown while executing queries.
*/
@Override | // Path: src/main/java/uk/sky/cqlmigrate/exception/CannotAcquireLockException.java
// public class CannotAcquireLockException extends LockException {
//
// public CannotAcquireLockException(String message) {
// super(message);
// }
//
// public CannotAcquireLockException(String message, Throwable cause) {
// super(message, cause);
// }
// }
//
// Path: src/main/java/uk/sky/cqlmigrate/exception/CannotReleaseLockException.java
// public class CannotReleaseLockException extends LockException {
//
// public CannotReleaseLockException(String message, Throwable cause) {
// super(message, cause);
// }
//
// public CannotReleaseLockException(String message) {
// super(message);
// }
// }
// Path: src/main/java/uk/sky/cqlmigrate/CassandraLockingMechanism.java
import com.datastax.oss.driver.api.core.ConsistencyLevel;
import com.datastax.oss.driver.api.core.CqlSession;
import com.datastax.oss.driver.api.core.DriverException;
import com.datastax.oss.driver.api.core.cql.PreparedStatement;
import com.datastax.oss.driver.api.core.cql.ResultSet;
import com.datastax.oss.driver.api.core.cql.Row;
import com.datastax.oss.driver.api.core.cql.SimpleStatement;
import com.datastax.oss.driver.api.core.servererrors.WriteTimeoutException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import uk.sky.cqlmigrate.exception.CannotAcquireLockException;
import uk.sky.cqlmigrate.exception.CannotReleaseLockException;
import static java.lang.String.format;
package uk.sky.cqlmigrate;
class CassandraLockingMechanism extends LockingMechanism {
private static final Logger log = LoggerFactory.getLogger(CassandraLockingMechanism.class);
private final CqlSession session;
private final ConsistencyLevel consistencyLevel;
private final String lockKeyspace;
private PreparedStatement selectLockQuery;
private PreparedStatement insertLockQuery;
private PreparedStatement deleteLockQuery;
private boolean isRetryAfterWriteTimeout;
public CassandraLockingMechanism(CqlSession session, String keyspace, ConsistencyLevel consistencyLevel, String lockKeyspace) {
super(keyspace + ".schema_migration");
this.session = session;
this.consistencyLevel = consistencyLevel;
this.lockKeyspace = lockKeyspace;
}
/**
* Prepares queries for acquiring and releasing lock.
*
* @throws CannotAcquireLockException if any DriverException thrown while executing queries.
*/
@Override | public void init() throws CannotAcquireLockException { |
sky-uk/cqlmigrate | src/main/java/uk/sky/cqlmigrate/CassandraLockingMechanism.java | // Path: src/main/java/uk/sky/cqlmigrate/exception/CannotAcquireLockException.java
// public class CannotAcquireLockException extends LockException {
//
// public CannotAcquireLockException(String message) {
// super(message);
// }
//
// public CannotAcquireLockException(String message, Throwable cause) {
// super(message, cause);
// }
// }
//
// Path: src/main/java/uk/sky/cqlmigrate/exception/CannotReleaseLockException.java
// public class CannotReleaseLockException extends LockException {
//
// public CannotReleaseLockException(String message, Throwable cause) {
// super(message, cause);
// }
//
// public CannotReleaseLockException(String message) {
// super(message);
// }
// }
| import com.datastax.oss.driver.api.core.ConsistencyLevel;
import com.datastax.oss.driver.api.core.CqlSession;
import com.datastax.oss.driver.api.core.DriverException;
import com.datastax.oss.driver.api.core.cql.PreparedStatement;
import com.datastax.oss.driver.api.core.cql.ResultSet;
import com.datastax.oss.driver.api.core.cql.Row;
import com.datastax.oss.driver.api.core.cql.SimpleStatement;
import com.datastax.oss.driver.api.core.servererrors.WriteTimeoutException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import uk.sky.cqlmigrate.exception.CannotAcquireLockException;
import uk.sky.cqlmigrate.exception.CannotReleaseLockException;
import static java.lang.String.format; | log.info("Lock currently held by {}", currentLock);
return false;
}
} catch (WriteTimeoutException wte) {
log.warn("Query to acquire lock for {} failed to execute: {}", clientId, wte.getMessage());
return false;
} catch (DriverException de) {
throw new CannotAcquireLockException(format("Query to acquire lock %s for client %s failed to execute", lockName, clientId), de);
}
}
/**
* Verify that a select of the locks completes successfully
*
* @throws DriverException propagated from the session.execute() call.
*/
private void verifyClusterIsHealthy() {
session.execute(selectLockQuery.bind());
}
/**
* {@inheritDoc}
* <p>
* Deletes lock from locks table.
* If a WriteTimeoutException has previously been thrown this
* will check if the lock did get successfully deleted.
*
* @throws CannotReleaseLockException if any DriverException thrown while executing queries.
*/
@Override | // Path: src/main/java/uk/sky/cqlmigrate/exception/CannotAcquireLockException.java
// public class CannotAcquireLockException extends LockException {
//
// public CannotAcquireLockException(String message) {
// super(message);
// }
//
// public CannotAcquireLockException(String message, Throwable cause) {
// super(message, cause);
// }
// }
//
// Path: src/main/java/uk/sky/cqlmigrate/exception/CannotReleaseLockException.java
// public class CannotReleaseLockException extends LockException {
//
// public CannotReleaseLockException(String message, Throwable cause) {
// super(message, cause);
// }
//
// public CannotReleaseLockException(String message) {
// super(message);
// }
// }
// Path: src/main/java/uk/sky/cqlmigrate/CassandraLockingMechanism.java
import com.datastax.oss.driver.api.core.ConsistencyLevel;
import com.datastax.oss.driver.api.core.CqlSession;
import com.datastax.oss.driver.api.core.DriverException;
import com.datastax.oss.driver.api.core.cql.PreparedStatement;
import com.datastax.oss.driver.api.core.cql.ResultSet;
import com.datastax.oss.driver.api.core.cql.Row;
import com.datastax.oss.driver.api.core.cql.SimpleStatement;
import com.datastax.oss.driver.api.core.servererrors.WriteTimeoutException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import uk.sky.cqlmigrate.exception.CannotAcquireLockException;
import uk.sky.cqlmigrate.exception.CannotReleaseLockException;
import static java.lang.String.format;
log.info("Lock currently held by {}", currentLock);
return false;
}
} catch (WriteTimeoutException wte) {
log.warn("Query to acquire lock for {} failed to execute: {}", clientId, wte.getMessage());
return false;
} catch (DriverException de) {
throw new CannotAcquireLockException(format("Query to acquire lock %s for client %s failed to execute", lockName, clientId), de);
}
}
/**
* Verify that a select of the locks completes successfully
*
* @throws DriverException propagated from the session.execute() call.
*/
private void verifyClusterIsHealthy() {
session.execute(selectLockQuery.bind());
}
/**
* {@inheritDoc}
* <p>
* Deletes lock from locks table.
* If a WriteTimeoutException has previously been thrown this
* will check if the lock did get successfully deleted.
*
* @throws CannotReleaseLockException if any DriverException thrown while executing queries.
*/
@Override | public boolean release(String clientId) throws CannotReleaseLockException { |
sky-uk/cqlmigrate | src/test/java/uk/sky/cqlmigrate/ChecksumCalculatorTest.java | // Path: src/main/java/uk/sky/cqlmigrate/ChecksumCalculator.java
// static String calculateChecksum(Path path) {
// try {
// final MessageDigest digest = MessageDigest.getInstance("SHA-1");
// final byte[] hash = digest.digest(Files.readAllBytes(path));
// return bytesToHex(hash);
// } catch (IOException | NoSuchAlgorithmException e) {
// throw new RuntimeException(e);
// }
// }
| import org.assertj.core.api.Assertions;
import org.junit.Test;
import java.nio.file.NoSuchFileException;
import java.nio.file.Path;
import java.nio.file.Paths;
import static org.assertj.core.api.Assertions.assertThat;
import static uk.sky.cqlmigrate.ChecksumCalculator.calculateChecksum; | package uk.sky.cqlmigrate;
public class ChecksumCalculatorTest {
@Test
public void calculateChecksumThrowsWhenFileDoesNotExist() throws Exception {
// given
Path path = Paths.get("/non-existant-file.cql");
// When | // Path: src/main/java/uk/sky/cqlmigrate/ChecksumCalculator.java
// static String calculateChecksum(Path path) {
// try {
// final MessageDigest digest = MessageDigest.getInstance("SHA-1");
// final byte[] hash = digest.digest(Files.readAllBytes(path));
// return bytesToHex(hash);
// } catch (IOException | NoSuchAlgorithmException e) {
// throw new RuntimeException(e);
// }
// }
// Path: src/test/java/uk/sky/cqlmigrate/ChecksumCalculatorTest.java
import org.assertj.core.api.Assertions;
import org.junit.Test;
import java.nio.file.NoSuchFileException;
import java.nio.file.Path;
import java.nio.file.Paths;
import static org.assertj.core.api.Assertions.assertThat;
import static uk.sky.cqlmigrate.ChecksumCalculator.calculateChecksum;
package uk.sky.cqlmigrate;
public class ChecksumCalculatorTest {
@Test
public void calculateChecksumThrowsWhenFileDoesNotExist() throws Exception {
// given
Path path = Paths.get("/non-existant-file.cql");
// When | RuntimeException runtimeException = Assertions.catchThrowableOfType(() -> calculateChecksum(path), RuntimeException.class); |
sky-uk/cqlmigrate | src/main/java/uk/sky/cqlmigrate/LockingMechanism.java | // Path: src/main/java/uk/sky/cqlmigrate/exception/CannotAcquireLockException.java
// public class CannotAcquireLockException extends LockException {
//
// public CannotAcquireLockException(String message) {
// super(message);
// }
//
// public CannotAcquireLockException(String message, Throwable cause) {
// super(message, cause);
// }
// }
//
// Path: src/main/java/uk/sky/cqlmigrate/exception/CannotReleaseLockException.java
// public class CannotReleaseLockException extends LockException {
//
// public CannotReleaseLockException(String message, Throwable cause) {
// super(message, cause);
// }
//
// public CannotReleaseLockException(String message) {
// super(message);
// }
// }
| import uk.sky.cqlmigrate.exception.CannotAcquireLockException;
import uk.sky.cqlmigrate.exception.CannotReleaseLockException; | package uk.sky.cqlmigrate;
abstract class LockingMechanism {
protected final String lockName;
public LockingMechanism(String lockName) {
this.lockName = lockName;
}
public void init() {
}
/**
* Returns true if successfully acquired lock.
*
* @param clientId client to acquire the lock for
* @return if the lock was successfully acquired. A false value means that the lock was not acquired,
* or that the result of the operation is unknown.
* @throws CannotAcquireLockException if any fatal failure occurs when trying to acquire lock.
*/ | // Path: src/main/java/uk/sky/cqlmigrate/exception/CannotAcquireLockException.java
// public class CannotAcquireLockException extends LockException {
//
// public CannotAcquireLockException(String message) {
// super(message);
// }
//
// public CannotAcquireLockException(String message, Throwable cause) {
// super(message, cause);
// }
// }
//
// Path: src/main/java/uk/sky/cqlmigrate/exception/CannotReleaseLockException.java
// public class CannotReleaseLockException extends LockException {
//
// public CannotReleaseLockException(String message, Throwable cause) {
// super(message, cause);
// }
//
// public CannotReleaseLockException(String message) {
// super(message);
// }
// }
// Path: src/main/java/uk/sky/cqlmigrate/LockingMechanism.java
import uk.sky.cqlmigrate.exception.CannotAcquireLockException;
import uk.sky.cqlmigrate.exception.CannotReleaseLockException;
package uk.sky.cqlmigrate;
abstract class LockingMechanism {
protected final String lockName;
public LockingMechanism(String lockName) {
this.lockName = lockName;
}
public void init() {
}
/**
* Returns true if successfully acquired lock.
*
* @param clientId client to acquire the lock for
* @return if the lock was successfully acquired. A false value means that the lock was not acquired,
* or that the result of the operation is unknown.
* @throws CannotAcquireLockException if any fatal failure occurs when trying to acquire lock.
*/ | abstract public boolean acquire(String clientId) throws CannotAcquireLockException; |
sky-uk/cqlmigrate | src/main/java/uk/sky/cqlmigrate/LockingMechanism.java | // Path: src/main/java/uk/sky/cqlmigrate/exception/CannotAcquireLockException.java
// public class CannotAcquireLockException extends LockException {
//
// public CannotAcquireLockException(String message) {
// super(message);
// }
//
// public CannotAcquireLockException(String message, Throwable cause) {
// super(message, cause);
// }
// }
//
// Path: src/main/java/uk/sky/cqlmigrate/exception/CannotReleaseLockException.java
// public class CannotReleaseLockException extends LockException {
//
// public CannotReleaseLockException(String message, Throwable cause) {
// super(message, cause);
// }
//
// public CannotReleaseLockException(String message) {
// super(message);
// }
// }
| import uk.sky.cqlmigrate.exception.CannotAcquireLockException;
import uk.sky.cqlmigrate.exception.CannotReleaseLockException; | package uk.sky.cqlmigrate;
abstract class LockingMechanism {
protected final String lockName;
public LockingMechanism(String lockName) {
this.lockName = lockName;
}
public void init() {
}
/**
* Returns true if successfully acquired lock.
*
* @param clientId client to acquire the lock for
* @return if the lock was successfully acquired. A false value means that the lock was not acquired,
* or that the result of the operation is unknown.
* @throws CannotAcquireLockException if any fatal failure occurs when trying to acquire lock.
*/
abstract public boolean acquire(String clientId) throws CannotAcquireLockException;
/**
* @param clientId client to release the lock for
* @return true if the lock was successfully released. A false value means that the lock was not released,
* or that the result of the operation is unknown.
* @throws CannotReleaseLockException if any fatal failure occurs when trying to release lock.
*/ | // Path: src/main/java/uk/sky/cqlmigrate/exception/CannotAcquireLockException.java
// public class CannotAcquireLockException extends LockException {
//
// public CannotAcquireLockException(String message) {
// super(message);
// }
//
// public CannotAcquireLockException(String message, Throwable cause) {
// super(message, cause);
// }
// }
//
// Path: src/main/java/uk/sky/cqlmigrate/exception/CannotReleaseLockException.java
// public class CannotReleaseLockException extends LockException {
//
// public CannotReleaseLockException(String message, Throwable cause) {
// super(message, cause);
// }
//
// public CannotReleaseLockException(String message) {
// super(message);
// }
// }
// Path: src/main/java/uk/sky/cqlmigrate/LockingMechanism.java
import uk.sky.cqlmigrate.exception.CannotAcquireLockException;
import uk.sky.cqlmigrate.exception.CannotReleaseLockException;
package uk.sky.cqlmigrate;
abstract class LockingMechanism {
protected final String lockName;
public LockingMechanism(String lockName) {
this.lockName = lockName;
}
public void init() {
}
/**
* Returns true if successfully acquired lock.
*
* @param clientId client to acquire the lock for
* @return if the lock was successfully acquired. A false value means that the lock was not acquired,
* or that the result of the operation is unknown.
* @throws CannotAcquireLockException if any fatal failure occurs when trying to acquire lock.
*/
abstract public boolean acquire(String clientId) throws CannotAcquireLockException;
/**
* @param clientId client to release the lock for
* @return true if the lock was successfully released. A false value means that the lock was not released,
* or that the result of the operation is unknown.
* @throws CannotReleaseLockException if any fatal failure occurs when trying to release lock.
*/ | abstract public boolean release(String clientId) throws CannotReleaseLockException; |
sky-uk/cqlmigrate | src/test/java/uk/sky/cqlmigrate/CqlMigratorImplTest.java | // Path: src/main/java/uk/sky/cqlmigrate/exception/CannotAcquireLockException.java
// public class CannotAcquireLockException extends LockException {
//
// public CannotAcquireLockException(String message) {
// super(message);
// }
//
// public CannotAcquireLockException(String message, Throwable cause) {
// super(message, cause);
// }
// }
| import com.datastax.oss.driver.api.core.ConsistencyLevel;
import com.datastax.oss.driver.api.core.CqlSession;
import com.datastax.oss.driver.api.core.cql.ResultSet;
import com.datastax.oss.driver.api.core.cql.Row;
import com.datastax.oss.driver.api.core.cql.SimpleStatement;
import com.datastax.oss.driver.api.core.metadata.schema.KeyspaceMetadata;
import com.datastax.oss.driver.api.core.metadata.schema.TableMetadata;
import com.datastax.oss.driver.api.core.servererrors.SyntaxError;
import com.google.common.util.concurrent.Uninterruptibles;
import org.apache.cassandra.exceptions.ConfigurationException;
import org.apache.thrift.transport.TTransportException;
import org.cassandraunit.utils.EmbeddedCassandraServerHelper;
import org.junit.*;
import uk.sky.cqlmigrate.exception.CannotAcquireLockException;
import java.io.IOException;
import java.net.URISyntaxException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.time.Instant;
import java.time.Duration;
import java.util.*;
import java.util.concurrent.*;
import static com.datastax.oss.driver.api.core.cql.SimpleStatement.newInstance;
import static java.time.Duration.ofMillis;
import static java.util.Arrays.asList;
import static java.util.Collections.singletonList;
import static org.assertj.core.api.Assertions.*;
import static org.junit.Assert.fail; | //when
MIGRATOR.migrate(CASSANDRA_HOSTS, LOCAL_DC, binaryPort, username, password, TEST_KEYSPACE, cqlPaths);
//then
assertThat(session.getMetadata().getKeyspace(TEST_KEYSPACE)).isNotEmpty();
}
@Test(timeout = 5000)
public void shouldThrowCannotAcquireLockExceptionIfLockCannotBeAcquiredAfterTimeout() throws Exception {
//given
CqlMigrator migrator = new CqlMigratorImpl(CqlMigratorConfig.builder()
.withLockConfig(CassandraLockConfig.builder().withPollingInterval(ofMillis(50)).withTimeout(ofMillis(300)).build())
.withReadConsistencyLevel(ConsistencyLevel.ALL)
.withWriteConsistencyLevel(ConsistencyLevel.ALL)
.build(), new SessionContextFactory());
String client = UUID.randomUUID().toString();
session.execute(newInstance("INSERT INTO cqlmigrate.locks (name, client) VALUES (?, ?)", LOCK_NAME, client));
Collection<Path> cqlPaths = singletonList(getResourcePath("cql_bootstrap"));
//when
Future<?> future = executorService.submit(() -> migrator.migrate(
CASSANDRA_HOSTS, LOCAL_DC, binaryPort, username, password, TEST_KEYSPACE, cqlPaths));
Thread.sleep(310);
Throwable throwable = catchThrowable(future::get);
//then
assertThat(throwable).isInstanceOf(ExecutionException.class); | // Path: src/main/java/uk/sky/cqlmigrate/exception/CannotAcquireLockException.java
// public class CannotAcquireLockException extends LockException {
//
// public CannotAcquireLockException(String message) {
// super(message);
// }
//
// public CannotAcquireLockException(String message, Throwable cause) {
// super(message, cause);
// }
// }
// Path: src/test/java/uk/sky/cqlmigrate/CqlMigratorImplTest.java
import com.datastax.oss.driver.api.core.ConsistencyLevel;
import com.datastax.oss.driver.api.core.CqlSession;
import com.datastax.oss.driver.api.core.cql.ResultSet;
import com.datastax.oss.driver.api.core.cql.Row;
import com.datastax.oss.driver.api.core.cql.SimpleStatement;
import com.datastax.oss.driver.api.core.metadata.schema.KeyspaceMetadata;
import com.datastax.oss.driver.api.core.metadata.schema.TableMetadata;
import com.datastax.oss.driver.api.core.servererrors.SyntaxError;
import com.google.common.util.concurrent.Uninterruptibles;
import org.apache.cassandra.exceptions.ConfigurationException;
import org.apache.thrift.transport.TTransportException;
import org.cassandraunit.utils.EmbeddedCassandraServerHelper;
import org.junit.*;
import uk.sky.cqlmigrate.exception.CannotAcquireLockException;
import java.io.IOException;
import java.net.URISyntaxException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.time.Instant;
import java.time.Duration;
import java.util.*;
import java.util.concurrent.*;
import static com.datastax.oss.driver.api.core.cql.SimpleStatement.newInstance;
import static java.time.Duration.ofMillis;
import static java.util.Arrays.asList;
import static java.util.Collections.singletonList;
import static org.assertj.core.api.Assertions.*;
import static org.junit.Assert.fail;
//when
MIGRATOR.migrate(CASSANDRA_HOSTS, LOCAL_DC, binaryPort, username, password, TEST_KEYSPACE, cqlPaths);
//then
assertThat(session.getMetadata().getKeyspace(TEST_KEYSPACE)).isNotEmpty();
}
@Test(timeout = 5000)
public void shouldThrowCannotAcquireLockExceptionIfLockCannotBeAcquiredAfterTimeout() throws Exception {
//given
CqlMigrator migrator = new CqlMigratorImpl(CqlMigratorConfig.builder()
.withLockConfig(CassandraLockConfig.builder().withPollingInterval(ofMillis(50)).withTimeout(ofMillis(300)).build())
.withReadConsistencyLevel(ConsistencyLevel.ALL)
.withWriteConsistencyLevel(ConsistencyLevel.ALL)
.build(), new SessionContextFactory());
String client = UUID.randomUUID().toString();
session.execute(newInstance("INSERT INTO cqlmigrate.locks (name, client) VALUES (?, ?)", LOCK_NAME, client));
Collection<Path> cqlPaths = singletonList(getResourcePath("cql_bootstrap"));
//when
Future<?> future = executorService.submit(() -> migrator.migrate(
CASSANDRA_HOSTS, LOCAL_DC, binaryPort, username, password, TEST_KEYSPACE, cqlPaths));
Thread.sleep(310);
Throwable throwable = catchThrowable(future::get);
//then
assertThat(throwable).isInstanceOf(ExecutionException.class); | assertThat(throwable.getCause()).isInstanceOf(CannotAcquireLockException.class); |
sky-uk/cqlmigrate | src/main/java/uk/sky/cqlmigrate/Lock.java | // Path: src/main/java/uk/sky/cqlmigrate/exception/CannotAcquireLockException.java
// public class CannotAcquireLockException extends LockException {
//
// public CannotAcquireLockException(String message) {
// super(message);
// }
//
// public CannotAcquireLockException(String message, Throwable cause) {
// super(message, cause);
// }
// }
//
// Path: src/main/java/uk/sky/cqlmigrate/exception/CannotReleaseLockException.java
// public class CannotReleaseLockException extends LockException {
//
// public CannotReleaseLockException(String message, Throwable cause) {
// super(message, cause);
// }
//
// public CannotReleaseLockException(String message) {
// super(message);
// }
// }
| import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import uk.sky.cqlmigrate.exception.CannotAcquireLockException;
import uk.sky.cqlmigrate.exception.CannotReleaseLockException;
import java.util.concurrent.TimeoutException; | package uk.sky.cqlmigrate;
/**
* Each instance attempts to acquire the lock.
*/
class Lock {
private static final Logger log = LoggerFactory.getLogger(Lock.class);
private final LockingMechanism lockingMechanism;
private final LockConfig lockConfig;
/**
*
* @param lockingMechanism {@code LockingMechanism} to use to acquire the lock
* @param lockConfig {@code LockConfig} for configuring the lock polling interval, timeout and client id
*/
Lock(LockingMechanism lockingMechanism, LockConfig lockConfig) {
this.lockingMechanism = lockingMechanism;
this.lockConfig = lockConfig;
}
/**
* If the lock is successfully acquired, the method will return, otherwise
* this will wait until the lock has been released. If a lock cannot
* be acquired within the configured timeout interval, an exception is thrown.
*
* @throws CannotAcquireLockException if this cannot acquire lock within the specified time interval or locking mechanism fails
*/ | // Path: src/main/java/uk/sky/cqlmigrate/exception/CannotAcquireLockException.java
// public class CannotAcquireLockException extends LockException {
//
// public CannotAcquireLockException(String message) {
// super(message);
// }
//
// public CannotAcquireLockException(String message, Throwable cause) {
// super(message, cause);
// }
// }
//
// Path: src/main/java/uk/sky/cqlmigrate/exception/CannotReleaseLockException.java
// public class CannotReleaseLockException extends LockException {
//
// public CannotReleaseLockException(String message, Throwable cause) {
// super(message, cause);
// }
//
// public CannotReleaseLockException(String message) {
// super(message);
// }
// }
// Path: src/main/java/uk/sky/cqlmigrate/Lock.java
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import uk.sky.cqlmigrate.exception.CannotAcquireLockException;
import uk.sky.cqlmigrate.exception.CannotReleaseLockException;
import java.util.concurrent.TimeoutException;
package uk.sky.cqlmigrate;
/**
* Each instance attempts to acquire the lock.
*/
class Lock {
private static final Logger log = LoggerFactory.getLogger(Lock.class);
private final LockingMechanism lockingMechanism;
private final LockConfig lockConfig;
/**
*
* @param lockingMechanism {@code LockingMechanism} to use to acquire the lock
* @param lockConfig {@code LockConfig} for configuring the lock polling interval, timeout and client id
*/
Lock(LockingMechanism lockingMechanism, LockConfig lockConfig) {
this.lockingMechanism = lockingMechanism;
this.lockConfig = lockConfig;
}
/**
* If the lock is successfully acquired, the method will return, otherwise
* this will wait until the lock has been released. If a lock cannot
* be acquired within the configured timeout interval, an exception is thrown.
*
* @throws CannotAcquireLockException if this cannot acquire lock within the specified time interval or locking mechanism fails
*/ | public void lock() throws CannotAcquireLockException { |
sky-uk/cqlmigrate | src/main/java/uk/sky/cqlmigrate/Lock.java | // Path: src/main/java/uk/sky/cqlmigrate/exception/CannotAcquireLockException.java
// public class CannotAcquireLockException extends LockException {
//
// public CannotAcquireLockException(String message) {
// super(message);
// }
//
// public CannotAcquireLockException(String message, Throwable cause) {
// super(message, cause);
// }
// }
//
// Path: src/main/java/uk/sky/cqlmigrate/exception/CannotReleaseLockException.java
// public class CannotReleaseLockException extends LockException {
//
// public CannotReleaseLockException(String message, Throwable cause) {
// super(message, cause);
// }
//
// public CannotReleaseLockException(String message) {
// super(message);
// }
// }
| import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import uk.sky.cqlmigrate.exception.CannotAcquireLockException;
import uk.sky.cqlmigrate.exception.CannotReleaseLockException;
import java.util.concurrent.TimeoutException; | package uk.sky.cqlmigrate;
/**
* Each instance attempts to acquire the lock.
*/
class Lock {
private static final Logger log = LoggerFactory.getLogger(Lock.class);
private final LockingMechanism lockingMechanism;
private final LockConfig lockConfig;
/**
*
* @param lockingMechanism {@code LockingMechanism} to use to acquire the lock
* @param lockConfig {@code LockConfig} for configuring the lock polling interval, timeout and client id
*/
Lock(LockingMechanism lockingMechanism, LockConfig lockConfig) {
this.lockingMechanism = lockingMechanism;
this.lockConfig = lockConfig;
}
/**
* If the lock is successfully acquired, the method will return, otherwise
* this will wait until the lock has been released. If a lock cannot
* be acquired within the configured timeout interval, an exception is thrown.
*
* @throws CannotAcquireLockException if this cannot acquire lock within the specified time interval or locking mechanism fails
*/
public void lock() throws CannotAcquireLockException {
lockingMechanism.init();
String lockName = lockingMechanism.getLockName();
String clientId = lockConfig.getClientId();
try {
log.info("Attempting to acquire lock for '{}', using client id '{}'", lockName, lockConfig.getClientId());
RetryTask.attempt(() -> lockingMechanism.acquire(clientId))
.withTimeout(lockConfig.getTimeout())
.withPollingInterval(lockConfig.getPollingInterval())
.untilSuccess();
} catch (TimeoutException te) {
log.warn("Unable to acquire lock for {}", lockConfig.getClientId(), te);
throw new CannotAcquireLockException("Lock currently in use", te);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new CannotAcquireLockException(String.format("Polling to acquire lock %s for client %s was interrupted", lockName, lockConfig.getClientId()), e);
}
}
/**
* Will release the lock using the locking mechanism. If a lock cannot
* be released within the configured timeout interval, an exception is thrown.
*
* @param migrationFailed true if migration failed, false otherwise
* @throws CannotReleaseLockException if this cannot release lock within the specified time interval or locking mechanism fails
*/ | // Path: src/main/java/uk/sky/cqlmigrate/exception/CannotAcquireLockException.java
// public class CannotAcquireLockException extends LockException {
//
// public CannotAcquireLockException(String message) {
// super(message);
// }
//
// public CannotAcquireLockException(String message, Throwable cause) {
// super(message, cause);
// }
// }
//
// Path: src/main/java/uk/sky/cqlmigrate/exception/CannotReleaseLockException.java
// public class CannotReleaseLockException extends LockException {
//
// public CannotReleaseLockException(String message, Throwable cause) {
// super(message, cause);
// }
//
// public CannotReleaseLockException(String message) {
// super(message);
// }
// }
// Path: src/main/java/uk/sky/cqlmigrate/Lock.java
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import uk.sky.cqlmigrate.exception.CannotAcquireLockException;
import uk.sky.cqlmigrate.exception.CannotReleaseLockException;
import java.util.concurrent.TimeoutException;
package uk.sky.cqlmigrate;
/**
* Each instance attempts to acquire the lock.
*/
class Lock {
private static final Logger log = LoggerFactory.getLogger(Lock.class);
private final LockingMechanism lockingMechanism;
private final LockConfig lockConfig;
/**
*
* @param lockingMechanism {@code LockingMechanism} to use to acquire the lock
* @param lockConfig {@code LockConfig} for configuring the lock polling interval, timeout and client id
*/
Lock(LockingMechanism lockingMechanism, LockConfig lockConfig) {
this.lockingMechanism = lockingMechanism;
this.lockConfig = lockConfig;
}
/**
* If the lock is successfully acquired, the method will return, otherwise
* this will wait until the lock has been released. If a lock cannot
* be acquired within the configured timeout interval, an exception is thrown.
*
* @throws CannotAcquireLockException if this cannot acquire lock within the specified time interval or locking mechanism fails
*/
public void lock() throws CannotAcquireLockException {
lockingMechanism.init();
String lockName = lockingMechanism.getLockName();
String clientId = lockConfig.getClientId();
try {
log.info("Attempting to acquire lock for '{}', using client id '{}'", lockName, lockConfig.getClientId());
RetryTask.attempt(() -> lockingMechanism.acquire(clientId))
.withTimeout(lockConfig.getTimeout())
.withPollingInterval(lockConfig.getPollingInterval())
.untilSuccess();
} catch (TimeoutException te) {
log.warn("Unable to acquire lock for {}", lockConfig.getClientId(), te);
throw new CannotAcquireLockException("Lock currently in use", te);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new CannotAcquireLockException(String.format("Polling to acquire lock %s for client %s was interrupted", lockName, lockConfig.getClientId()), e);
}
}
/**
* Will release the lock using the locking mechanism. If a lock cannot
* be released within the configured timeout interval, an exception is thrown.
*
* @param migrationFailed true if migration failed, false otherwise
* @throws CannotReleaseLockException if this cannot release lock within the specified time interval or locking mechanism fails
*/ | public void unlock(boolean migrationFailed) throws CannotReleaseLockException { |
sky-uk/cqlmigrate | src/test/java/uk/sky/cqlmigrate/LockTest.java | // Path: src/main/java/uk/sky/cqlmigrate/exception/CannotAcquireLockException.java
// public class CannotAcquireLockException extends LockException {
//
// public CannotAcquireLockException(String message) {
// super(message);
// }
//
// public CannotAcquireLockException(String message, Throwable cause) {
// super(message, cause);
// }
// }
//
// Path: src/main/java/uk/sky/cqlmigrate/exception/CannotReleaseLockException.java
// public class CannotReleaseLockException extends LockException {
//
// public CannotReleaseLockException(String message, Throwable cause) {
// super(message, cause);
// }
//
// public CannotReleaseLockException(String message) {
// super(message);
// }
// }
| import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.catchThrowable;
import static org.junit.Assert.fail;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.inOrder;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InOrder;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import uk.sky.cqlmigrate.exception.CannotAcquireLockException;
import uk.sky.cqlmigrate.exception.CannotReleaseLockException;
import java.time.Duration; | given(lockingMechanism.acquire(LOCK_CONFIG.getClientId())).willReturn(true);
//when
lock.lock();
}
@Test
public void retriesToAcquireLockAfterIntervalIfFailedTheFirstTime() throws Throwable {
//given
given(lockingMechanism.acquire(LOCK_CONFIG.getClientId())).willReturn(false, true);
//when
long startTime = System.currentTimeMillis();
lock.lock();
long duration = System.currentTimeMillis() - startTime;
//then
assertThat(duration).isGreaterThanOrEqualTo(POLLING_MILLIS);
}
@Test
public void throwsExceptionIfFailedToAcquireLockBeforeTimeout() throws Throwable {
//given
given(lockingMechanism.acquire(LOCK_CONFIG.getClientId())).willReturn(false);
//when
long startTime = System.currentTimeMillis();
try {
lock.lock();
fail("Expected Exception"); | // Path: src/main/java/uk/sky/cqlmigrate/exception/CannotAcquireLockException.java
// public class CannotAcquireLockException extends LockException {
//
// public CannotAcquireLockException(String message) {
// super(message);
// }
//
// public CannotAcquireLockException(String message, Throwable cause) {
// super(message, cause);
// }
// }
//
// Path: src/main/java/uk/sky/cqlmigrate/exception/CannotReleaseLockException.java
// public class CannotReleaseLockException extends LockException {
//
// public CannotReleaseLockException(String message, Throwable cause) {
// super(message, cause);
// }
//
// public CannotReleaseLockException(String message) {
// super(message);
// }
// }
// Path: src/test/java/uk/sky/cqlmigrate/LockTest.java
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.catchThrowable;
import static org.junit.Assert.fail;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.inOrder;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InOrder;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import uk.sky.cqlmigrate.exception.CannotAcquireLockException;
import uk.sky.cqlmigrate.exception.CannotReleaseLockException;
import java.time.Duration;
given(lockingMechanism.acquire(LOCK_CONFIG.getClientId())).willReturn(true);
//when
lock.lock();
}
@Test
public void retriesToAcquireLockAfterIntervalIfFailedTheFirstTime() throws Throwable {
//given
given(lockingMechanism.acquire(LOCK_CONFIG.getClientId())).willReturn(false, true);
//when
long startTime = System.currentTimeMillis();
lock.lock();
long duration = System.currentTimeMillis() - startTime;
//then
assertThat(duration).isGreaterThanOrEqualTo(POLLING_MILLIS);
}
@Test
public void throwsExceptionIfFailedToAcquireLockBeforeTimeout() throws Throwable {
//given
given(lockingMechanism.acquire(LOCK_CONFIG.getClientId())).willReturn(false);
//when
long startTime = System.currentTimeMillis();
try {
lock.lock();
fail("Expected Exception"); | } catch (CannotAcquireLockException e) {} |
sky-uk/cqlmigrate | src/test/java/uk/sky/cqlmigrate/LockTest.java | // Path: src/main/java/uk/sky/cqlmigrate/exception/CannotAcquireLockException.java
// public class CannotAcquireLockException extends LockException {
//
// public CannotAcquireLockException(String message) {
// super(message);
// }
//
// public CannotAcquireLockException(String message, Throwable cause) {
// super(message, cause);
// }
// }
//
// Path: src/main/java/uk/sky/cqlmigrate/exception/CannotReleaseLockException.java
// public class CannotReleaseLockException extends LockException {
//
// public CannotReleaseLockException(String message, Throwable cause) {
// super(message, cause);
// }
//
// public CannotReleaseLockException(String message) {
// super(message);
// }
// }
| import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.catchThrowable;
import static org.junit.Assert.fail;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.inOrder;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InOrder;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import uk.sky.cqlmigrate.exception.CannotAcquireLockException;
import uk.sky.cqlmigrate.exception.CannotReleaseLockException;
import java.time.Duration; |
@Test
public void retriesToReleaseLockAfterIntervalIfFailedTheFirstTime() throws Throwable {
//given
given(lockingMechanism.acquire(LOCK_CONFIG.getClientId())).willReturn(true);
given(lockingMechanism.release(LOCK_CONFIG.getClientId())).willReturn(false, true);
lock.lock();
//when
long startTime = System.currentTimeMillis();
lock.unlock(false);
long duration = System.currentTimeMillis() - startTime;
//then
assertThat(duration).isGreaterThanOrEqualTo(POLLING_MILLIS);
verify(lockingMechanism, times(2)).release(LOCK_CONFIG.getClientId());
}
@Test
public void throwsExceptionIfFailedToReleaseLockBeforeTimeout() throws Throwable {
//given
given(lockingMechanism.acquire(LOCK_CONFIG.getClientId())).willReturn(true);
given(lockingMechanism.release(LOCK_CONFIG.getClientId())).willReturn(false);
lock.lock();
//when
long startTime = System.currentTimeMillis();
try {
lock.unlock(false);
fail("Expected Exception"); | // Path: src/main/java/uk/sky/cqlmigrate/exception/CannotAcquireLockException.java
// public class CannotAcquireLockException extends LockException {
//
// public CannotAcquireLockException(String message) {
// super(message);
// }
//
// public CannotAcquireLockException(String message, Throwable cause) {
// super(message, cause);
// }
// }
//
// Path: src/main/java/uk/sky/cqlmigrate/exception/CannotReleaseLockException.java
// public class CannotReleaseLockException extends LockException {
//
// public CannotReleaseLockException(String message, Throwable cause) {
// super(message, cause);
// }
//
// public CannotReleaseLockException(String message) {
// super(message);
// }
// }
// Path: src/test/java/uk/sky/cqlmigrate/LockTest.java
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.catchThrowable;
import static org.junit.Assert.fail;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.inOrder;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InOrder;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import uk.sky.cqlmigrate.exception.CannotAcquireLockException;
import uk.sky.cqlmigrate.exception.CannotReleaseLockException;
import java.time.Duration;
@Test
public void retriesToReleaseLockAfterIntervalIfFailedTheFirstTime() throws Throwable {
//given
given(lockingMechanism.acquire(LOCK_CONFIG.getClientId())).willReturn(true);
given(lockingMechanism.release(LOCK_CONFIG.getClientId())).willReturn(false, true);
lock.lock();
//when
long startTime = System.currentTimeMillis();
lock.unlock(false);
long duration = System.currentTimeMillis() - startTime;
//then
assertThat(duration).isGreaterThanOrEqualTo(POLLING_MILLIS);
verify(lockingMechanism, times(2)).release(LOCK_CONFIG.getClientId());
}
@Test
public void throwsExceptionIfFailedToReleaseLockBeforeTimeout() throws Throwable {
//given
given(lockingMechanism.acquire(LOCK_CONFIG.getClientId())).willReturn(true);
given(lockingMechanism.release(LOCK_CONFIG.getClientId())).willReturn(false);
lock.lock();
//when
long startTime = System.currentTimeMillis();
try {
lock.unlock(false);
fail("Expected Exception"); | } catch (CannotReleaseLockException e) { |
sky-uk/cqlmigrate | src/main/java/uk/sky/cqlmigrate/ClusterHealth.java | // Path: src/main/java/uk/sky/cqlmigrate/exception/ClusterUnhealthyException.java
// public class ClusterUnhealthyException extends RuntimeException {
// public ClusterUnhealthyException(String message) {
// super(message);
// }
// }
| import com.datastax.oss.driver.api.core.metadata.Node;
import com.datastax.oss.driver.api.core.metadata.NodeState;
import com.datastax.oss.driver.api.core.session.Session;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import uk.sky.cqlmigrate.exception.ClusterUnhealthyException;
import java.net.InetAddress;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.stream.Collectors; | package uk.sky.cqlmigrate;
class ClusterHealth {
private static final Logger log = LoggerFactory.getLogger(ClusterHealth.class);
private final Session session;
ClusterHealth(Session session) {
this.session = session;
}
| // Path: src/main/java/uk/sky/cqlmigrate/exception/ClusterUnhealthyException.java
// public class ClusterUnhealthyException extends RuntimeException {
// public ClusterUnhealthyException(String message) {
// super(message);
// }
// }
// Path: src/main/java/uk/sky/cqlmigrate/ClusterHealth.java
import com.datastax.oss.driver.api.core.metadata.Node;
import com.datastax.oss.driver.api.core.metadata.NodeState;
import com.datastax.oss.driver.api.core.session.Session;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import uk.sky.cqlmigrate.exception.ClusterUnhealthyException;
import java.net.InetAddress;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.stream.Collectors;
package uk.sky.cqlmigrate;
class ClusterHealth {
private static final Logger log = LoggerFactory.getLogger(ClusterHealth.class);
private final Session session;
ClusterHealth(Session session) {
this.session = session;
}
| void check() throws ClusterUnhealthyException { |
sky-uk/cqlmigrate | src/test/java/uk/sky/cqlmigrate/CassandraLockingMechanismTest.java | // Path: src/main/java/uk/sky/cqlmigrate/exception/CannotAcquireLockException.java
// public class CannotAcquireLockException extends LockException {
//
// public CannotAcquireLockException(String message) {
// super(message);
// }
//
// public CannotAcquireLockException(String message, Throwable cause) {
// super(message, cause);
// }
// }
//
// Path: src/main/java/uk/sky/cqlmigrate/exception/CannotReleaseLockException.java
// public class CannotReleaseLockException extends LockException {
//
// public CannotReleaseLockException(String message, Throwable cause) {
// super(message, cause);
// }
//
// public CannotReleaseLockException(String message) {
// super(message);
// }
// }
//
// Path: src/test/java/uk/sky/cqlmigrate/util/PortScavenger.java
// public class PortScavenger {
//
// public static int getFreePort() {
// ServerSocket socket = null;
// try {
// socket = new ServerSocket(0);
// socket.setReuseAddress(true);
// int port = socket.getLocalPort();
// closeSocket(socket);
// return port;
// } catch (IOException ignored) {
// } finally {
// closeSocket(socket);
// }
// throw new IllegalStateException("Could not find a free TCP/IP port to start embedded Jetty HTTP Server on");
//
// }
//
// private static void closeSocket(ServerSocket socket) {
// if (socket != null) {
// try {
// socket.close();
// } catch (IOException ignored) {
// }
// }
// }
// }
| import com.datastax.oss.driver.api.core.ConsistencyLevel;
import com.datastax.oss.driver.api.core.CqlSession;
import com.datastax.oss.driver.api.core.DriverException;
import com.datastax.oss.protocol.internal.request.Prepare;
import com.datastax.oss.simulacron.common.cluster.ClusterSpec;
import com.datastax.oss.simulacron.common.cluster.DataCenterSpec;
import com.datastax.oss.simulacron.common.cluster.QueryLog;
import com.datastax.oss.simulacron.common.codec.WriteType;
import com.datastax.oss.simulacron.server.BoundCluster;
import com.datastax.oss.simulacron.server.Server;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
import org.assertj.core.api.AbstractThrowableAssert;
import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import uk.sky.cqlmigrate.exception.CannotAcquireLockException;
import uk.sky.cqlmigrate.exception.CannotReleaseLockException;
import uk.sky.cqlmigrate.util.PortScavenger;
import java.net.Inet4Address;
import java.net.InetSocketAddress;
import java.net.UnknownHostException;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.UUID;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import static com.datastax.oss.simulacron.common.stubbing.PrimeDsl.*;
import static java.lang.String.valueOf;
import static org.assertj.core.api.Assertions.*; | package uk.sky.cqlmigrate;
public class CassandraLockingMechanismTest {
private static final String LOCK_KEYSPACE = "lock-keyspace";
private static final String CLIENT_ID = UUID.randomUUID().toString();
private static final String PREPARE_INSERT_QUERY = "INSERT INTO cqlmigrate.locks (name, client) VALUES (?, ?) IF NOT EXISTS";
private static final String PREPARE_DELETE_QUERY = "DELETE FROM cqlmigrate.locks WHERE name = ? IF client = ?";
| // Path: src/main/java/uk/sky/cqlmigrate/exception/CannotAcquireLockException.java
// public class CannotAcquireLockException extends LockException {
//
// public CannotAcquireLockException(String message) {
// super(message);
// }
//
// public CannotAcquireLockException(String message, Throwable cause) {
// super(message, cause);
// }
// }
//
// Path: src/main/java/uk/sky/cqlmigrate/exception/CannotReleaseLockException.java
// public class CannotReleaseLockException extends LockException {
//
// public CannotReleaseLockException(String message, Throwable cause) {
// super(message, cause);
// }
//
// public CannotReleaseLockException(String message) {
// super(message);
// }
// }
//
// Path: src/test/java/uk/sky/cqlmigrate/util/PortScavenger.java
// public class PortScavenger {
//
// public static int getFreePort() {
// ServerSocket socket = null;
// try {
// socket = new ServerSocket(0);
// socket.setReuseAddress(true);
// int port = socket.getLocalPort();
// closeSocket(socket);
// return port;
// } catch (IOException ignored) {
// } finally {
// closeSocket(socket);
// }
// throw new IllegalStateException("Could not find a free TCP/IP port to start embedded Jetty HTTP Server on");
//
// }
//
// private static void closeSocket(ServerSocket socket) {
// if (socket != null) {
// try {
// socket.close();
// } catch (IOException ignored) {
// }
// }
// }
// }
// Path: src/test/java/uk/sky/cqlmigrate/CassandraLockingMechanismTest.java
import com.datastax.oss.driver.api.core.ConsistencyLevel;
import com.datastax.oss.driver.api.core.CqlSession;
import com.datastax.oss.driver.api.core.DriverException;
import com.datastax.oss.protocol.internal.request.Prepare;
import com.datastax.oss.simulacron.common.cluster.ClusterSpec;
import com.datastax.oss.simulacron.common.cluster.DataCenterSpec;
import com.datastax.oss.simulacron.common.cluster.QueryLog;
import com.datastax.oss.simulacron.common.codec.WriteType;
import com.datastax.oss.simulacron.server.BoundCluster;
import com.datastax.oss.simulacron.server.Server;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
import org.assertj.core.api.AbstractThrowableAssert;
import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import uk.sky.cqlmigrate.exception.CannotAcquireLockException;
import uk.sky.cqlmigrate.exception.CannotReleaseLockException;
import uk.sky.cqlmigrate.util.PortScavenger;
import java.net.Inet4Address;
import java.net.InetSocketAddress;
import java.net.UnknownHostException;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.UUID;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import static com.datastax.oss.simulacron.common.stubbing.PrimeDsl.*;
import static java.lang.String.valueOf;
import static org.assertj.core.api.Assertions.*;
package uk.sky.cqlmigrate;
public class CassandraLockingMechanismTest {
private static final String LOCK_KEYSPACE = "lock-keyspace";
private static final String CLIENT_ID = UUID.randomUUID().toString();
private static final String PREPARE_INSERT_QUERY = "INSERT INTO cqlmigrate.locks (name, client) VALUES (?, ?) IF NOT EXISTS";
private static final String PREPARE_DELETE_QUERY = "DELETE FROM cqlmigrate.locks WHERE name = ? IF client = ?";
| private static final int defaultStartingPort = PortScavenger.getFreePort(); |
sky-uk/cqlmigrate | src/test/java/uk/sky/cqlmigrate/CassandraLockingMechanismTest.java | // Path: src/main/java/uk/sky/cqlmigrate/exception/CannotAcquireLockException.java
// public class CannotAcquireLockException extends LockException {
//
// public CannotAcquireLockException(String message) {
// super(message);
// }
//
// public CannotAcquireLockException(String message, Throwable cause) {
// super(message, cause);
// }
// }
//
// Path: src/main/java/uk/sky/cqlmigrate/exception/CannotReleaseLockException.java
// public class CannotReleaseLockException extends LockException {
//
// public CannotReleaseLockException(String message, Throwable cause) {
// super(message, cause);
// }
//
// public CannotReleaseLockException(String message) {
// super(message);
// }
// }
//
// Path: src/test/java/uk/sky/cqlmigrate/util/PortScavenger.java
// public class PortScavenger {
//
// public static int getFreePort() {
// ServerSocket socket = null;
// try {
// socket = new ServerSocket(0);
// socket.setReuseAddress(true);
// int port = socket.getLocalPort();
// closeSocket(socket);
// return port;
// } catch (IOException ignored) {
// } finally {
// closeSocket(socket);
// }
// throw new IllegalStateException("Could not find a free TCP/IP port to start embedded Jetty HTTP Server on");
//
// }
//
// private static void closeSocket(ServerSocket socket) {
// if (socket != null) {
// try {
// socket.close();
// } catch (IOException ignored) {
// }
// }
// }
// }
| import com.datastax.oss.driver.api.core.ConsistencyLevel;
import com.datastax.oss.driver.api.core.CqlSession;
import com.datastax.oss.driver.api.core.DriverException;
import com.datastax.oss.protocol.internal.request.Prepare;
import com.datastax.oss.simulacron.common.cluster.ClusterSpec;
import com.datastax.oss.simulacron.common.cluster.DataCenterSpec;
import com.datastax.oss.simulacron.common.cluster.QueryLog;
import com.datastax.oss.simulacron.common.codec.WriteType;
import com.datastax.oss.simulacron.server.BoundCluster;
import com.datastax.oss.simulacron.server.Server;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
import org.assertj.core.api.AbstractThrowableAssert;
import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import uk.sky.cqlmigrate.exception.CannotAcquireLockException;
import uk.sky.cqlmigrate.exception.CannotReleaseLockException;
import uk.sky.cqlmigrate.util.PortScavenger;
import java.net.Inet4Address;
import java.net.InetSocketAddress;
import java.net.UnknownHostException;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.UUID;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import static com.datastax.oss.simulacron.common.stubbing.PrimeDsl.*;
import static java.lang.String.valueOf;
import static org.assertj.core.api.Assertions.*; | .describedAs("lock not acquired")
.isFalse();
}
@Test
public void shouldUnsuccessfullyAcquireLockWhenInsertIsNotApplied() {
//given
cluster.prime(primeInsertQuery(LOCK_KEYSPACE, CLIENT_ID, true).
then(writeTimeout(com.datastax.oss.simulacron.common.codec.ConsistencyLevel.ALL, 1, 1, WriteType.SIMPLE)));
//when
lockingMechanism.init();
boolean acquiredLock = lockingMechanism.acquire(CLIENT_ID);
//then
assertThat(acquiredLock)
.describedAs("lock was not acquired")
.isFalse();
}
@Test
public void shouldThrowExceptionIfQueryFailsToExecuteWhenAcquiringLock() {
cluster.prime(primeInsertQuery(LOCK_KEYSPACE, CLIENT_ID, true).
then(unavailable(com.datastax.oss.simulacron.common.codec.ConsistencyLevel.ALL, 1, 1)));
lockingMechanism.init();
//when
Throwable throwable = catchThrowable(() -> lockingMechanism.acquire(CLIENT_ID));
//then
assertThat(throwable)
.isNotNull() | // Path: src/main/java/uk/sky/cqlmigrate/exception/CannotAcquireLockException.java
// public class CannotAcquireLockException extends LockException {
//
// public CannotAcquireLockException(String message) {
// super(message);
// }
//
// public CannotAcquireLockException(String message, Throwable cause) {
// super(message, cause);
// }
// }
//
// Path: src/main/java/uk/sky/cqlmigrate/exception/CannotReleaseLockException.java
// public class CannotReleaseLockException extends LockException {
//
// public CannotReleaseLockException(String message, Throwable cause) {
// super(message, cause);
// }
//
// public CannotReleaseLockException(String message) {
// super(message);
// }
// }
//
// Path: src/test/java/uk/sky/cqlmigrate/util/PortScavenger.java
// public class PortScavenger {
//
// public static int getFreePort() {
// ServerSocket socket = null;
// try {
// socket = new ServerSocket(0);
// socket.setReuseAddress(true);
// int port = socket.getLocalPort();
// closeSocket(socket);
// return port;
// } catch (IOException ignored) {
// } finally {
// closeSocket(socket);
// }
// throw new IllegalStateException("Could not find a free TCP/IP port to start embedded Jetty HTTP Server on");
//
// }
//
// private static void closeSocket(ServerSocket socket) {
// if (socket != null) {
// try {
// socket.close();
// } catch (IOException ignored) {
// }
// }
// }
// }
// Path: src/test/java/uk/sky/cqlmigrate/CassandraLockingMechanismTest.java
import com.datastax.oss.driver.api.core.ConsistencyLevel;
import com.datastax.oss.driver.api.core.CqlSession;
import com.datastax.oss.driver.api.core.DriverException;
import com.datastax.oss.protocol.internal.request.Prepare;
import com.datastax.oss.simulacron.common.cluster.ClusterSpec;
import com.datastax.oss.simulacron.common.cluster.DataCenterSpec;
import com.datastax.oss.simulacron.common.cluster.QueryLog;
import com.datastax.oss.simulacron.common.codec.WriteType;
import com.datastax.oss.simulacron.server.BoundCluster;
import com.datastax.oss.simulacron.server.Server;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
import org.assertj.core.api.AbstractThrowableAssert;
import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import uk.sky.cqlmigrate.exception.CannotAcquireLockException;
import uk.sky.cqlmigrate.exception.CannotReleaseLockException;
import uk.sky.cqlmigrate.util.PortScavenger;
import java.net.Inet4Address;
import java.net.InetSocketAddress;
import java.net.UnknownHostException;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.UUID;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import static com.datastax.oss.simulacron.common.stubbing.PrimeDsl.*;
import static java.lang.String.valueOf;
import static org.assertj.core.api.Assertions.*;
.describedAs("lock not acquired")
.isFalse();
}
@Test
public void shouldUnsuccessfullyAcquireLockWhenInsertIsNotApplied() {
//given
cluster.prime(primeInsertQuery(LOCK_KEYSPACE, CLIENT_ID, true).
then(writeTimeout(com.datastax.oss.simulacron.common.codec.ConsistencyLevel.ALL, 1, 1, WriteType.SIMPLE)));
//when
lockingMechanism.init();
boolean acquiredLock = lockingMechanism.acquire(CLIENT_ID);
//then
assertThat(acquiredLock)
.describedAs("lock was not acquired")
.isFalse();
}
@Test
public void shouldThrowExceptionIfQueryFailsToExecuteWhenAcquiringLock() {
cluster.prime(primeInsertQuery(LOCK_KEYSPACE, CLIENT_ID, true).
then(unavailable(com.datastax.oss.simulacron.common.codec.ConsistencyLevel.ALL, 1, 1)));
lockingMechanism.init();
//when
Throwable throwable = catchThrowable(() -> lockingMechanism.acquire(CLIENT_ID));
//then
assertThat(throwable)
.isNotNull() | .isInstanceOf(CannotAcquireLockException.class) |
sky-uk/cqlmigrate | src/test/java/uk/sky/cqlmigrate/CassandraLockingMechanismTest.java | // Path: src/main/java/uk/sky/cqlmigrate/exception/CannotAcquireLockException.java
// public class CannotAcquireLockException extends LockException {
//
// public CannotAcquireLockException(String message) {
// super(message);
// }
//
// public CannotAcquireLockException(String message, Throwable cause) {
// super(message, cause);
// }
// }
//
// Path: src/main/java/uk/sky/cqlmigrate/exception/CannotReleaseLockException.java
// public class CannotReleaseLockException extends LockException {
//
// public CannotReleaseLockException(String message, Throwable cause) {
// super(message, cause);
// }
//
// public CannotReleaseLockException(String message) {
// super(message);
// }
// }
//
// Path: src/test/java/uk/sky/cqlmigrate/util/PortScavenger.java
// public class PortScavenger {
//
// public static int getFreePort() {
// ServerSocket socket = null;
// try {
// socket = new ServerSocket(0);
// socket.setReuseAddress(true);
// int port = socket.getLocalPort();
// closeSocket(socket);
// return port;
// } catch (IOException ignored) {
// } finally {
// closeSocket(socket);
// }
// throw new IllegalStateException("Could not find a free TCP/IP port to start embedded Jetty HTTP Server on");
//
// }
//
// private static void closeSocket(ServerSocket socket) {
// if (socket != null) {
// try {
// socket.close();
// } catch (IOException ignored) {
// }
// }
// }
// }
| import com.datastax.oss.driver.api.core.ConsistencyLevel;
import com.datastax.oss.driver.api.core.CqlSession;
import com.datastax.oss.driver.api.core.DriverException;
import com.datastax.oss.protocol.internal.request.Prepare;
import com.datastax.oss.simulacron.common.cluster.ClusterSpec;
import com.datastax.oss.simulacron.common.cluster.DataCenterSpec;
import com.datastax.oss.simulacron.common.cluster.QueryLog;
import com.datastax.oss.simulacron.common.codec.WriteType;
import com.datastax.oss.simulacron.server.BoundCluster;
import com.datastax.oss.simulacron.server.Server;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
import org.assertj.core.api.AbstractThrowableAssert;
import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import uk.sky.cqlmigrate.exception.CannotAcquireLockException;
import uk.sky.cqlmigrate.exception.CannotReleaseLockException;
import uk.sky.cqlmigrate.util.PortScavenger;
import java.net.Inet4Address;
import java.net.InetSocketAddress;
import java.net.UnknownHostException;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.UUID;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import static com.datastax.oss.simulacron.common.stubbing.PrimeDsl.*;
import static java.lang.String.valueOf;
import static org.assertj.core.api.Assertions.*; | .collect(Collectors.toList());
assertThat(queryLogs.size()).isEqualTo(1);
}
@Test
public void shouldSuccessfullyReleaseLockWhenNoLockFound() {
cluster.prime(primeDeleteQuery(LOCK_KEYSPACE, CLIENT_ID, false));
lockingMechanism.init();
//when
AbstractThrowableAssert<?, ? extends Throwable> execution = assertThatCode(
() -> lockingMechanism.release(CLIENT_ID)
);
// then
execution.doesNotThrowAnyException();
}
@Test
public void shouldThrowExceptionIfQueryFailsToExecuteWhenReleasingLock() {
//given
cluster.prime(primeDeleteQuery(LOCK_KEYSPACE, CLIENT_ID, true).
then(unavailable(com.datastax.oss.simulacron.common.codec.ConsistencyLevel.ALL, 1, 1)));
lockingMechanism.init();
//when
Throwable throwable = catchThrowable(() -> lockingMechanism.release(CLIENT_ID));
//then
assertThat(throwable)
.isNotNull() | // Path: src/main/java/uk/sky/cqlmigrate/exception/CannotAcquireLockException.java
// public class CannotAcquireLockException extends LockException {
//
// public CannotAcquireLockException(String message) {
// super(message);
// }
//
// public CannotAcquireLockException(String message, Throwable cause) {
// super(message, cause);
// }
// }
//
// Path: src/main/java/uk/sky/cqlmigrate/exception/CannotReleaseLockException.java
// public class CannotReleaseLockException extends LockException {
//
// public CannotReleaseLockException(String message, Throwable cause) {
// super(message, cause);
// }
//
// public CannotReleaseLockException(String message) {
// super(message);
// }
// }
//
// Path: src/test/java/uk/sky/cqlmigrate/util/PortScavenger.java
// public class PortScavenger {
//
// public static int getFreePort() {
// ServerSocket socket = null;
// try {
// socket = new ServerSocket(0);
// socket.setReuseAddress(true);
// int port = socket.getLocalPort();
// closeSocket(socket);
// return port;
// } catch (IOException ignored) {
// } finally {
// closeSocket(socket);
// }
// throw new IllegalStateException("Could not find a free TCP/IP port to start embedded Jetty HTTP Server on");
//
// }
//
// private static void closeSocket(ServerSocket socket) {
// if (socket != null) {
// try {
// socket.close();
// } catch (IOException ignored) {
// }
// }
// }
// }
// Path: src/test/java/uk/sky/cqlmigrate/CassandraLockingMechanismTest.java
import com.datastax.oss.driver.api.core.ConsistencyLevel;
import com.datastax.oss.driver.api.core.CqlSession;
import com.datastax.oss.driver.api.core.DriverException;
import com.datastax.oss.protocol.internal.request.Prepare;
import com.datastax.oss.simulacron.common.cluster.ClusterSpec;
import com.datastax.oss.simulacron.common.cluster.DataCenterSpec;
import com.datastax.oss.simulacron.common.cluster.QueryLog;
import com.datastax.oss.simulacron.common.codec.WriteType;
import com.datastax.oss.simulacron.server.BoundCluster;
import com.datastax.oss.simulacron.server.Server;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
import org.assertj.core.api.AbstractThrowableAssert;
import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import uk.sky.cqlmigrate.exception.CannotAcquireLockException;
import uk.sky.cqlmigrate.exception.CannotReleaseLockException;
import uk.sky.cqlmigrate.util.PortScavenger;
import java.net.Inet4Address;
import java.net.InetSocketAddress;
import java.net.UnknownHostException;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.UUID;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import static com.datastax.oss.simulacron.common.stubbing.PrimeDsl.*;
import static java.lang.String.valueOf;
import static org.assertj.core.api.Assertions.*;
.collect(Collectors.toList());
assertThat(queryLogs.size()).isEqualTo(1);
}
@Test
public void shouldSuccessfullyReleaseLockWhenNoLockFound() {
cluster.prime(primeDeleteQuery(LOCK_KEYSPACE, CLIENT_ID, false));
lockingMechanism.init();
//when
AbstractThrowableAssert<?, ? extends Throwable> execution = assertThatCode(
() -> lockingMechanism.release(CLIENT_ID)
);
// then
execution.doesNotThrowAnyException();
}
@Test
public void shouldThrowExceptionIfQueryFailsToExecuteWhenReleasingLock() {
//given
cluster.prime(primeDeleteQuery(LOCK_KEYSPACE, CLIENT_ID, true).
then(unavailable(com.datastax.oss.simulacron.common.codec.ConsistencyLevel.ALL, 1, 1)));
lockingMechanism.init();
//when
Throwable throwable = catchThrowable(() -> lockingMechanism.release(CLIENT_ID));
//then
assertThat(throwable)
.isNotNull() | .isInstanceOf(CannotReleaseLockException.class) |
sky-uk/cqlmigrate | src/main/java/uk/sky/cqlmigrate/PreMigrationChecker.java | // Path: src/main/java/uk/sky/cqlmigrate/SchemaUpdates.java
// public static final String SCHEMA_UPDATES_TABLE = "schema_updates";
| import com.datastax.oss.driver.api.core.CqlIdentifier;
import com.datastax.oss.driver.api.core.metadata.schema.RelationMetadata;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.List;
import static uk.sky.cqlmigrate.SchemaUpdates.SCHEMA_UPDATES_TABLE; | package uk.sky.cqlmigrate;
public class PreMigrationChecker {
private static final Logger LOGGER = LoggerFactory.getLogger(PreMigrationChecker.class);
private final SessionContext sessionContext;
private final String keyspace;
private final SchemaChecker schemaChecker;
private final CqlPaths paths;
public PreMigrationChecker(SessionContext sessionContext, String keyspace, SchemaChecker schemaChecker, CqlPaths paths) {
this.sessionContext = sessionContext;
this.keyspace = keyspace;
this.schemaChecker = schemaChecker;
this.paths = paths;
}
boolean migrationIsNeeded() {
return !keyspaceExists() || !schemaUpdatesTableExists() || !allMigrationFilesApplied();
}
private boolean keyspaceExists() {
return sessionContext.getSession().getMetadata().getKeyspace(keyspace).isPresent();
}
private boolean schemaUpdatesTableExists() {
if(keyspaceExists()){
return sessionContext.getSession().getMetadata().getKeyspace(keyspace) | // Path: src/main/java/uk/sky/cqlmigrate/SchemaUpdates.java
// public static final String SCHEMA_UPDATES_TABLE = "schema_updates";
// Path: src/main/java/uk/sky/cqlmigrate/PreMigrationChecker.java
import com.datastax.oss.driver.api.core.CqlIdentifier;
import com.datastax.oss.driver.api.core.metadata.schema.RelationMetadata;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.List;
import static uk.sky.cqlmigrate.SchemaUpdates.SCHEMA_UPDATES_TABLE;
package uk.sky.cqlmigrate;
public class PreMigrationChecker {
private static final Logger LOGGER = LoggerFactory.getLogger(PreMigrationChecker.class);
private final SessionContext sessionContext;
private final String keyspace;
private final SchemaChecker schemaChecker;
private final CqlPaths paths;
public PreMigrationChecker(SessionContext sessionContext, String keyspace, SchemaChecker schemaChecker, CqlPaths paths) {
this.sessionContext = sessionContext;
this.keyspace = keyspace;
this.schemaChecker = schemaChecker;
this.paths = paths;
}
boolean migrationIsNeeded() {
return !keyspaceExists() || !schemaUpdatesTableExists() || !allMigrationFilesApplied();
}
private boolean keyspaceExists() {
return sessionContext.getSession().getMetadata().getKeyspace(keyspace).isPresent();
}
private boolean schemaUpdatesTableExists() {
if(keyspaceExists()){
return sessionContext.getSession().getMetadata().getKeyspace(keyspace) | .flatMap(keyspaceMetadata -> keyspaceMetadata.getTable(SCHEMA_UPDATES_TABLE)).isPresent(); |
sky-uk/cqlmigrate | src/test/java/uk/sky/cqlmigrate/ClusterHealthTest.java | // Path: src/main/java/uk/sky/cqlmigrate/exception/ClusterUnhealthyException.java
// public class ClusterUnhealthyException extends RuntimeException {
// public ClusterUnhealthyException(String message) {
// super(message);
// }
// }
//
// Path: src/test/java/uk/sky/cqlmigrate/util/PortScavenger.java
// public class PortScavenger {
//
// public static int getFreePort() {
// ServerSocket socket = null;
// try {
// socket = new ServerSocket(0);
// socket.setReuseAddress(true);
// int port = socket.getLocalPort();
// closeSocket(socket);
// return port;
// } catch (IOException ignored) {
// } finally {
// closeSocket(socket);
// }
// throw new IllegalStateException("Could not find a free TCP/IP port to start embedded Jetty HTTP Server on");
//
// }
//
// private static void closeSocket(ServerSocket socket) {
// if (socket != null) {
// try {
// socket.close();
// } catch (IOException ignored) {
// }
// }
// }
// }
| import com.datastax.oss.driver.api.core.CqlSession;
import com.datastax.oss.simulacron.common.cluster.ClusterSpec;
import com.datastax.oss.simulacron.common.cluster.DataCenterSpec;
import com.datastax.oss.simulacron.server.BoundCluster;
import com.datastax.oss.simulacron.server.RejectScope;
import com.datastax.oss.simulacron.server.Server;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import uk.sky.cqlmigrate.exception.ClusterUnhealthyException;
import uk.sky.cqlmigrate.util.PortScavenger;
import java.net.Inet4Address;
import java.net.InetSocketAddress;
import java.net.UnknownHostException;
import java.util.UUID;
import static com.datastax.oss.simulacron.common.stubbing.CloseType.DISCONNECT;
import static com.datastax.oss.simulacron.common.stubbing.PrimeDsl.rows;
import static com.datastax.oss.simulacron.common.stubbing.PrimeDsl.when;
import static java.util.concurrent.TimeUnit.MILLISECONDS;
import static java.util.concurrent.TimeUnit.SECONDS;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.catchThrowable;
import static org.awaitility.Awaitility.await; |
bCluster.prime(when("select cluster_name from system.local where key = 'local'")
.then(rows().row("cluster_name", "0").build()));
realCluster = CqlSession.builder()
.addContactPoint(new InetSocketAddress(Inet4Address.getByAddress(new byte[]{127, 0, 0, 1}), defaultStartingPort))
.withLocalDatacenter(dc.getName())
.build();
clusterHealth = new ClusterHealth(realCluster);
}
@After
public void tearDown() {
realCluster.close();
}
@Test
public void shouldThrowExceptionIfHostIsDown() {
//given
bCluster.node(0).closeConnections(DISCONNECT);
bCluster.node(0).rejectConnections(0, RejectScope.UNBIND);
await().pollInterval(500, MILLISECONDS)
.atMost(5, SECONDS)
.untilAsserted(() -> {
//when
Throwable throwable = catchThrowable(clusterHealth::check);
//then
assertThat(throwable).isNotNull(); | // Path: src/main/java/uk/sky/cqlmigrate/exception/ClusterUnhealthyException.java
// public class ClusterUnhealthyException extends RuntimeException {
// public ClusterUnhealthyException(String message) {
// super(message);
// }
// }
//
// Path: src/test/java/uk/sky/cqlmigrate/util/PortScavenger.java
// public class PortScavenger {
//
// public static int getFreePort() {
// ServerSocket socket = null;
// try {
// socket = new ServerSocket(0);
// socket.setReuseAddress(true);
// int port = socket.getLocalPort();
// closeSocket(socket);
// return port;
// } catch (IOException ignored) {
// } finally {
// closeSocket(socket);
// }
// throw new IllegalStateException("Could not find a free TCP/IP port to start embedded Jetty HTTP Server on");
//
// }
//
// private static void closeSocket(ServerSocket socket) {
// if (socket != null) {
// try {
// socket.close();
// } catch (IOException ignored) {
// }
// }
// }
// }
// Path: src/test/java/uk/sky/cqlmigrate/ClusterHealthTest.java
import com.datastax.oss.driver.api.core.CqlSession;
import com.datastax.oss.simulacron.common.cluster.ClusterSpec;
import com.datastax.oss.simulacron.common.cluster.DataCenterSpec;
import com.datastax.oss.simulacron.server.BoundCluster;
import com.datastax.oss.simulacron.server.RejectScope;
import com.datastax.oss.simulacron.server.Server;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import uk.sky.cqlmigrate.exception.ClusterUnhealthyException;
import uk.sky.cqlmigrate.util.PortScavenger;
import java.net.Inet4Address;
import java.net.InetSocketAddress;
import java.net.UnknownHostException;
import java.util.UUID;
import static com.datastax.oss.simulacron.common.stubbing.CloseType.DISCONNECT;
import static com.datastax.oss.simulacron.common.stubbing.PrimeDsl.rows;
import static com.datastax.oss.simulacron.common.stubbing.PrimeDsl.when;
import static java.util.concurrent.TimeUnit.MILLISECONDS;
import static java.util.concurrent.TimeUnit.SECONDS;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.catchThrowable;
import static org.awaitility.Awaitility.await;
bCluster.prime(when("select cluster_name from system.local where key = 'local'")
.then(rows().row("cluster_name", "0").build()));
realCluster = CqlSession.builder()
.addContactPoint(new InetSocketAddress(Inet4Address.getByAddress(new byte[]{127, 0, 0, 1}), defaultStartingPort))
.withLocalDatacenter(dc.getName())
.build();
clusterHealth = new ClusterHealth(realCluster);
}
@After
public void tearDown() {
realCluster.close();
}
@Test
public void shouldThrowExceptionIfHostIsDown() {
//given
bCluster.node(0).closeConnections(DISCONNECT);
bCluster.node(0).rejectConnections(0, RejectScope.UNBIND);
await().pollInterval(500, MILLISECONDS)
.atMost(5, SECONDS)
.untilAsserted(() -> {
//when
Throwable throwable = catchThrowable(clusterHealth::check);
//then
assertThat(throwable).isNotNull(); | assertThat(throwable).isInstanceOf(ClusterUnhealthyException.class); |
sky-uk/cqlmigrate | src/main/java/uk/sky/cqlmigrate/CassandraNoOpLockingMechanism.java | // Path: src/main/java/uk/sky/cqlmigrate/exception/CannotAcquireLockException.java
// public class CannotAcquireLockException extends LockException {
//
// public CannotAcquireLockException(String message) {
// super(message);
// }
//
// public CannotAcquireLockException(String message, Throwable cause) {
// super(message, cause);
// }
// }
//
// Path: src/main/java/uk/sky/cqlmigrate/exception/CannotReleaseLockException.java
// public class CannotReleaseLockException extends LockException {
//
// public CannotReleaseLockException(String message, Throwable cause) {
// super(message, cause);
// }
//
// public CannotReleaseLockException(String message) {
// super(message);
// }
// }
| import uk.sky.cqlmigrate.exception.CannotAcquireLockException;
import uk.sky.cqlmigrate.exception.CannotReleaseLockException; | package uk.sky.cqlmigrate;
class CassandraNoOpLockingMechanism extends LockingMechanism {
public CassandraNoOpLockingMechanism() {
super("NoOp");
}
/**
* Nothing to prepare.
*/
@Override | // Path: src/main/java/uk/sky/cqlmigrate/exception/CannotAcquireLockException.java
// public class CannotAcquireLockException extends LockException {
//
// public CannotAcquireLockException(String message) {
// super(message);
// }
//
// public CannotAcquireLockException(String message, Throwable cause) {
// super(message, cause);
// }
// }
//
// Path: src/main/java/uk/sky/cqlmigrate/exception/CannotReleaseLockException.java
// public class CannotReleaseLockException extends LockException {
//
// public CannotReleaseLockException(String message, Throwable cause) {
// super(message, cause);
// }
//
// public CannotReleaseLockException(String message) {
// super(message);
// }
// }
// Path: src/main/java/uk/sky/cqlmigrate/CassandraNoOpLockingMechanism.java
import uk.sky.cqlmigrate.exception.CannotAcquireLockException;
import uk.sky.cqlmigrate.exception.CannotReleaseLockException;
package uk.sky.cqlmigrate;
class CassandraNoOpLockingMechanism extends LockingMechanism {
public CassandraNoOpLockingMechanism() {
super("NoOp");
}
/**
* Nothing to prepare.
*/
@Override | public void init() throws CannotAcquireLockException { |
sky-uk/cqlmigrate | src/main/java/uk/sky/cqlmigrate/CassandraNoOpLockingMechanism.java | // Path: src/main/java/uk/sky/cqlmigrate/exception/CannotAcquireLockException.java
// public class CannotAcquireLockException extends LockException {
//
// public CannotAcquireLockException(String message) {
// super(message);
// }
//
// public CannotAcquireLockException(String message, Throwable cause) {
// super(message, cause);
// }
// }
//
// Path: src/main/java/uk/sky/cqlmigrate/exception/CannotReleaseLockException.java
// public class CannotReleaseLockException extends LockException {
//
// public CannotReleaseLockException(String message, Throwable cause) {
// super(message, cause);
// }
//
// public CannotReleaseLockException(String message) {
// super(message);
// }
// }
| import uk.sky.cqlmigrate.exception.CannotAcquireLockException;
import uk.sky.cqlmigrate.exception.CannotReleaseLockException; | package uk.sky.cqlmigrate;
class CassandraNoOpLockingMechanism extends LockingMechanism {
public CassandraNoOpLockingMechanism() {
super("NoOp");
}
/**
* Nothing to prepare.
*/
@Override
public void init() throws CannotAcquireLockException {
}
/**
* {@inheritDoc}
* <p>
* Always a success, no lock to acquire.
*/
@Override
public boolean acquire(String clientId) throws CannotAcquireLockException {
return true;
}
/**
* {@inheritDoc}
* <p>
* Always a success, no lock to release.
*/
@Override | // Path: src/main/java/uk/sky/cqlmigrate/exception/CannotAcquireLockException.java
// public class CannotAcquireLockException extends LockException {
//
// public CannotAcquireLockException(String message) {
// super(message);
// }
//
// public CannotAcquireLockException(String message, Throwable cause) {
// super(message, cause);
// }
// }
//
// Path: src/main/java/uk/sky/cqlmigrate/exception/CannotReleaseLockException.java
// public class CannotReleaseLockException extends LockException {
//
// public CannotReleaseLockException(String message, Throwable cause) {
// super(message, cause);
// }
//
// public CannotReleaseLockException(String message) {
// super(message);
// }
// }
// Path: src/main/java/uk/sky/cqlmigrate/CassandraNoOpLockingMechanism.java
import uk.sky.cqlmigrate.exception.CannotAcquireLockException;
import uk.sky.cqlmigrate.exception.CannotReleaseLockException;
package uk.sky.cqlmigrate;
class CassandraNoOpLockingMechanism extends LockingMechanism {
public CassandraNoOpLockingMechanism() {
super("NoOp");
}
/**
* Nothing to prepare.
*/
@Override
public void init() throws CannotAcquireLockException {
}
/**
* {@inheritDoc}
* <p>
* Always a success, no lock to acquire.
*/
@Override
public boolean acquire(String clientId) throws CannotAcquireLockException {
return true;
}
/**
* {@inheritDoc}
* <p>
* Always a success, no lock to release.
*/
@Override | public boolean release(String clientId) throws CannotReleaseLockException { |
sky-uk/cqlmigrate | src/test/java/uk/sky/cqlmigrate/CqlMigratorConsistencyLevelIntegrationTest.java | // Path: src/test/java/uk/sky/cqlmigrate/util/PortScavenger.java
// public class PortScavenger {
//
// public static int getFreePort() {
// ServerSocket socket = null;
// try {
// socket = new ServerSocket(0);
// socket.setReuseAddress(true);
// int port = socket.getLocalPort();
// closeSocket(socket);
// return port;
// } catch (IOException ignored) {
// } finally {
// closeSocket(socket);
// }
// throw new IllegalStateException("Could not find a free TCP/IP port to start embedded Jetty HTTP Server on");
//
// }
//
// private static void closeSocket(ServerSocket socket) {
// if (socket != null) {
// try {
// socket.close();
// } catch (IOException ignored) {
// }
// }
// }
// }
| import com.datastax.oss.driver.api.core.ConsistencyLevel;
import com.datastax.oss.simulacron.common.cluster.ClusterSpec;
import com.datastax.oss.simulacron.common.cluster.DataCenterSpec;
import com.datastax.oss.simulacron.common.cluster.QueryLog;
import com.datastax.oss.simulacron.common.cluster.RequestPrime;
import com.datastax.oss.simulacron.common.request.Query;
import com.datastax.oss.simulacron.common.result.SuccessResult;
import com.datastax.oss.simulacron.common.stubbing.Prime;
import com.datastax.oss.simulacron.common.stubbing.PrimeDsl;
import com.datastax.oss.simulacron.server.BoundCluster;
import com.datastax.oss.simulacron.server.Server;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
import org.apache.cassandra.exceptions.ConfigurationException;
import org.junit.*;
import uk.sky.cqlmigrate.util.PortScavenger;
import java.net.Inet4Address;
import java.net.InetSocketAddress;
import java.net.URISyntaxException;
import java.net.UnknownHostException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.*;
import java.util.stream.Collectors;
import static com.datastax.oss.simulacron.common.stubbing.PrimeDsl.*;
import static java.lang.String.valueOf;
import static java.util.Arrays.asList;
import static org.assertj.core.api.Assertions.assertThat; | package uk.sky.cqlmigrate;
public class CqlMigratorConsistencyLevelIntegrationTest {
private static final String CLIENT_ID = UUID.randomUUID().toString(); | // Path: src/test/java/uk/sky/cqlmigrate/util/PortScavenger.java
// public class PortScavenger {
//
// public static int getFreePort() {
// ServerSocket socket = null;
// try {
// socket = new ServerSocket(0);
// socket.setReuseAddress(true);
// int port = socket.getLocalPort();
// closeSocket(socket);
// return port;
// } catch (IOException ignored) {
// } finally {
// closeSocket(socket);
// }
// throw new IllegalStateException("Could not find a free TCP/IP port to start embedded Jetty HTTP Server on");
//
// }
//
// private static void closeSocket(ServerSocket socket) {
// if (socket != null) {
// try {
// socket.close();
// } catch (IOException ignored) {
// }
// }
// }
// }
// Path: src/test/java/uk/sky/cqlmigrate/CqlMigratorConsistencyLevelIntegrationTest.java
import com.datastax.oss.driver.api.core.ConsistencyLevel;
import com.datastax.oss.simulacron.common.cluster.ClusterSpec;
import com.datastax.oss.simulacron.common.cluster.DataCenterSpec;
import com.datastax.oss.simulacron.common.cluster.QueryLog;
import com.datastax.oss.simulacron.common.cluster.RequestPrime;
import com.datastax.oss.simulacron.common.request.Query;
import com.datastax.oss.simulacron.common.result.SuccessResult;
import com.datastax.oss.simulacron.common.stubbing.Prime;
import com.datastax.oss.simulacron.common.stubbing.PrimeDsl;
import com.datastax.oss.simulacron.server.BoundCluster;
import com.datastax.oss.simulacron.server.Server;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
import org.apache.cassandra.exceptions.ConfigurationException;
import org.junit.*;
import uk.sky.cqlmigrate.util.PortScavenger;
import java.net.Inet4Address;
import java.net.InetSocketAddress;
import java.net.URISyntaxException;
import java.net.UnknownHostException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.*;
import java.util.stream.Collectors;
import static com.datastax.oss.simulacron.common.stubbing.PrimeDsl.*;
import static java.lang.String.valueOf;
import static java.util.Arrays.asList;
import static org.assertj.core.api.Assertions.assertThat;
package uk.sky.cqlmigrate;
public class CqlMigratorConsistencyLevelIntegrationTest {
private static final String CLIENT_ID = UUID.randomUUID().toString(); | private static final int defaultStartingPort = PortScavenger.getFreePort(); |
dantetam/civgame | src/lwjglEngine/toolbox/MatrixMathUtil.java | // Path: src/lwjglEngine/entities/Camera.java
// public class Camera {
//
// public Vector3f position = new Vector3f(500, 100, 500);
// public float pitch = -10, yaw = 0, roll = 0; // High-low, left-right, tilt
// private float jerkPitch, jerkYaw;
// private int turnsPitch, turnsYaw;
// private static final float LOWER_BOUND_Y = 40, UPPER_BOUND_Y = 400;
//
// public Camera() {
//
// }
// // public Camera(Vector3f p, float a, float b, float c) {}
//
// // Allow the user to focus on the point (x, z) from a top-view perspective
// public void focusCamera(float x, float z, float angPitch) {
// float distanceBack = Math.abs(position.y / (float) Math.tan(angPitch));
// position = new Vector3f(x, position.y, z + distanceBack);
// turnsPitch = 20;
// turnsYaw = 20;
// // jerkPitch =
// // -(pitch-(float)Math.toDegrees(Math.atan(position.y/20F)))/(float)turnsPitch;
// jerkPitch = -(pitch + angPitch) / (float) turnsPitch;
// jerkYaw = -(yaw) / (float) turnsYaw;
// // pitch = 0; yaw = 0; roll = 0;
// }
//
// public void move() {
// if (turnsPitch > 0 || turnsYaw > 0) {
// if (turnsPitch > 0) {
// pitch += jerkPitch;
// turnsPitch--;
// }
// if (turnsYaw > 0) {
// yaw += jerkYaw;
// turnsYaw--;
// }
// return; // Override keyboard when camera is being shifted
// }
// float step = 5f, tilt = 1f;
// if (Keyboard.isKeyDown(GLFW.GLFW_KEY_I)) {
// position.y -= step;
// if (position.y < LOWER_BOUND_Y) {
// position.y = LOWER_BOUND_Y;
// }
// }
// if (Keyboard.isKeyDown(GLFW.GLFW_KEY_O)) {
// position.y += step;
// if (position.y > UPPER_BOUND_Y) {
// position.y = UPPER_BOUND_Y;
// }
// }
// if (Keyboard.isKeyDown(GLFW.GLFW_KEY_A)) {
// position.x -= step * Math.cos(Math.toRadians(yaw));
// position.z -= step * Math.sin(Math.toRadians(yaw));
// }
// if (Keyboard.isKeyDown(GLFW.GLFW_KEY_D)) {
// position.x += step * Math.cos(Math.toRadians(yaw));
// position.z += step * Math.sin(Math.toRadians(yaw));
// }
// if (Keyboard.isKeyDown(GLFW.GLFW_KEY_S)) {
// // laziness, oops
// position.x -= step * Math.cos(Math.toRadians(yaw - 90));
// position.z -= step * Math.sin(Math.toRadians(yaw - 90));
// }
// if (Keyboard.isKeyDown(GLFW.GLFW_KEY_W)) {
// // +90 is clockwise, this is a right turn from pointing left (the 'a' command)
// position.x -= step * Math.cos(Math.toRadians(yaw + 90));
// position.z -= step * Math.sin(Math.toRadians(yaw + 90));
// }
// if (Keyboard.isKeyDown(GLFW.GLFW_KEY_Q))
// yaw -= tilt * 1f;
// if (Keyboard.isKeyDown(GLFW.GLFW_KEY_E))
// yaw += tilt * 1f;
// if (Keyboard.isKeyDown(GLFW.GLFW_KEY_H))
// yaw -= tilt * 1f;
// if (Keyboard.isKeyDown(GLFW.GLFW_KEY_K))
// yaw += tilt * 1f;
// if (Keyboard.isKeyDown(GLFW.GLFW_KEY_U))
// pitch -= tilt;
// if (Keyboard.isKeyDown(GLFW.GLFW_KEY_J))
// pitch += tilt;
// }
//
// }
| import org.lwjgl.util.vector.Matrix4f;
import org.lwjgl.util.vector.Vector2f;
import org.lwjgl.util.vector.Vector3f;
import lwjglEngine.entities.Camera; | package lwjglEngine.toolbox;
//Courtesy of ThinMatrix. Hope his kickstarter goes well.
public class MatrixMathUtil {
//Rotate normally by a certain translation
public static Matrix4f createTransformMatrix(Vector3f translation, float rx, float ry, float rz, float scale)
{
Matrix4f matrix = new Matrix4f();
matrix.setIdentity();
//Writing matrix twice accesses 'matrix' and rewrites the new 'transformed' matrix in 'matrix'
Matrix4f.translate(translation, matrix, matrix);
//Rotate it by angles around the axes
Matrix4f.rotate((float)Math.toRadians(rx), new Vector3f(1,0,0), matrix, matrix);
Matrix4f.rotate((float)Math.toRadians(ry), new Vector3f(0,1,0), matrix, matrix);
Matrix4f.rotate((float)Math.toRadians(rz), new Vector3f(0,0,1), matrix, matrix);
Matrix4f.scale(new Vector3f(scale,scale,scale), matrix, matrix);
return matrix;
}
//For 2D GUIs
public static Matrix4f createTransformationMatrix(Vector2f translation, Vector2f scale) {
Matrix4f matrix = new Matrix4f();
matrix.setIdentity();
Matrix4f.translate(translation, matrix, matrix);
Matrix4f.scale(new Vector3f(scale.x, scale.y, 1f), matrix, matrix);
return matrix;
}
//Rotate in the opposite direction with respect to a camera's orientation | // Path: src/lwjglEngine/entities/Camera.java
// public class Camera {
//
// public Vector3f position = new Vector3f(500, 100, 500);
// public float pitch = -10, yaw = 0, roll = 0; // High-low, left-right, tilt
// private float jerkPitch, jerkYaw;
// private int turnsPitch, turnsYaw;
// private static final float LOWER_BOUND_Y = 40, UPPER_BOUND_Y = 400;
//
// public Camera() {
//
// }
// // public Camera(Vector3f p, float a, float b, float c) {}
//
// // Allow the user to focus on the point (x, z) from a top-view perspective
// public void focusCamera(float x, float z, float angPitch) {
// float distanceBack = Math.abs(position.y / (float) Math.tan(angPitch));
// position = new Vector3f(x, position.y, z + distanceBack);
// turnsPitch = 20;
// turnsYaw = 20;
// // jerkPitch =
// // -(pitch-(float)Math.toDegrees(Math.atan(position.y/20F)))/(float)turnsPitch;
// jerkPitch = -(pitch + angPitch) / (float) turnsPitch;
// jerkYaw = -(yaw) / (float) turnsYaw;
// // pitch = 0; yaw = 0; roll = 0;
// }
//
// public void move() {
// if (turnsPitch > 0 || turnsYaw > 0) {
// if (turnsPitch > 0) {
// pitch += jerkPitch;
// turnsPitch--;
// }
// if (turnsYaw > 0) {
// yaw += jerkYaw;
// turnsYaw--;
// }
// return; // Override keyboard when camera is being shifted
// }
// float step = 5f, tilt = 1f;
// if (Keyboard.isKeyDown(GLFW.GLFW_KEY_I)) {
// position.y -= step;
// if (position.y < LOWER_BOUND_Y) {
// position.y = LOWER_BOUND_Y;
// }
// }
// if (Keyboard.isKeyDown(GLFW.GLFW_KEY_O)) {
// position.y += step;
// if (position.y > UPPER_BOUND_Y) {
// position.y = UPPER_BOUND_Y;
// }
// }
// if (Keyboard.isKeyDown(GLFW.GLFW_KEY_A)) {
// position.x -= step * Math.cos(Math.toRadians(yaw));
// position.z -= step * Math.sin(Math.toRadians(yaw));
// }
// if (Keyboard.isKeyDown(GLFW.GLFW_KEY_D)) {
// position.x += step * Math.cos(Math.toRadians(yaw));
// position.z += step * Math.sin(Math.toRadians(yaw));
// }
// if (Keyboard.isKeyDown(GLFW.GLFW_KEY_S)) {
// // laziness, oops
// position.x -= step * Math.cos(Math.toRadians(yaw - 90));
// position.z -= step * Math.sin(Math.toRadians(yaw - 90));
// }
// if (Keyboard.isKeyDown(GLFW.GLFW_KEY_W)) {
// // +90 is clockwise, this is a right turn from pointing left (the 'a' command)
// position.x -= step * Math.cos(Math.toRadians(yaw + 90));
// position.z -= step * Math.sin(Math.toRadians(yaw + 90));
// }
// if (Keyboard.isKeyDown(GLFW.GLFW_KEY_Q))
// yaw -= tilt * 1f;
// if (Keyboard.isKeyDown(GLFW.GLFW_KEY_E))
// yaw += tilt * 1f;
// if (Keyboard.isKeyDown(GLFW.GLFW_KEY_H))
// yaw -= tilt * 1f;
// if (Keyboard.isKeyDown(GLFW.GLFW_KEY_K))
// yaw += tilt * 1f;
// if (Keyboard.isKeyDown(GLFW.GLFW_KEY_U))
// pitch -= tilt;
// if (Keyboard.isKeyDown(GLFW.GLFW_KEY_J))
// pitch += tilt;
// }
//
// }
// Path: src/lwjglEngine/toolbox/MatrixMathUtil.java
import org.lwjgl.util.vector.Matrix4f;
import org.lwjgl.util.vector.Vector2f;
import org.lwjgl.util.vector.Vector3f;
import lwjglEngine.entities.Camera;
package lwjglEngine.toolbox;
//Courtesy of ThinMatrix. Hope his kickstarter goes well.
public class MatrixMathUtil {
//Rotate normally by a certain translation
public static Matrix4f createTransformMatrix(Vector3f translation, float rx, float ry, float rz, float scale)
{
Matrix4f matrix = new Matrix4f();
matrix.setIdentity();
//Writing matrix twice accesses 'matrix' and rewrites the new 'transformed' matrix in 'matrix'
Matrix4f.translate(translation, matrix, matrix);
//Rotate it by angles around the axes
Matrix4f.rotate((float)Math.toRadians(rx), new Vector3f(1,0,0), matrix, matrix);
Matrix4f.rotate((float)Math.toRadians(ry), new Vector3f(0,1,0), matrix, matrix);
Matrix4f.rotate((float)Math.toRadians(rz), new Vector3f(0,0,1), matrix, matrix);
Matrix4f.scale(new Vector3f(scale,scale,scale), matrix, matrix);
return matrix;
}
//For 2D GUIs
public static Matrix4f createTransformationMatrix(Vector2f translation, Vector2f scale) {
Matrix4f matrix = new Matrix4f();
matrix.setIdentity();
Matrix4f.translate(translation, matrix, matrix);
Matrix4f.scale(new Vector3f(scale.x, scale.y, 1f), matrix, matrix);
return matrix;
}
//Rotate in the opposite direction with respect to a camera's orientation | public static Matrix4f createViewMatrix(Camera camera) |
dantetam/civgame | src/lwjglEngine/fontMeshCreator/MetaFile.java | // Path: src/lwjglEngine/render/DisplayManager.java
// public class DisplayManager {
//
// public static final int width = (int) CivGame.WIDTH, height = (int) CivGame.HEIGHT;
// public static long window;
// public static CivGame main;
//
// //Store the callbacks in memory
// private static GLFWErrorCallback errorCallback;
// public static GLFWKeyCallback keyCallback;
// private static GLFWCursorPosCallback cursorPosCallback;
// public static GLFWMouseButtonCallback mouseButtonCallback;
//
// public DisplayManager(CivGame m)
// {
// main = m;
// }
//
// public static void createDisplay()
// {
// glfwInit();
// glfwSetErrorCallback(errorCallback = Callbacks.errorCallbackPrint(System.err));
//
// glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);
// glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
// glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
// glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
// window = glfwCreateWindow(width, height, "", 0, 0);
// glfwMakeContextCurrent(window);
// GLContext.createFromCurrent();
// glfwShowWindow(window);
//
// setCursorPosCallback();
// setMouseCallback();
// setKeyCallback();
//
// if (window == 0) {
// throw new RuntimeException("Failed to create window");
// }
//
// GL11.glViewport(0, 0, width, height);
// }
//
// public static void setCursorPosCallback()
// {
// GLFW.glfwSetCursorPosCallback(window, (cursorPosCallback = new GLFWCursorPosCallback() {
// public void invoke(long window, double xpos, double ypos) {
// Mouse.setMouse((float)xpos, (float)ypos);
// }
// }));
// }
//
// public static void setMouseCallback()
// {
// GLFW.glfwSetMouseButtonCallback(DisplayManager.window, (DisplayManager.mouseButtonCallback = new GLFWMouseButtonCallback() {
// public void invoke(long window, int button, int action, int mods) {
// if (action == GLFW.GLFW_PRESS) {
// main.menuSystem.queueMousePass(Mouse.getX(), Mouse.getY()); //includes button == 2 i.e. scroll wheel
// if (button == 0) {
// main.inputSystem.processLeftMouseClick(Mouse.getX(), Mouse.getY());
// }
// else if (button == 1) {
// main.inputSystem.processRightMouseClick(Mouse.getX(), Mouse.getY());
// }
// main.menuSystem.forceUpdate();
// //menuSystem.closeMenus();
// }
//
// }
// }));
// }
//
// public static void setKeyCallback()
// {
// GLFW.glfwSetKeyCallback(DisplayManager.window, (DisplayManager.keyCallback = new GLFWKeyCallback() {
// public void invoke(long window, int key, int scancode, int action, int mods) {
// if (action == GLFW.GLFW_PRESS) {
// main.inputSystem.keyPressed(key);
// main.menuSystem.forceUpdate();
// //menuSystem.closeMenus();
// }
// }
// }));
// }
//
// public static void updateDisplay()
// {
// for (int i = GLFW.GLFW_KEY_0; i <= GLFW.GLFW_KEY_Z; i++)
// {
// Keyboard.keys[i] = GLFW.glfwGetKey(window, i) == GLFW.GLFW_PRESS;
// }
// /*Display.sync(120);
// Display.update();*/
// glfwPollEvents();
// glfwSwapBuffers(window);
// }
//
// public static void closeDisplay()
// {
// glfwDestroyWindow(window);
// }
//
// public static boolean requestClose()
// {
// return glfwWindowShouldClose(DisplayManager.window) == GL_TRUE;
// }
//
// }
| import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import lwjglEngine.render.DisplayManager; | package lwjglEngine.fontMeshCreator;
/**
* Provides functionality for getting the values from a font file.
*
* @author Karl
*
*/
public class MetaFile {
/*private static final int PAD_TOP = 0;
private static final int PAD_LEFT = 1;
private static final int PAD_BOTTOM = 2;
private static final int PAD_RIGHT = 3;*/
private static final int PAD_TOP = 3;
private static final int PAD_LEFT = 3;
private static final int PAD_BOTTOM = 3;
private static final int PAD_RIGHT = 3;
private static final int DESIRED_PADDING = 3;
private static final String SPLITTER = " ";
private static final String NUMBER_SEPARATOR = ",";
private double aspectRatio;
private double verticalPerPixelSize;
private double horizontalPerPixelSize;
private double spaceWidth;
private int[] padding;
private int paddingWidth;
private int paddingHeight;
private Map<Integer, Character> metaData = new HashMap<Integer, Character>();
private BufferedReader reader;
private Map<String, String> values = new HashMap<String, String>();
/**
* Opens a font file in preparation for reading.
*
* @param file
* - the font file.
*/
protected MetaFile(File file) { | // Path: src/lwjglEngine/render/DisplayManager.java
// public class DisplayManager {
//
// public static final int width = (int) CivGame.WIDTH, height = (int) CivGame.HEIGHT;
// public static long window;
// public static CivGame main;
//
// //Store the callbacks in memory
// private static GLFWErrorCallback errorCallback;
// public static GLFWKeyCallback keyCallback;
// private static GLFWCursorPosCallback cursorPosCallback;
// public static GLFWMouseButtonCallback mouseButtonCallback;
//
// public DisplayManager(CivGame m)
// {
// main = m;
// }
//
// public static void createDisplay()
// {
// glfwInit();
// glfwSetErrorCallback(errorCallback = Callbacks.errorCallbackPrint(System.err));
//
// glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);
// glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
// glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
// glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
// window = glfwCreateWindow(width, height, "", 0, 0);
// glfwMakeContextCurrent(window);
// GLContext.createFromCurrent();
// glfwShowWindow(window);
//
// setCursorPosCallback();
// setMouseCallback();
// setKeyCallback();
//
// if (window == 0) {
// throw new RuntimeException("Failed to create window");
// }
//
// GL11.glViewport(0, 0, width, height);
// }
//
// public static void setCursorPosCallback()
// {
// GLFW.glfwSetCursorPosCallback(window, (cursorPosCallback = new GLFWCursorPosCallback() {
// public void invoke(long window, double xpos, double ypos) {
// Mouse.setMouse((float)xpos, (float)ypos);
// }
// }));
// }
//
// public static void setMouseCallback()
// {
// GLFW.glfwSetMouseButtonCallback(DisplayManager.window, (DisplayManager.mouseButtonCallback = new GLFWMouseButtonCallback() {
// public void invoke(long window, int button, int action, int mods) {
// if (action == GLFW.GLFW_PRESS) {
// main.menuSystem.queueMousePass(Mouse.getX(), Mouse.getY()); //includes button == 2 i.e. scroll wheel
// if (button == 0) {
// main.inputSystem.processLeftMouseClick(Mouse.getX(), Mouse.getY());
// }
// else if (button == 1) {
// main.inputSystem.processRightMouseClick(Mouse.getX(), Mouse.getY());
// }
// main.menuSystem.forceUpdate();
// //menuSystem.closeMenus();
// }
//
// }
// }));
// }
//
// public static void setKeyCallback()
// {
// GLFW.glfwSetKeyCallback(DisplayManager.window, (DisplayManager.keyCallback = new GLFWKeyCallback() {
// public void invoke(long window, int key, int scancode, int action, int mods) {
// if (action == GLFW.GLFW_PRESS) {
// main.inputSystem.keyPressed(key);
// main.menuSystem.forceUpdate();
// //menuSystem.closeMenus();
// }
// }
// }));
// }
//
// public static void updateDisplay()
// {
// for (int i = GLFW.GLFW_KEY_0; i <= GLFW.GLFW_KEY_Z; i++)
// {
// Keyboard.keys[i] = GLFW.glfwGetKey(window, i) == GLFW.GLFW_PRESS;
// }
// /*Display.sync(120);
// Display.update();*/
// glfwPollEvents();
// glfwSwapBuffers(window);
// }
//
// public static void closeDisplay()
// {
// glfwDestroyWindow(window);
// }
//
// public static boolean requestClose()
// {
// return glfwWindowShouldClose(DisplayManager.window) == GL_TRUE;
// }
//
// }
// Path: src/lwjglEngine/fontMeshCreator/MetaFile.java
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import lwjglEngine.render.DisplayManager;
package lwjglEngine.fontMeshCreator;
/**
* Provides functionality for getting the values from a font file.
*
* @author Karl
*
*/
public class MetaFile {
/*private static final int PAD_TOP = 0;
private static final int PAD_LEFT = 1;
private static final int PAD_BOTTOM = 2;
private static final int PAD_RIGHT = 3;*/
private static final int PAD_TOP = 3;
private static final int PAD_LEFT = 3;
private static final int PAD_BOTTOM = 3;
private static final int PAD_RIGHT = 3;
private static final int DESIRED_PADDING = 3;
private static final String SPLITTER = " ";
private static final String NUMBER_SEPARATOR = ",";
private double aspectRatio;
private double verticalPerPixelSize;
private double horizontalPerPixelSize;
private double spaceWidth;
private int[] padding;
private int paddingWidth;
private int paddingHeight;
private Map<Integer, Character> metaData = new HashMap<Integer, Character>();
private BufferedReader reader;
private Map<String, String> values = new HashMap<String, String>();
/**
* Opens a font file in preparation for reading.
*
* @param file
* - the font file.
*/
protected MetaFile(File file) { | this.aspectRatio = (double) DisplayManager.width / (double) DisplayManager.height; |
dantetam/civgame | src/lwjglEngine/models/TexturedModel.java | // Path: src/lwjglEngine/textures/ModelTexture.java
// public class ModelTexture {
//
// public int textureID;
//
// public float shineDamper = 1, reflectiveness = 0;
//
// public boolean transparent = false, fastLighting = false;
//
// public ModelTexture(int id)
// {
// if (id < 0) id = 0; //-1 "default" id
// textureID = id;
// }
//
// }
| import lwjglEngine.textures.ModelTexture; | package lwjglEngine.models;
public class TexturedModel {
private RawModel rawModel; | // Path: src/lwjglEngine/textures/ModelTexture.java
// public class ModelTexture {
//
// public int textureID;
//
// public float shineDamper = 1, reflectiveness = 0;
//
// public boolean transparent = false, fastLighting = false;
//
// public ModelTexture(int id)
// {
// if (id < 0) id = 0; //-1 "default" id
// textureID = id;
// }
//
// }
// Path: src/lwjglEngine/models/TexturedModel.java
import lwjglEngine.textures.ModelTexture;
package lwjglEngine.models;
public class TexturedModel {
private RawModel rawModel; | private ModelTexture texture; |
dantetam/civgame | src/entity/Entity.java | // Path: src/data/Color.java
// public class Color {
//
// public double r,g,b;
//
// public Color(double x, double y, double z) {r = x; g = y; b = z;}
// public Color(Color c) {r = c.r; g = c.g; b = c.b;}
//
// }
| import data.Color; | package entity;
public class Entity {
public float posX, posY, posZ;
public float sizeX, sizeY, sizeZ; | // Path: src/data/Color.java
// public class Color {
//
// public double r,g,b;
//
// public Color(double x, double y, double z) {r = x; g = y; b = z;}
// public Color(Color c) {r = c.r; g = c.g; b = c.b;}
//
// }
// Path: src/entity/Entity.java
import data.Color;
package entity;
public class Entity {
public float posX, posY, posZ;
public float sizeX, sizeY, sizeZ; | public Color color; |
dantetam/civgame | src/render/Button.java | // Path: src/lwjglEngine/fontMeshCreator/FontType.java
// public class FontType {
//
// private int textureAtlas;
// private TextMeshCreator creator;
//
// /**
// * Creates a new font and loads up the data about each character from the
// * font file.
// *
// * @param textureAtlas
// * - the ID of the font atlas texture.
// * @param fontFile
// * - the font file containing information about each character in
// * the texture atlas.
// */
// public FontType(int textureAtlas, File fontFile) {
// this.textureAtlas = textureAtlas;
// this.creator = new TextMeshCreator(fontFile);
// }
//
// /**
// * @return The font texture atlas.
// */
// public int getTextureAtlas() {
// return textureAtlas;
// }
//
// /**
// * Takes in an unloaded text and calculate all of the vertices for the quads
// * on which this text will be rendered. The vertex positions and texture
// * coords and calculated based on the information from the font file.
// *
// * @param text
// * - the unloaded text.
// * @return Information about the vertices of all the quads.
// */
// public TextMeshData loadText(TextBox text) {
// return creator.createTextMesh(text);
// }
//
// }
| import java.util.ArrayList;
import lwjglEngine.fontMeshCreator.FontType; | package render;
public class Button extends TextBox {
//public float posX, posY;
//public float sizeX, sizeY;
public String command;
| // Path: src/lwjglEngine/fontMeshCreator/FontType.java
// public class FontType {
//
// private int textureAtlas;
// private TextMeshCreator creator;
//
// /**
// * Creates a new font and loads up the data about each character from the
// * font file.
// *
// * @param textureAtlas
// * - the ID of the font atlas texture.
// * @param fontFile
// * - the font file containing information about each character in
// * the texture atlas.
// */
// public FontType(int textureAtlas, File fontFile) {
// this.textureAtlas = textureAtlas;
// this.creator = new TextMeshCreator(fontFile);
// }
//
// /**
// * @return The font texture atlas.
// */
// public int getTextureAtlas() {
// return textureAtlas;
// }
//
// /**
// * Takes in an unloaded text and calculate all of the vertices for the quads
// * on which this text will be rendered. The vertex positions and texture
// * coords and calculated based on the information from the font file.
// *
// * @param text
// * - the unloaded text.
// * @return Information about the vertices of all the quads.
// */
// public TextMeshData loadText(TextBox text) {
// return creator.createTextMesh(text);
// }
//
// }
// Path: src/render/Button.java
import java.util.ArrayList;
import lwjglEngine.fontMeshCreator.FontType;
package render;
public class Button extends TextBox {
//public float posX, posY;
//public float sizeX, sizeY;
public String command;
| public Button(int fontSize, FontType font, int maxLineLength, boolean centered, int texture, String command, String display, String tooltip, float a, float b, float c, float d) { |
dantetam/civgame | src/lwjglEngine/entities/Camera.java | // Path: src/lwjglEngine/gui/Keyboard.java
// public class Keyboard {
//
// public static boolean[] keys = new boolean[200];
//
// public static boolean isKeyDown(int key)
// {
// return keys[key];
// }
//
// }
| import org.lwjgl.glfw.GLFW;
import org.lwjgl.util.vector.Vector3f;
import lwjglEngine.gui.Keyboard; | package lwjglEngine.entities;
//There is no real camera in OpenGL
//Every object in the world must be moved in the opposite direction of the camera's movement
public class Camera {
public Vector3f position = new Vector3f(500, 100, 500);
public float pitch = -10, yaw = 0, roll = 0; // High-low, left-right, tilt
private float jerkPitch, jerkYaw;
private int turnsPitch, turnsYaw;
private static final float LOWER_BOUND_Y = 40, UPPER_BOUND_Y = 400;
public Camera() {
}
// public Camera(Vector3f p, float a, float b, float c) {}
// Allow the user to focus on the point (x, z) from a top-view perspective
public void focusCamera(float x, float z, float angPitch) {
float distanceBack = Math.abs(position.y / (float) Math.tan(angPitch));
position = new Vector3f(x, position.y, z + distanceBack);
turnsPitch = 20;
turnsYaw = 20;
// jerkPitch =
// -(pitch-(float)Math.toDegrees(Math.atan(position.y/20F)))/(float)turnsPitch;
jerkPitch = -(pitch + angPitch) / (float) turnsPitch;
jerkYaw = -(yaw) / (float) turnsYaw;
// pitch = 0; yaw = 0; roll = 0;
}
public void move() {
if (turnsPitch > 0 || turnsYaw > 0) {
if (turnsPitch > 0) {
pitch += jerkPitch;
turnsPitch--;
}
if (turnsYaw > 0) {
yaw += jerkYaw;
turnsYaw--;
}
return; // Override keyboard when camera is being shifted
}
float step = 5f, tilt = 1f; | // Path: src/lwjglEngine/gui/Keyboard.java
// public class Keyboard {
//
// public static boolean[] keys = new boolean[200];
//
// public static boolean isKeyDown(int key)
// {
// return keys[key];
// }
//
// }
// Path: src/lwjglEngine/entities/Camera.java
import org.lwjgl.glfw.GLFW;
import org.lwjgl.util.vector.Vector3f;
import lwjglEngine.gui.Keyboard;
package lwjglEngine.entities;
//There is no real camera in OpenGL
//Every object in the world must be moved in the opposite direction of the camera's movement
public class Camera {
public Vector3f position = new Vector3f(500, 100, 500);
public float pitch = -10, yaw = 0, roll = 0; // High-low, left-right, tilt
private float jerkPitch, jerkYaw;
private int turnsPitch, turnsYaw;
private static final float LOWER_BOUND_Y = 40, UPPER_BOUND_Y = 400;
public Camera() {
}
// public Camera(Vector3f p, float a, float b, float c) {}
// Allow the user to focus on the point (x, z) from a top-view perspective
public void focusCamera(float x, float z, float angPitch) {
float distanceBack = Math.abs(position.y / (float) Math.tan(angPitch));
position = new Vector3f(x, position.y, z + distanceBack);
turnsPitch = 20;
turnsYaw = 20;
// jerkPitch =
// -(pitch-(float)Math.toDegrees(Math.atan(position.y/20F)))/(float)turnsPitch;
jerkPitch = -(pitch + angPitch) / (float) turnsPitch;
jerkYaw = -(yaw) / (float) turnsYaw;
// pitch = 0; yaw = 0; roll = 0;
}
public void move() {
if (turnsPitch > 0 || turnsYaw > 0) {
if (turnsPitch > 0) {
pitch += jerkPitch;
turnsPitch--;
}
if (turnsYaw > 0) {
yaw += jerkYaw;
turnsYaw--;
}
return; // Override keyboard when camera is being shifted
}
float step = 5f, tilt = 1f; | if (Keyboard.isKeyDown(GLFW.GLFW_KEY_I)) { |
dantetam/civgame | src/lwjglEngine/entities/Group.java | // Path: src/vector/Vector3f.java
// public class Vector3f {
// public float x, y, z;
//
// public Vector3f(float a, float b, float c) {
// x = a;
// y = b;
// z = c;
// }
//
// public boolean equals(Object obj) {
// if (!(obj instanceof Vector3f)) return false;
// Vector3f v = (Vector3f) obj;
// return x == v.x && y == v.y && z == v.z;
// }
//
// public int hashCode() {
// int hash = 17;
// hash = hash * 31 + (int) (x * 127);
// hash = hash * 31 + (int) (y * 127);
// hash = hash * 31 + (int) (z * 127);
// return hash;
// }
//
// public String toString() {
// return x + " " + y + " " + z;
// }
//
// public float dist(Vector3f v) {
// return (float) Math.sqrt(Math.pow(x - v.x, 2) + Math.pow(y - v.y, 2) + Math.pow(z - v.z, 2));
// }
//
// public void scale(float f) {
// x *= f;
// y *= f;
// z *= f;
// }
//
// public Vector3f scaled(float f) {
// Vector3f result = new Vector3f(x, y, z);
// result.scale(f);
// return result;
// }
//
// public float magnitude() {
// return (float) Math.sqrt(x * x + y * y + z * z);
// }
//
// public Vector3f normalized() {
// float m = magnitude();
// return new Vector3f(x / m, y / m, z / m);
// }
// }
| import java.util.ArrayList;
import vector.Vector3f; | package lwjglEngine.entities;
public class Group {
public ArrayList<Entity> entities; | // Path: src/vector/Vector3f.java
// public class Vector3f {
// public float x, y, z;
//
// public Vector3f(float a, float b, float c) {
// x = a;
// y = b;
// z = c;
// }
//
// public boolean equals(Object obj) {
// if (!(obj instanceof Vector3f)) return false;
// Vector3f v = (Vector3f) obj;
// return x == v.x && y == v.y && z == v.z;
// }
//
// public int hashCode() {
// int hash = 17;
// hash = hash * 31 + (int) (x * 127);
// hash = hash * 31 + (int) (y * 127);
// hash = hash * 31 + (int) (z * 127);
// return hash;
// }
//
// public String toString() {
// return x + " " + y + " " + z;
// }
//
// public float dist(Vector3f v) {
// return (float) Math.sqrt(Math.pow(x - v.x, 2) + Math.pow(y - v.y, 2) + Math.pow(z - v.z, 2));
// }
//
// public void scale(float f) {
// x *= f;
// y *= f;
// z *= f;
// }
//
// public Vector3f scaled(float f) {
// Vector3f result = new Vector3f(x, y, z);
// result.scale(f);
// return result;
// }
//
// public float magnitude() {
// return (float) Math.sqrt(x * x + y * y + z * z);
// }
//
// public Vector3f normalized() {
// float m = magnitude();
// return new Vector3f(x / m, y / m, z / m);
// }
// }
// Path: src/lwjglEngine/entities/Group.java
import java.util.ArrayList;
import vector.Vector3f;
package lwjglEngine.entities;
public class Group {
public ArrayList<Entity> entities; | public Vector3f position = new Vector3f(0,0,0); |
dantetam/civgame | src/render/Menu.java | // Path: src/lwjglEngine/fontMeshCreator/FontType.java
// public class FontType {
//
// private int textureAtlas;
// private TextMeshCreator creator;
//
// /**
// * Creates a new font and loads up the data about each character from the
// * font file.
// *
// * @param textureAtlas
// * - the ID of the font atlas texture.
// * @param fontFile
// * - the font file containing information about each character in
// * the texture atlas.
// */
// public FontType(int textureAtlas, File fontFile) {
// this.textureAtlas = textureAtlas;
// this.creator = new TextMeshCreator(fontFile);
// }
//
// /**
// * @return The font texture atlas.
// */
// public int getTextureAtlas() {
// return textureAtlas;
// }
//
// /**
// * Takes in an unloaded text and calculate all of the vertices for the quads
// * on which this text will be rendered. The vertex positions and texture
// * coords and calculated based on the information from the font file.
// *
// * @param text
// * - the unloaded text.
// * @return Information about the vertices of all the quads.
// */
// public TextMeshData loadText(TextBox text) {
// return creator.createTextMesh(text);
// }
//
// }
| import java.util.ArrayList;
import org.lwjgl.util.vector.Vector2f;
import lwjglEngine.fontMeshCreator.FontType; | package render;
public class Menu {
public ArrayList<TextBox> buttons;
public String name;
private boolean active;
public boolean noShortcuts = false;
public Menu(String name)
{
this.name = name;
buttons = new ArrayList<TextBox>();
active = false;
}
/*public TextBox addButton(String command, String display, String tooltip, float a, float b, float c, float d)
{
Button temp = new Button(12,null,display.length(),true,-1,command,display,tooltip,a,b,c,d);
temp.menu = this;
buttons.add(temp);
return temp;
}*/
public TextBox addButton(int texture, String command, String display, String tooltip, float a, float b, float c, float d)
{
Button temp = new Button(12,null,display.length(),true,texture,command,display,tooltip,a,b,c,d);
temp.menu = this;
buttons.add(temp);
return temp;
}
| // Path: src/lwjglEngine/fontMeshCreator/FontType.java
// public class FontType {
//
// private int textureAtlas;
// private TextMeshCreator creator;
//
// /**
// * Creates a new font and loads up the data about each character from the
// * font file.
// *
// * @param textureAtlas
// * - the ID of the font atlas texture.
// * @param fontFile
// * - the font file containing information about each character in
// * the texture atlas.
// */
// public FontType(int textureAtlas, File fontFile) {
// this.textureAtlas = textureAtlas;
// this.creator = new TextMeshCreator(fontFile);
// }
//
// /**
// * @return The font texture atlas.
// */
// public int getTextureAtlas() {
// return textureAtlas;
// }
//
// /**
// * Takes in an unloaded text and calculate all of the vertices for the quads
// * on which this text will be rendered. The vertex positions and texture
// * coords and calculated based on the information from the font file.
// *
// * @param text
// * - the unloaded text.
// * @return Information about the vertices of all the quads.
// */
// public TextMeshData loadText(TextBox text) {
// return creator.createTextMesh(text);
// }
//
// }
// Path: src/render/Menu.java
import java.util.ArrayList;
import org.lwjgl.util.vector.Vector2f;
import lwjglEngine.fontMeshCreator.FontType;
package render;
public class Menu {
public ArrayList<TextBox> buttons;
public String name;
private boolean active;
public boolean noShortcuts = false;
public Menu(String name)
{
this.name = name;
buttons = new ArrayList<TextBox>();
active = false;
}
/*public TextBox addButton(String command, String display, String tooltip, float a, float b, float c, float d)
{
Button temp = new Button(12,null,display.length(),true,-1,command,display,tooltip,a,b,c,d);
temp.menu = this;
buttons.add(temp);
return temp;
}*/
public TextBox addButton(int texture, String command, String display, String tooltip, float a, float b, float c, float d)
{
Button temp = new Button(12,null,display.length(),true,texture,command,display,tooltip,a,b,c,d);
temp.menu = this;
buttons.add(temp);
return temp;
}
| public TextBox addButton(int w, FontType x, int y, boolean z, int texture, String command, String display, String tooltip, float a, float b, float c, float d) |
dantetam/civgame | src/lwjglEngine/gui/GuiTexture.java | // Path: src/lwjglEngine/render/DisplayManager.java
// public class DisplayManager {
//
// public static final int width = (int) CivGame.WIDTH, height = (int) CivGame.HEIGHT;
// public static long window;
// public static CivGame main;
//
// //Store the callbacks in memory
// private static GLFWErrorCallback errorCallback;
// public static GLFWKeyCallback keyCallback;
// private static GLFWCursorPosCallback cursorPosCallback;
// public static GLFWMouseButtonCallback mouseButtonCallback;
//
// public DisplayManager(CivGame m)
// {
// main = m;
// }
//
// public static void createDisplay()
// {
// glfwInit();
// glfwSetErrorCallback(errorCallback = Callbacks.errorCallbackPrint(System.err));
//
// glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);
// glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
// glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
// glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
// window = glfwCreateWindow(width, height, "", 0, 0);
// glfwMakeContextCurrent(window);
// GLContext.createFromCurrent();
// glfwShowWindow(window);
//
// setCursorPosCallback();
// setMouseCallback();
// setKeyCallback();
//
// if (window == 0) {
// throw new RuntimeException("Failed to create window");
// }
//
// GL11.glViewport(0, 0, width, height);
// }
//
// public static void setCursorPosCallback()
// {
// GLFW.glfwSetCursorPosCallback(window, (cursorPosCallback = new GLFWCursorPosCallback() {
// public void invoke(long window, double xpos, double ypos) {
// Mouse.setMouse((float)xpos, (float)ypos);
// }
// }));
// }
//
// public static void setMouseCallback()
// {
// GLFW.glfwSetMouseButtonCallback(DisplayManager.window, (DisplayManager.mouseButtonCallback = new GLFWMouseButtonCallback() {
// public void invoke(long window, int button, int action, int mods) {
// if (action == GLFW.GLFW_PRESS) {
// main.menuSystem.queueMousePass(Mouse.getX(), Mouse.getY()); //includes button == 2 i.e. scroll wheel
// if (button == 0) {
// main.inputSystem.processLeftMouseClick(Mouse.getX(), Mouse.getY());
// }
// else if (button == 1) {
// main.inputSystem.processRightMouseClick(Mouse.getX(), Mouse.getY());
// }
// main.menuSystem.forceUpdate();
// //menuSystem.closeMenus();
// }
//
// }
// }));
// }
//
// public static void setKeyCallback()
// {
// GLFW.glfwSetKeyCallback(DisplayManager.window, (DisplayManager.keyCallback = new GLFWKeyCallback() {
// public void invoke(long window, int key, int scancode, int action, int mods) {
// if (action == GLFW.GLFW_PRESS) {
// main.inputSystem.keyPressed(key);
// main.menuSystem.forceUpdate();
// //menuSystem.closeMenus();
// }
// }
// }));
// }
//
// public static void updateDisplay()
// {
// for (int i = GLFW.GLFW_KEY_0; i <= GLFW.GLFW_KEY_Z; i++)
// {
// Keyboard.keys[i] = GLFW.glfwGetKey(window, i) == GLFW.GLFW_PRESS;
// }
// /*Display.sync(120);
// Display.update();*/
// glfwPollEvents();
// glfwSwapBuffers(window);
// }
//
// public static void closeDisplay()
// {
// glfwDestroyWindow(window);
// }
//
// public static boolean requestClose()
// {
// return glfwWindowShouldClose(DisplayManager.window) == GL_TRUE;
// }
//
// }
| import org.lwjgl.util.vector.Vector2f;
import org.lwjgl.util.vector.Vector4f;
import lwjglEngine.render.DisplayManager; | package lwjglEngine.gui;
//Completely scrap t
public class GuiTexture {
public int texture;
public Vector2f pos, size;
public Vector2f origPos;
public Vector2f pixelPos, pixelSize;
public boolean active = true;
public Vector4f color = new Vector4f(0, 0, 0, 255);
public GuiTexture(int t, Vector2f p, Vector2f s) {
texture = t;
pixelPos = p;
pixelSize = s;
origPos = p; | // Path: src/lwjglEngine/render/DisplayManager.java
// public class DisplayManager {
//
// public static final int width = (int) CivGame.WIDTH, height = (int) CivGame.HEIGHT;
// public static long window;
// public static CivGame main;
//
// //Store the callbacks in memory
// private static GLFWErrorCallback errorCallback;
// public static GLFWKeyCallback keyCallback;
// private static GLFWCursorPosCallback cursorPosCallback;
// public static GLFWMouseButtonCallback mouseButtonCallback;
//
// public DisplayManager(CivGame m)
// {
// main = m;
// }
//
// public static void createDisplay()
// {
// glfwInit();
// glfwSetErrorCallback(errorCallback = Callbacks.errorCallbackPrint(System.err));
//
// glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);
// glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
// glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
// glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
// window = glfwCreateWindow(width, height, "", 0, 0);
// glfwMakeContextCurrent(window);
// GLContext.createFromCurrent();
// glfwShowWindow(window);
//
// setCursorPosCallback();
// setMouseCallback();
// setKeyCallback();
//
// if (window == 0) {
// throw new RuntimeException("Failed to create window");
// }
//
// GL11.glViewport(0, 0, width, height);
// }
//
// public static void setCursorPosCallback()
// {
// GLFW.glfwSetCursorPosCallback(window, (cursorPosCallback = new GLFWCursorPosCallback() {
// public void invoke(long window, double xpos, double ypos) {
// Mouse.setMouse((float)xpos, (float)ypos);
// }
// }));
// }
//
// public static void setMouseCallback()
// {
// GLFW.glfwSetMouseButtonCallback(DisplayManager.window, (DisplayManager.mouseButtonCallback = new GLFWMouseButtonCallback() {
// public void invoke(long window, int button, int action, int mods) {
// if (action == GLFW.GLFW_PRESS) {
// main.menuSystem.queueMousePass(Mouse.getX(), Mouse.getY()); //includes button == 2 i.e. scroll wheel
// if (button == 0) {
// main.inputSystem.processLeftMouseClick(Mouse.getX(), Mouse.getY());
// }
// else if (button == 1) {
// main.inputSystem.processRightMouseClick(Mouse.getX(), Mouse.getY());
// }
// main.menuSystem.forceUpdate();
// //menuSystem.closeMenus();
// }
//
// }
// }));
// }
//
// public static void setKeyCallback()
// {
// GLFW.glfwSetKeyCallback(DisplayManager.window, (DisplayManager.keyCallback = new GLFWKeyCallback() {
// public void invoke(long window, int key, int scancode, int action, int mods) {
// if (action == GLFW.GLFW_PRESS) {
// main.inputSystem.keyPressed(key);
// main.menuSystem.forceUpdate();
// //menuSystem.closeMenus();
// }
// }
// }));
// }
//
// public static void updateDisplay()
// {
// for (int i = GLFW.GLFW_KEY_0; i <= GLFW.GLFW_KEY_Z; i++)
// {
// Keyboard.keys[i] = GLFW.glfwGetKey(window, i) == GLFW.GLFW_PRESS;
// }
// /*Display.sync(120);
// Display.update();*/
// glfwPollEvents();
// glfwSwapBuffers(window);
// }
//
// public static void closeDisplay()
// {
// glfwDestroyWindow(window);
// }
//
// public static boolean requestClose()
// {
// return glfwWindowShouldClose(DisplayManager.window) == GL_TRUE;
// }
//
// }
// Path: src/lwjglEngine/gui/GuiTexture.java
import org.lwjgl.util.vector.Vector2f;
import org.lwjgl.util.vector.Vector4f;
import lwjglEngine.render.DisplayManager;
package lwjglEngine.gui;
//Completely scrap t
public class GuiTexture {
public int texture;
public Vector2f pos, size;
public Vector2f origPos;
public Vector2f pixelPos, pixelSize;
public boolean active = true;
public Vector4f color = new Vector4f(0, 0, 0, 255);
public GuiTexture(int t, Vector2f p, Vector2f s) {
texture = t;
pixelPos = p;
pixelSize = s;
origPos = p; | pos = new Vector2f(p.x / DisplayManager.width, p.y / DisplayManager.height); |
mars3142/toaster | app/src/main/java/org/mars3142/android/toaster/loader/PackageLoader.java | // Path: app/src/main/java/org/mars3142/android/toaster/data/PackageEntry.java
// public class PackageEntry {
//
// private ApplicationInfo mInfo;
//
// private File mApkFile;
// private String mLabel;
// private Drawable mIcon;
// private Boolean mMounted;
//
// public PackageEntry(ApplicationInfo applicationInfo) {
// mInfo = applicationInfo;
// mApkFile = new File(mInfo.sourceDir);
// }
//
// public String getPackageName() {
// if (mInfo != null) {
// return mInfo.packageName;
// }
//
// return null;
// }
//
// public String getLabel(Context context) {
// if (mLabel == null || !mMounted) {
// if (!mApkFile.exists()) {
// mMounted = false;
// mLabel = mInfo.packageName;
// } else {
// mMounted = true;
// CharSequence label = mInfo.loadLabel(context.getPackageManager());
// mLabel = label != null ? label.toString() : mInfo.packageName;
// }
// }
//
// return mLabel;
// }
//
// @TargetApi(Build.VERSION_CODES.LOLLIPOP)
// public Drawable getIcon(Context context) {
// if (mIcon == null) {
// if (mApkFile.exists()) {
// mIcon = mInfo.loadIcon(context.getPackageManager());
// return mIcon;
// } else {
// mMounted = false;
// }
// } else if (!mMounted) {
// if (mApkFile.exists()) {
// mMounted = true;
// mIcon = mInfo.loadIcon(context.getPackageManager());
// return mIcon;
// }
// } else {
// return mIcon;
// }
//
// Drawable drawable;
// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
// drawable = context.getDrawable(android.R.drawable.sym_def_app_icon);
// } else {
// drawable = context.getResources().getDrawable(android.R.drawable.sym_def_app_icon);
// }
// return drawable;
// }
//
// @Override
// public String toString() {
// return mLabel;
// }
// }
//
// Path: app/src/main/java/org/mars3142/android/toaster/observer/InstalledAppsObserver.java
// public class InstalledAppsObserver extends BroadcastReceiver {
//
// private PackageLoader mLoader;
//
// public InstalledAppsObserver(PackageLoader loader) {
// mLoader = loader;
//
// IntentFilter filter = new IntentFilter();
// filter.addAction(Intent.ACTION_PACKAGE_ADDED);
// filter.addAction(Intent.ACTION_PACKAGE_REMOVED);
// filter.addAction(Intent.ACTION_PACKAGE_CHANGED);
// filter.addDataScheme("package");
// mLoader.getContext().registerReceiver(this, filter);
//
// IntentFilter sdFilter = new IntentFilter();
// sdFilter.addAction(Intent.ACTION_EXTERNAL_APPLICATIONS_AVAILABLE);
// sdFilter.addAction(Intent.ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE);
// mLoader.getContext().registerReceiver(this, sdFilter);
// }
//
// @Override
// public void onReceive(Context context, Intent intent) {
// mLoader.onContentChanged();
// }
// }
//
// Path: app/src/main/java/org/mars3142/android/toaster/observer/SystemLocalObserver.java
// public class SystemLocalObserver extends BroadcastReceiver {
//
// private PackageLoader mLoader;
//
// public SystemLocalObserver(PackageLoader loader) {
// mLoader = loader;
//
// IntentFilter filter = new IntentFilter();
// filter.addAction(Intent.ACTION_LOCALE_CHANGED);
// mLoader.getContext().registerReceiver(this, filter);
// }
//
// @Override
// public void onReceive(Context context, Intent intent) {
// mLoader.onContentChanged();
// }
// }
| import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import android.content.AsyncTaskLoader;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.os.Bundle;
import org.mars3142.android.toaster.data.PackageEntry;
import org.mars3142.android.toaster.observer.InstalledAppsObserver;
import org.mars3142.android.toaster.observer.SystemLocalObserver;
import java.util.ArrayList; | /*
* This file is part of Toaster
*
* Copyright (c) 2014, 2017 Peter Siegmund
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.mars3142.android.toaster.loader;
/**
* @author mars3142
*
* inspired by https://github.com/alexjlockwood/AppListLoader/blob/master/src/com/adp/loadercustom/loader/AppListLoader.java
*/
public class PackageLoader extends AsyncTaskLoader<PackageEntry[]> {
/**
* Key for source param
*/
public static final String SOURCE = "source";
/**
* Parameter SOURCE is for apps
*/
public static final int SOURCE_APPS = 0;
/**
* Parameter SOURCE is for database
*/
public static final int SOURCE_DATABASE = 1;
private int mSource;
private PackageManager mManager; | // Path: app/src/main/java/org/mars3142/android/toaster/data/PackageEntry.java
// public class PackageEntry {
//
// private ApplicationInfo mInfo;
//
// private File mApkFile;
// private String mLabel;
// private Drawable mIcon;
// private Boolean mMounted;
//
// public PackageEntry(ApplicationInfo applicationInfo) {
// mInfo = applicationInfo;
// mApkFile = new File(mInfo.sourceDir);
// }
//
// public String getPackageName() {
// if (mInfo != null) {
// return mInfo.packageName;
// }
//
// return null;
// }
//
// public String getLabel(Context context) {
// if (mLabel == null || !mMounted) {
// if (!mApkFile.exists()) {
// mMounted = false;
// mLabel = mInfo.packageName;
// } else {
// mMounted = true;
// CharSequence label = mInfo.loadLabel(context.getPackageManager());
// mLabel = label != null ? label.toString() : mInfo.packageName;
// }
// }
//
// return mLabel;
// }
//
// @TargetApi(Build.VERSION_CODES.LOLLIPOP)
// public Drawable getIcon(Context context) {
// if (mIcon == null) {
// if (mApkFile.exists()) {
// mIcon = mInfo.loadIcon(context.getPackageManager());
// return mIcon;
// } else {
// mMounted = false;
// }
// } else if (!mMounted) {
// if (mApkFile.exists()) {
// mMounted = true;
// mIcon = mInfo.loadIcon(context.getPackageManager());
// return mIcon;
// }
// } else {
// return mIcon;
// }
//
// Drawable drawable;
// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
// drawable = context.getDrawable(android.R.drawable.sym_def_app_icon);
// } else {
// drawable = context.getResources().getDrawable(android.R.drawable.sym_def_app_icon);
// }
// return drawable;
// }
//
// @Override
// public String toString() {
// return mLabel;
// }
// }
//
// Path: app/src/main/java/org/mars3142/android/toaster/observer/InstalledAppsObserver.java
// public class InstalledAppsObserver extends BroadcastReceiver {
//
// private PackageLoader mLoader;
//
// public InstalledAppsObserver(PackageLoader loader) {
// mLoader = loader;
//
// IntentFilter filter = new IntentFilter();
// filter.addAction(Intent.ACTION_PACKAGE_ADDED);
// filter.addAction(Intent.ACTION_PACKAGE_REMOVED);
// filter.addAction(Intent.ACTION_PACKAGE_CHANGED);
// filter.addDataScheme("package");
// mLoader.getContext().registerReceiver(this, filter);
//
// IntentFilter sdFilter = new IntentFilter();
// sdFilter.addAction(Intent.ACTION_EXTERNAL_APPLICATIONS_AVAILABLE);
// sdFilter.addAction(Intent.ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE);
// mLoader.getContext().registerReceiver(this, sdFilter);
// }
//
// @Override
// public void onReceive(Context context, Intent intent) {
// mLoader.onContentChanged();
// }
// }
//
// Path: app/src/main/java/org/mars3142/android/toaster/observer/SystemLocalObserver.java
// public class SystemLocalObserver extends BroadcastReceiver {
//
// private PackageLoader mLoader;
//
// public SystemLocalObserver(PackageLoader loader) {
// mLoader = loader;
//
// IntentFilter filter = new IntentFilter();
// filter.addAction(Intent.ACTION_LOCALE_CHANGED);
// mLoader.getContext().registerReceiver(this, filter);
// }
//
// @Override
// public void onReceive(Context context, Intent intent) {
// mLoader.onContentChanged();
// }
// }
// Path: app/src/main/java/org/mars3142/android/toaster/loader/PackageLoader.java
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import android.content.AsyncTaskLoader;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.os.Bundle;
import org.mars3142.android.toaster.data.PackageEntry;
import org.mars3142.android.toaster.observer.InstalledAppsObserver;
import org.mars3142.android.toaster.observer.SystemLocalObserver;
import java.util.ArrayList;
/*
* This file is part of Toaster
*
* Copyright (c) 2014, 2017 Peter Siegmund
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.mars3142.android.toaster.loader;
/**
* @author mars3142
*
* inspired by https://github.com/alexjlockwood/AppListLoader/blob/master/src/com/adp/loadercustom/loader/AppListLoader.java
*/
public class PackageLoader extends AsyncTaskLoader<PackageEntry[]> {
/**
* Key for source param
*/
public static final String SOURCE = "source";
/**
* Parameter SOURCE is for apps
*/
public static final int SOURCE_APPS = 0;
/**
* Parameter SOURCE is for database
*/
public static final int SOURCE_DATABASE = 1;
private int mSource;
private PackageManager mManager; | private InstalledAppsObserver mAppsObserver; |
mars3142/toaster | app/src/main/java/org/mars3142/android/toaster/loader/PackageLoader.java | // Path: app/src/main/java/org/mars3142/android/toaster/data/PackageEntry.java
// public class PackageEntry {
//
// private ApplicationInfo mInfo;
//
// private File mApkFile;
// private String mLabel;
// private Drawable mIcon;
// private Boolean mMounted;
//
// public PackageEntry(ApplicationInfo applicationInfo) {
// mInfo = applicationInfo;
// mApkFile = new File(mInfo.sourceDir);
// }
//
// public String getPackageName() {
// if (mInfo != null) {
// return mInfo.packageName;
// }
//
// return null;
// }
//
// public String getLabel(Context context) {
// if (mLabel == null || !mMounted) {
// if (!mApkFile.exists()) {
// mMounted = false;
// mLabel = mInfo.packageName;
// } else {
// mMounted = true;
// CharSequence label = mInfo.loadLabel(context.getPackageManager());
// mLabel = label != null ? label.toString() : mInfo.packageName;
// }
// }
//
// return mLabel;
// }
//
// @TargetApi(Build.VERSION_CODES.LOLLIPOP)
// public Drawable getIcon(Context context) {
// if (mIcon == null) {
// if (mApkFile.exists()) {
// mIcon = mInfo.loadIcon(context.getPackageManager());
// return mIcon;
// } else {
// mMounted = false;
// }
// } else if (!mMounted) {
// if (mApkFile.exists()) {
// mMounted = true;
// mIcon = mInfo.loadIcon(context.getPackageManager());
// return mIcon;
// }
// } else {
// return mIcon;
// }
//
// Drawable drawable;
// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
// drawable = context.getDrawable(android.R.drawable.sym_def_app_icon);
// } else {
// drawable = context.getResources().getDrawable(android.R.drawable.sym_def_app_icon);
// }
// return drawable;
// }
//
// @Override
// public String toString() {
// return mLabel;
// }
// }
//
// Path: app/src/main/java/org/mars3142/android/toaster/observer/InstalledAppsObserver.java
// public class InstalledAppsObserver extends BroadcastReceiver {
//
// private PackageLoader mLoader;
//
// public InstalledAppsObserver(PackageLoader loader) {
// mLoader = loader;
//
// IntentFilter filter = new IntentFilter();
// filter.addAction(Intent.ACTION_PACKAGE_ADDED);
// filter.addAction(Intent.ACTION_PACKAGE_REMOVED);
// filter.addAction(Intent.ACTION_PACKAGE_CHANGED);
// filter.addDataScheme("package");
// mLoader.getContext().registerReceiver(this, filter);
//
// IntentFilter sdFilter = new IntentFilter();
// sdFilter.addAction(Intent.ACTION_EXTERNAL_APPLICATIONS_AVAILABLE);
// sdFilter.addAction(Intent.ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE);
// mLoader.getContext().registerReceiver(this, sdFilter);
// }
//
// @Override
// public void onReceive(Context context, Intent intent) {
// mLoader.onContentChanged();
// }
// }
//
// Path: app/src/main/java/org/mars3142/android/toaster/observer/SystemLocalObserver.java
// public class SystemLocalObserver extends BroadcastReceiver {
//
// private PackageLoader mLoader;
//
// public SystemLocalObserver(PackageLoader loader) {
// mLoader = loader;
//
// IntentFilter filter = new IntentFilter();
// filter.addAction(Intent.ACTION_LOCALE_CHANGED);
// mLoader.getContext().registerReceiver(this, filter);
// }
//
// @Override
// public void onReceive(Context context, Intent intent) {
// mLoader.onContentChanged();
// }
// }
| import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import android.content.AsyncTaskLoader;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.os.Bundle;
import org.mars3142.android.toaster.data.PackageEntry;
import org.mars3142.android.toaster.observer.InstalledAppsObserver;
import org.mars3142.android.toaster.observer.SystemLocalObserver;
import java.util.ArrayList; | /*
* This file is part of Toaster
*
* Copyright (c) 2014, 2017 Peter Siegmund
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.mars3142.android.toaster.loader;
/**
* @author mars3142
*
* inspired by https://github.com/alexjlockwood/AppListLoader/blob/master/src/com/adp/loadercustom/loader/AppListLoader.java
*/
public class PackageLoader extends AsyncTaskLoader<PackageEntry[]> {
/**
* Key for source param
*/
public static final String SOURCE = "source";
/**
* Parameter SOURCE is for apps
*/
public static final int SOURCE_APPS = 0;
/**
* Parameter SOURCE is for database
*/
public static final int SOURCE_DATABASE = 1;
private int mSource;
private PackageManager mManager;
private InstalledAppsObserver mAppsObserver; | // Path: app/src/main/java/org/mars3142/android/toaster/data/PackageEntry.java
// public class PackageEntry {
//
// private ApplicationInfo mInfo;
//
// private File mApkFile;
// private String mLabel;
// private Drawable mIcon;
// private Boolean mMounted;
//
// public PackageEntry(ApplicationInfo applicationInfo) {
// mInfo = applicationInfo;
// mApkFile = new File(mInfo.sourceDir);
// }
//
// public String getPackageName() {
// if (mInfo != null) {
// return mInfo.packageName;
// }
//
// return null;
// }
//
// public String getLabel(Context context) {
// if (mLabel == null || !mMounted) {
// if (!mApkFile.exists()) {
// mMounted = false;
// mLabel = mInfo.packageName;
// } else {
// mMounted = true;
// CharSequence label = mInfo.loadLabel(context.getPackageManager());
// mLabel = label != null ? label.toString() : mInfo.packageName;
// }
// }
//
// return mLabel;
// }
//
// @TargetApi(Build.VERSION_CODES.LOLLIPOP)
// public Drawable getIcon(Context context) {
// if (mIcon == null) {
// if (mApkFile.exists()) {
// mIcon = mInfo.loadIcon(context.getPackageManager());
// return mIcon;
// } else {
// mMounted = false;
// }
// } else if (!mMounted) {
// if (mApkFile.exists()) {
// mMounted = true;
// mIcon = mInfo.loadIcon(context.getPackageManager());
// return mIcon;
// }
// } else {
// return mIcon;
// }
//
// Drawable drawable;
// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
// drawable = context.getDrawable(android.R.drawable.sym_def_app_icon);
// } else {
// drawable = context.getResources().getDrawable(android.R.drawable.sym_def_app_icon);
// }
// return drawable;
// }
//
// @Override
// public String toString() {
// return mLabel;
// }
// }
//
// Path: app/src/main/java/org/mars3142/android/toaster/observer/InstalledAppsObserver.java
// public class InstalledAppsObserver extends BroadcastReceiver {
//
// private PackageLoader mLoader;
//
// public InstalledAppsObserver(PackageLoader loader) {
// mLoader = loader;
//
// IntentFilter filter = new IntentFilter();
// filter.addAction(Intent.ACTION_PACKAGE_ADDED);
// filter.addAction(Intent.ACTION_PACKAGE_REMOVED);
// filter.addAction(Intent.ACTION_PACKAGE_CHANGED);
// filter.addDataScheme("package");
// mLoader.getContext().registerReceiver(this, filter);
//
// IntentFilter sdFilter = new IntentFilter();
// sdFilter.addAction(Intent.ACTION_EXTERNAL_APPLICATIONS_AVAILABLE);
// sdFilter.addAction(Intent.ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE);
// mLoader.getContext().registerReceiver(this, sdFilter);
// }
//
// @Override
// public void onReceive(Context context, Intent intent) {
// mLoader.onContentChanged();
// }
// }
//
// Path: app/src/main/java/org/mars3142/android/toaster/observer/SystemLocalObserver.java
// public class SystemLocalObserver extends BroadcastReceiver {
//
// private PackageLoader mLoader;
//
// public SystemLocalObserver(PackageLoader loader) {
// mLoader = loader;
//
// IntentFilter filter = new IntentFilter();
// filter.addAction(Intent.ACTION_LOCALE_CHANGED);
// mLoader.getContext().registerReceiver(this, filter);
// }
//
// @Override
// public void onReceive(Context context, Intent intent) {
// mLoader.onContentChanged();
// }
// }
// Path: app/src/main/java/org/mars3142/android/toaster/loader/PackageLoader.java
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import android.content.AsyncTaskLoader;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.os.Bundle;
import org.mars3142.android.toaster.data.PackageEntry;
import org.mars3142.android.toaster.observer.InstalledAppsObserver;
import org.mars3142.android.toaster.observer.SystemLocalObserver;
import java.util.ArrayList;
/*
* This file is part of Toaster
*
* Copyright (c) 2014, 2017 Peter Siegmund
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.mars3142.android.toaster.loader;
/**
* @author mars3142
*
* inspired by https://github.com/alexjlockwood/AppListLoader/blob/master/src/com/adp/loadercustom/loader/AppListLoader.java
*/
public class PackageLoader extends AsyncTaskLoader<PackageEntry[]> {
/**
* Key for source param
*/
public static final String SOURCE = "source";
/**
* Parameter SOURCE is for apps
*/
public static final int SOURCE_APPS = 0;
/**
* Parameter SOURCE is for database
*/
public static final int SOURCE_DATABASE = 1;
private int mSource;
private PackageManager mManager;
private InstalledAppsObserver mAppsObserver; | private SystemLocalObserver mLocalObserver; |
mars3142/toaster | app/src/main/java/org/mars3142/android/toaster/adapter/PackageRecyclerAdapter.java | // Path: app/src/main/java/org/mars3142/android/toaster/data/PackageEntry.java
// public class PackageEntry {
//
// private ApplicationInfo mInfo;
//
// private File mApkFile;
// private String mLabel;
// private Drawable mIcon;
// private Boolean mMounted;
//
// public PackageEntry(ApplicationInfo applicationInfo) {
// mInfo = applicationInfo;
// mApkFile = new File(mInfo.sourceDir);
// }
//
// public String getPackageName() {
// if (mInfo != null) {
// return mInfo.packageName;
// }
//
// return null;
// }
//
// public String getLabel(Context context) {
// if (mLabel == null || !mMounted) {
// if (!mApkFile.exists()) {
// mMounted = false;
// mLabel = mInfo.packageName;
// } else {
// mMounted = true;
// CharSequence label = mInfo.loadLabel(context.getPackageManager());
// mLabel = label != null ? label.toString() : mInfo.packageName;
// }
// }
//
// return mLabel;
// }
//
// @TargetApi(Build.VERSION_CODES.LOLLIPOP)
// public Drawable getIcon(Context context) {
// if (mIcon == null) {
// if (mApkFile.exists()) {
// mIcon = mInfo.loadIcon(context.getPackageManager());
// return mIcon;
// } else {
// mMounted = false;
// }
// } else if (!mMounted) {
// if (mApkFile.exists()) {
// mMounted = true;
// mIcon = mInfo.loadIcon(context.getPackageManager());
// return mIcon;
// }
// } else {
// return mIcon;
// }
//
// Drawable drawable;
// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
// drawable = context.getDrawable(android.R.drawable.sym_def_app_icon);
// } else {
// drawable = context.getResources().getDrawable(android.R.drawable.sym_def_app_icon);
// }
// return drawable;
// }
//
// @Override
// public String toString() {
// return mLabel;
// }
// }
//
// Path: app/src/main/java/org/mars3142/android/toaster/viewholder/NavDrawerRecyclerViewHolder.java
// public class NavDrawerRecyclerViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
//
// private OnItemClickListener mOnItemClickListener;
// public ImageView mPackageIcon;
// public TextView mAppName;
// public String mPackageName;
//
// public NavDrawerRecyclerViewHolder(View itemView, OnItemClickListener onItemClickListener) {
// super(itemView);
//
// mOnItemClickListener = onItemClickListener;
// mAppName = (TextView) itemView.findViewById(R.id.app_name);
// mPackageIcon = (ImageView) itemView.findViewById(R.id.package_icon);
// itemView.setOnClickListener(this);
// }
//
// @Override
// public void onClick(View view) {
// if (mOnItemClickListener != null) {
// mOnItemClickListener.onItemClick(mPackageName);
// }
// }
//
// public interface OnItemClickListener {
// void onItemClick(String packageName);
// }
// }
| import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import org.mars3142.android.toaster.R;
import org.mars3142.android.toaster.data.PackageEntry;
import org.mars3142.android.toaster.viewholder.NavDrawerRecyclerViewHolder; | /*
* This file is part of Toaster
*
* Copyright (c) 2014, 2017 Peter Siegmund
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.mars3142.android.toaster.adapter;
/**
* @author mars3142
*/
public class PackageRecyclerAdapter
extends RecyclerView.Adapter<NavDrawerRecyclerViewHolder>
implements NavDrawerRecyclerViewHolder.OnItemClickListener {
private Context mContext; | // Path: app/src/main/java/org/mars3142/android/toaster/data/PackageEntry.java
// public class PackageEntry {
//
// private ApplicationInfo mInfo;
//
// private File mApkFile;
// private String mLabel;
// private Drawable mIcon;
// private Boolean mMounted;
//
// public PackageEntry(ApplicationInfo applicationInfo) {
// mInfo = applicationInfo;
// mApkFile = new File(mInfo.sourceDir);
// }
//
// public String getPackageName() {
// if (mInfo != null) {
// return mInfo.packageName;
// }
//
// return null;
// }
//
// public String getLabel(Context context) {
// if (mLabel == null || !mMounted) {
// if (!mApkFile.exists()) {
// mMounted = false;
// mLabel = mInfo.packageName;
// } else {
// mMounted = true;
// CharSequence label = mInfo.loadLabel(context.getPackageManager());
// mLabel = label != null ? label.toString() : mInfo.packageName;
// }
// }
//
// return mLabel;
// }
//
// @TargetApi(Build.VERSION_CODES.LOLLIPOP)
// public Drawable getIcon(Context context) {
// if (mIcon == null) {
// if (mApkFile.exists()) {
// mIcon = mInfo.loadIcon(context.getPackageManager());
// return mIcon;
// } else {
// mMounted = false;
// }
// } else if (!mMounted) {
// if (mApkFile.exists()) {
// mMounted = true;
// mIcon = mInfo.loadIcon(context.getPackageManager());
// return mIcon;
// }
// } else {
// return mIcon;
// }
//
// Drawable drawable;
// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
// drawable = context.getDrawable(android.R.drawable.sym_def_app_icon);
// } else {
// drawable = context.getResources().getDrawable(android.R.drawable.sym_def_app_icon);
// }
// return drawable;
// }
//
// @Override
// public String toString() {
// return mLabel;
// }
// }
//
// Path: app/src/main/java/org/mars3142/android/toaster/viewholder/NavDrawerRecyclerViewHolder.java
// public class NavDrawerRecyclerViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
//
// private OnItemClickListener mOnItemClickListener;
// public ImageView mPackageIcon;
// public TextView mAppName;
// public String mPackageName;
//
// public NavDrawerRecyclerViewHolder(View itemView, OnItemClickListener onItemClickListener) {
// super(itemView);
//
// mOnItemClickListener = onItemClickListener;
// mAppName = (TextView) itemView.findViewById(R.id.app_name);
// mPackageIcon = (ImageView) itemView.findViewById(R.id.package_icon);
// itemView.setOnClickListener(this);
// }
//
// @Override
// public void onClick(View view) {
// if (mOnItemClickListener != null) {
// mOnItemClickListener.onItemClick(mPackageName);
// }
// }
//
// public interface OnItemClickListener {
// void onItemClick(String packageName);
// }
// }
// Path: app/src/main/java/org/mars3142/android/toaster/adapter/PackageRecyclerAdapter.java
import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import org.mars3142.android.toaster.R;
import org.mars3142.android.toaster.data.PackageEntry;
import org.mars3142.android.toaster.viewholder.NavDrawerRecyclerViewHolder;
/*
* This file is part of Toaster
*
* Copyright (c) 2014, 2017 Peter Siegmund
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.mars3142.android.toaster.adapter;
/**
* @author mars3142
*/
public class PackageRecyclerAdapter
extends RecyclerView.Adapter<NavDrawerRecyclerViewHolder>
implements NavDrawerRecyclerViewHolder.OnItemClickListener {
private Context mContext; | private PackageEntry[] mPackages; |
mars3142/toaster | app/src/main/java/org/mars3142/android/toaster/adapter/NavDrawerRecyclerAdapter.java | // Path: app/src/main/java/org/mars3142/android/toaster/card/ToastCard.java
// public class ToastCard extends Card {
//
// public String message;
// public String appName;
// public String packageName;
// public String timestamp;
// public Drawable packageIcon;
// public Palette palette;
//
// private TextView mMessageTextView;
// private TextView mPackageNameTextView;
// private ImageView mPackageIconView;
// private RelativeLayout mCardBackgroundView;
//
// private static HashMap<String, Palette> mPalettes;
//
// public ToastCard(Context context) {
// super(context, R.layout.toaster_card);
//
// init();
// }
//
// public ToastCard(Context context, String packageName) {
// this(context);
//
// init();
// loadData(packageName);
// }
//
// private void init() {
// if (mPalettes == null) {
// mPalettes = new HashMap<>();
// }
// }
//
// private void loadData(String packageName) {
// if (!TextUtils.isEmpty(packageName)) {
// this.packageName = packageName;
// appName = PackageHelper.with(getContext()).getAppName(packageName);
// appName = (appName == null) ? packageName : appName;
// packageIcon = PackageHelper.with(getContext()).getIconFromPackageName(packageName);
// if (mPalettes.containsKey(packageName)) {
// palette = mPalettes.get(packageName);
// } else {
// if (packageIcon != null) {
// palette = new Palette.Builder(PackageHelper.drawableToBitmap(packageIcon)).generate();
// mPalettes.put(packageName, palette);
// }
// }
// }
// }
//
// @Override
// public void setupInnerViewElements(ViewGroup parent, View view) {
// if (mCardBackgroundView == null) {
// mCardBackgroundView = (RelativeLayout) parent.findViewById(R.id.backgroundColor);
// }
//
// if (mMessageTextView == null) {
// mMessageTextView = (TextView) parent.findViewById(R.id.message);
// }
//
// if (mPackageNameTextView == null) {
// mPackageNameTextView = (TextView) parent.findViewById(R.id.package_name);
// }
//
// if (mPackageIconView == null) {
// mPackageIconView = (ImageView) parent.findViewById(R.id.package_icon);
// }
//
// if (mCardBackgroundView != null) {
// int color = ContextCompat.getColor(getContext(), R.color.colorPrimary);
// if (palette != null) {
// color = palette.getMutedColor(color);
// }
// mCardBackgroundView.setBackgroundColor(color);
// }
//
// if (mMessageTextView != null) {
// mMessageTextView.setText(message);
// }
//
// if (mPackageNameTextView != null) {
// mPackageNameTextView.setText(appName == null ? packageName : appName);
// }
//
// if (mPackageIconView != null) {
// mPackageIconView.setImageDrawable(packageIcon);
// }
// }
// }
//
// Path: app/src/main/java/org/mars3142/android/toaster/viewholder/NavDrawerRecyclerViewHolder.java
// public class NavDrawerRecyclerViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
//
// private OnItemClickListener mOnItemClickListener;
// public ImageView mPackageIcon;
// public TextView mAppName;
// public String mPackageName;
//
// public NavDrawerRecyclerViewHolder(View itemView, OnItemClickListener onItemClickListener) {
// super(itemView);
//
// mOnItemClickListener = onItemClickListener;
// mAppName = (TextView) itemView.findViewById(R.id.app_name);
// mPackageIcon = (ImageView) itemView.findViewById(R.id.package_icon);
// itemView.setOnClickListener(this);
// }
//
// @Override
// public void onClick(View view) {
// if (mOnItemClickListener != null) {
// mOnItemClickListener.onItemClick(mPackageName);
// }
// }
//
// public interface OnItemClickListener {
// void onItemClick(String packageName);
// }
// }
| import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import org.mars3142.android.toaster.R;
import org.mars3142.android.toaster.card.ToastCard;
import org.mars3142.android.toaster.viewholder.NavDrawerRecyclerViewHolder;
import java.util.ArrayList; | /*
* This file is part of Toaster
*
* Copyright (c) 2014, 2017 Peter Siegmund
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.mars3142.android.toaster.adapter;
/**
* @author mars3142
*/
public class NavDrawerRecyclerAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
private final static int TYPE_ACCOUNT = 0;
private final static int TYPE_HEADER = 1;
private final static int TYPE_ITEM = 2;
private Context mContext; | // Path: app/src/main/java/org/mars3142/android/toaster/card/ToastCard.java
// public class ToastCard extends Card {
//
// public String message;
// public String appName;
// public String packageName;
// public String timestamp;
// public Drawable packageIcon;
// public Palette palette;
//
// private TextView mMessageTextView;
// private TextView mPackageNameTextView;
// private ImageView mPackageIconView;
// private RelativeLayout mCardBackgroundView;
//
// private static HashMap<String, Palette> mPalettes;
//
// public ToastCard(Context context) {
// super(context, R.layout.toaster_card);
//
// init();
// }
//
// public ToastCard(Context context, String packageName) {
// this(context);
//
// init();
// loadData(packageName);
// }
//
// private void init() {
// if (mPalettes == null) {
// mPalettes = new HashMap<>();
// }
// }
//
// private void loadData(String packageName) {
// if (!TextUtils.isEmpty(packageName)) {
// this.packageName = packageName;
// appName = PackageHelper.with(getContext()).getAppName(packageName);
// appName = (appName == null) ? packageName : appName;
// packageIcon = PackageHelper.with(getContext()).getIconFromPackageName(packageName);
// if (mPalettes.containsKey(packageName)) {
// palette = mPalettes.get(packageName);
// } else {
// if (packageIcon != null) {
// palette = new Palette.Builder(PackageHelper.drawableToBitmap(packageIcon)).generate();
// mPalettes.put(packageName, palette);
// }
// }
// }
// }
//
// @Override
// public void setupInnerViewElements(ViewGroup parent, View view) {
// if (mCardBackgroundView == null) {
// mCardBackgroundView = (RelativeLayout) parent.findViewById(R.id.backgroundColor);
// }
//
// if (mMessageTextView == null) {
// mMessageTextView = (TextView) parent.findViewById(R.id.message);
// }
//
// if (mPackageNameTextView == null) {
// mPackageNameTextView = (TextView) parent.findViewById(R.id.package_name);
// }
//
// if (mPackageIconView == null) {
// mPackageIconView = (ImageView) parent.findViewById(R.id.package_icon);
// }
//
// if (mCardBackgroundView != null) {
// int color = ContextCompat.getColor(getContext(), R.color.colorPrimary);
// if (palette != null) {
// color = palette.getMutedColor(color);
// }
// mCardBackgroundView.setBackgroundColor(color);
// }
//
// if (mMessageTextView != null) {
// mMessageTextView.setText(message);
// }
//
// if (mPackageNameTextView != null) {
// mPackageNameTextView.setText(appName == null ? packageName : appName);
// }
//
// if (mPackageIconView != null) {
// mPackageIconView.setImageDrawable(packageIcon);
// }
// }
// }
//
// Path: app/src/main/java/org/mars3142/android/toaster/viewholder/NavDrawerRecyclerViewHolder.java
// public class NavDrawerRecyclerViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
//
// private OnItemClickListener mOnItemClickListener;
// public ImageView mPackageIcon;
// public TextView mAppName;
// public String mPackageName;
//
// public NavDrawerRecyclerViewHolder(View itemView, OnItemClickListener onItemClickListener) {
// super(itemView);
//
// mOnItemClickListener = onItemClickListener;
// mAppName = (TextView) itemView.findViewById(R.id.app_name);
// mPackageIcon = (ImageView) itemView.findViewById(R.id.package_icon);
// itemView.setOnClickListener(this);
// }
//
// @Override
// public void onClick(View view) {
// if (mOnItemClickListener != null) {
// mOnItemClickListener.onItemClick(mPackageName);
// }
// }
//
// public interface OnItemClickListener {
// void onItemClick(String packageName);
// }
// }
// Path: app/src/main/java/org/mars3142/android/toaster/adapter/NavDrawerRecyclerAdapter.java
import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import org.mars3142.android.toaster.R;
import org.mars3142.android.toaster.card.ToastCard;
import org.mars3142.android.toaster.viewholder.NavDrawerRecyclerViewHolder;
import java.util.ArrayList;
/*
* This file is part of Toaster
*
* Copyright (c) 2014, 2017 Peter Siegmund
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.mars3142.android.toaster.adapter;
/**
* @author mars3142
*/
public class NavDrawerRecyclerAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
private final static int TYPE_ACCOUNT = 0;
private final static int TYPE_HEADER = 1;
private final static int TYPE_ITEM = 2;
private Context mContext; | private NavDrawerRecyclerViewHolder.OnItemClickListener mListener; |
mars3142/toaster | app/src/main/java/org/mars3142/android/toaster/adapter/NavDrawerRecyclerAdapter.java | // Path: app/src/main/java/org/mars3142/android/toaster/card/ToastCard.java
// public class ToastCard extends Card {
//
// public String message;
// public String appName;
// public String packageName;
// public String timestamp;
// public Drawable packageIcon;
// public Palette palette;
//
// private TextView mMessageTextView;
// private TextView mPackageNameTextView;
// private ImageView mPackageIconView;
// private RelativeLayout mCardBackgroundView;
//
// private static HashMap<String, Palette> mPalettes;
//
// public ToastCard(Context context) {
// super(context, R.layout.toaster_card);
//
// init();
// }
//
// public ToastCard(Context context, String packageName) {
// this(context);
//
// init();
// loadData(packageName);
// }
//
// private void init() {
// if (mPalettes == null) {
// mPalettes = new HashMap<>();
// }
// }
//
// private void loadData(String packageName) {
// if (!TextUtils.isEmpty(packageName)) {
// this.packageName = packageName;
// appName = PackageHelper.with(getContext()).getAppName(packageName);
// appName = (appName == null) ? packageName : appName;
// packageIcon = PackageHelper.with(getContext()).getIconFromPackageName(packageName);
// if (mPalettes.containsKey(packageName)) {
// palette = mPalettes.get(packageName);
// } else {
// if (packageIcon != null) {
// palette = new Palette.Builder(PackageHelper.drawableToBitmap(packageIcon)).generate();
// mPalettes.put(packageName, palette);
// }
// }
// }
// }
//
// @Override
// public void setupInnerViewElements(ViewGroup parent, View view) {
// if (mCardBackgroundView == null) {
// mCardBackgroundView = (RelativeLayout) parent.findViewById(R.id.backgroundColor);
// }
//
// if (mMessageTextView == null) {
// mMessageTextView = (TextView) parent.findViewById(R.id.message);
// }
//
// if (mPackageNameTextView == null) {
// mPackageNameTextView = (TextView) parent.findViewById(R.id.package_name);
// }
//
// if (mPackageIconView == null) {
// mPackageIconView = (ImageView) parent.findViewById(R.id.package_icon);
// }
//
// if (mCardBackgroundView != null) {
// int color = ContextCompat.getColor(getContext(), R.color.colorPrimary);
// if (palette != null) {
// color = palette.getMutedColor(color);
// }
// mCardBackgroundView.setBackgroundColor(color);
// }
//
// if (mMessageTextView != null) {
// mMessageTextView.setText(message);
// }
//
// if (mPackageNameTextView != null) {
// mPackageNameTextView.setText(appName == null ? packageName : appName);
// }
//
// if (mPackageIconView != null) {
// mPackageIconView.setImageDrawable(packageIcon);
// }
// }
// }
//
// Path: app/src/main/java/org/mars3142/android/toaster/viewholder/NavDrawerRecyclerViewHolder.java
// public class NavDrawerRecyclerViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
//
// private OnItemClickListener mOnItemClickListener;
// public ImageView mPackageIcon;
// public TextView mAppName;
// public String mPackageName;
//
// public NavDrawerRecyclerViewHolder(View itemView, OnItemClickListener onItemClickListener) {
// super(itemView);
//
// mOnItemClickListener = onItemClickListener;
// mAppName = (TextView) itemView.findViewById(R.id.app_name);
// mPackageIcon = (ImageView) itemView.findViewById(R.id.package_icon);
// itemView.setOnClickListener(this);
// }
//
// @Override
// public void onClick(View view) {
// if (mOnItemClickListener != null) {
// mOnItemClickListener.onItemClick(mPackageName);
// }
// }
//
// public interface OnItemClickListener {
// void onItemClick(String packageName);
// }
// }
| import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import org.mars3142.android.toaster.R;
import org.mars3142.android.toaster.card.ToastCard;
import org.mars3142.android.toaster.viewholder.NavDrawerRecyclerViewHolder;
import java.util.ArrayList; | /*
* This file is part of Toaster
*
* Copyright (c) 2014, 2017 Peter Siegmund
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.mars3142.android.toaster.adapter;
/**
* @author mars3142
*/
public class NavDrawerRecyclerAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
private final static int TYPE_ACCOUNT = 0;
private final static int TYPE_HEADER = 1;
private final static int TYPE_ITEM = 2;
private Context mContext;
private NavDrawerRecyclerViewHolder.OnItemClickListener mListener; | // Path: app/src/main/java/org/mars3142/android/toaster/card/ToastCard.java
// public class ToastCard extends Card {
//
// public String message;
// public String appName;
// public String packageName;
// public String timestamp;
// public Drawable packageIcon;
// public Palette palette;
//
// private TextView mMessageTextView;
// private TextView mPackageNameTextView;
// private ImageView mPackageIconView;
// private RelativeLayout mCardBackgroundView;
//
// private static HashMap<String, Palette> mPalettes;
//
// public ToastCard(Context context) {
// super(context, R.layout.toaster_card);
//
// init();
// }
//
// public ToastCard(Context context, String packageName) {
// this(context);
//
// init();
// loadData(packageName);
// }
//
// private void init() {
// if (mPalettes == null) {
// mPalettes = new HashMap<>();
// }
// }
//
// private void loadData(String packageName) {
// if (!TextUtils.isEmpty(packageName)) {
// this.packageName = packageName;
// appName = PackageHelper.with(getContext()).getAppName(packageName);
// appName = (appName == null) ? packageName : appName;
// packageIcon = PackageHelper.with(getContext()).getIconFromPackageName(packageName);
// if (mPalettes.containsKey(packageName)) {
// palette = mPalettes.get(packageName);
// } else {
// if (packageIcon != null) {
// palette = new Palette.Builder(PackageHelper.drawableToBitmap(packageIcon)).generate();
// mPalettes.put(packageName, palette);
// }
// }
// }
// }
//
// @Override
// public void setupInnerViewElements(ViewGroup parent, View view) {
// if (mCardBackgroundView == null) {
// mCardBackgroundView = (RelativeLayout) parent.findViewById(R.id.backgroundColor);
// }
//
// if (mMessageTextView == null) {
// mMessageTextView = (TextView) parent.findViewById(R.id.message);
// }
//
// if (mPackageNameTextView == null) {
// mPackageNameTextView = (TextView) parent.findViewById(R.id.package_name);
// }
//
// if (mPackageIconView == null) {
// mPackageIconView = (ImageView) parent.findViewById(R.id.package_icon);
// }
//
// if (mCardBackgroundView != null) {
// int color = ContextCompat.getColor(getContext(), R.color.colorPrimary);
// if (palette != null) {
// color = palette.getMutedColor(color);
// }
// mCardBackgroundView.setBackgroundColor(color);
// }
//
// if (mMessageTextView != null) {
// mMessageTextView.setText(message);
// }
//
// if (mPackageNameTextView != null) {
// mPackageNameTextView.setText(appName == null ? packageName : appName);
// }
//
// if (mPackageIconView != null) {
// mPackageIconView.setImageDrawable(packageIcon);
// }
// }
// }
//
// Path: app/src/main/java/org/mars3142/android/toaster/viewholder/NavDrawerRecyclerViewHolder.java
// public class NavDrawerRecyclerViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
//
// private OnItemClickListener mOnItemClickListener;
// public ImageView mPackageIcon;
// public TextView mAppName;
// public String mPackageName;
//
// public NavDrawerRecyclerViewHolder(View itemView, OnItemClickListener onItemClickListener) {
// super(itemView);
//
// mOnItemClickListener = onItemClickListener;
// mAppName = (TextView) itemView.findViewById(R.id.app_name);
// mPackageIcon = (ImageView) itemView.findViewById(R.id.package_icon);
// itemView.setOnClickListener(this);
// }
//
// @Override
// public void onClick(View view) {
// if (mOnItemClickListener != null) {
// mOnItemClickListener.onItemClick(mPackageName);
// }
// }
//
// public interface OnItemClickListener {
// void onItemClick(String packageName);
// }
// }
// Path: app/src/main/java/org/mars3142/android/toaster/adapter/NavDrawerRecyclerAdapter.java
import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import org.mars3142.android.toaster.R;
import org.mars3142.android.toaster.card.ToastCard;
import org.mars3142.android.toaster.viewholder.NavDrawerRecyclerViewHolder;
import java.util.ArrayList;
/*
* This file is part of Toaster
*
* Copyright (c) 2014, 2017 Peter Siegmund
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.mars3142.android.toaster.adapter;
/**
* @author mars3142
*/
public class NavDrawerRecyclerAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
private final static int TYPE_ACCOUNT = 0;
private final static int TYPE_HEADER = 1;
private final static int TYPE_ITEM = 2;
private Context mContext;
private NavDrawerRecyclerViewHolder.OnItemClickListener mListener; | private ArrayList<ToastCard> mData; |
mars3142/toaster | app/src/main/java/org/mars3142/android/toaster/ui/widget/Widget.java | // Path: app/src/main/java/org/mars3142/android/toaster/service/WidgetService.java
// public class WidgetService extends RemoteViewsService {
//
// @Override
// public RemoteViewsFactory onGetViewFactory(Intent intent) {
// Timber.d("onGetViewFactory");
//
// return (new WidgetViewsFactory(this.getApplicationContext()));
// }
// }
| import org.mars3142.android.toaster.service.WidgetService;
import java.util.Arrays;
import timber.log.Timber;
import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProvider;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.util.Log;
import android.widget.RemoteViews;
import org.mars3142.android.toaster.BuildConfig;
import org.mars3142.android.toaster.R; | /*
* This file is part of Toaster
*
* Copyright (c) 2014, 2017 Peter Siegmund
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.mars3142.android.toaster.ui.widget;
/**
* @author mars3142
*/
public class Widget extends AppWidgetProvider {
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
Timber.v("onUpdate: [ %s ]", Arrays.toString(appWidgetIds));
updateWidget(context, appWidgetManager);
}
@Override
public void onReceive(Context context, Intent intent) {
Timber.v("onReceived");
updateWidget(context, AppWidgetManager.getInstance(context));
}
private void updateWidget(Context context, AppWidgetManager appWidgetManager) { | // Path: app/src/main/java/org/mars3142/android/toaster/service/WidgetService.java
// public class WidgetService extends RemoteViewsService {
//
// @Override
// public RemoteViewsFactory onGetViewFactory(Intent intent) {
// Timber.d("onGetViewFactory");
//
// return (new WidgetViewsFactory(this.getApplicationContext()));
// }
// }
// Path: app/src/main/java/org/mars3142/android/toaster/ui/widget/Widget.java
import org.mars3142.android.toaster.service.WidgetService;
import java.util.Arrays;
import timber.log.Timber;
import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProvider;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.util.Log;
import android.widget.RemoteViews;
import org.mars3142.android.toaster.BuildConfig;
import org.mars3142.android.toaster.R;
/*
* This file is part of Toaster
*
* Copyright (c) 2014, 2017 Peter Siegmund
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.mars3142.android.toaster.ui.widget;
/**
* @author mars3142
*/
public class Widget extends AppWidgetProvider {
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
Timber.v("onUpdate: [ %s ]", Arrays.toString(appWidgetIds));
updateWidget(context, appWidgetManager);
}
@Override
public void onReceive(Context context, Intent intent) {
Timber.v("onReceived");
updateWidget(context, AppWidgetManager.getInstance(context));
}
private void updateWidget(Context context, AppWidgetManager appWidgetManager) { | Intent intent = new Intent(context, WidgetService.class); |
mars3142/toaster | app/src/main/java/org/mars3142/android/toaster/service/WidgetService.java | // Path: app/src/main/java/org/mars3142/android/toaster/factory/WidgetViewsFactory.java
// public class WidgetViewsFactory
// implements RemoteViewsService.RemoteViewsFactory {
//
// private Context mContext;
// private ArrayList<String> mPackages;
//
// public WidgetViewsFactory(Context context) {
// mContext = context;
//
// mPackages = new ArrayList<>();
//
// ContentResolver cr = context.getContentResolver();
// Cursor data = cr.query(ToasterTable.TOASTER_URI, new String[]{ToasterTable.PACKAGE}, null, null, ToasterTable._ID + " DESC LIMIT 5");
// if (data.moveToFirst()) {
// do {
// mPackages.add(data.getString(data.getColumnIndex(ToasterTable.PACKAGE)));
// } while (data.moveToNext());
// }
// data.close();
// }
//
// @Override
// public void onCreate() {
// // no-op
// }
//
// @Override
// public void onDataSetChanged() {
// // no-op
// }
//
// @Override
// public void onDestroy() {
// mContext = null;
// }
//
// @Override
// public int getCount() {
// return mPackages.size();
// }
//
// @Override
// public RemoteViews getViewAt(int position) {
// Timber.v("getViewAt( %d )", position);
//
// RemoteViews row = new RemoteViews(mContext.getPackageName(), R.layout.widget_row);
// ToastCard toastCard = new ToastCard(mContext, mPackages.get(position));
//
// row.setTextViewText(R.id.package_name, toastCard.appName);
// row.setImageViewBitmap(R.id.package_icon, PackageHelper.drawableToBitmap(toastCard.packageIcon));
//
// int color = mContext.getResources().getColor(R.color.colorPrimary);
// if (toastCard.palette != null) {
// color = toastCard.palette.getMutedColor(color);
// }
// row.setInt(R.id.row, "setBackgroundColor", color);
//
// return (row);
// }
//
// @Override
// public RemoteViews getLoadingView() {
// Timber.d("getLoadingView");
//
// return new RemoteViews(mContext.getPackageName(), R.layout.widget_loading);
// }
//
// @Override
// public int getViewTypeCount() {
// return 1;
// }
//
// @Override
// public long getItemId(int position) {
// return position;
// }
//
// @Override
// public boolean hasStableIds() {
// return false;
// }
// }
| import org.mars3142.android.toaster.factory.WidgetViewsFactory;
import timber.log.Timber;
import android.content.Intent;
import android.widget.RemoteViewsService;
| /*
* This file is part of Toaster
*
* Copyright (c) 2014, 2017 Peter Siegmund
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.mars3142.android.toaster.service;
/**
* @author mars3142
*/
public class WidgetService extends RemoteViewsService {
@Override
public RemoteViewsFactory onGetViewFactory(Intent intent) {
Timber.d("onGetViewFactory");
| // Path: app/src/main/java/org/mars3142/android/toaster/factory/WidgetViewsFactory.java
// public class WidgetViewsFactory
// implements RemoteViewsService.RemoteViewsFactory {
//
// private Context mContext;
// private ArrayList<String> mPackages;
//
// public WidgetViewsFactory(Context context) {
// mContext = context;
//
// mPackages = new ArrayList<>();
//
// ContentResolver cr = context.getContentResolver();
// Cursor data = cr.query(ToasterTable.TOASTER_URI, new String[]{ToasterTable.PACKAGE}, null, null, ToasterTable._ID + " DESC LIMIT 5");
// if (data.moveToFirst()) {
// do {
// mPackages.add(data.getString(data.getColumnIndex(ToasterTable.PACKAGE)));
// } while (data.moveToNext());
// }
// data.close();
// }
//
// @Override
// public void onCreate() {
// // no-op
// }
//
// @Override
// public void onDataSetChanged() {
// // no-op
// }
//
// @Override
// public void onDestroy() {
// mContext = null;
// }
//
// @Override
// public int getCount() {
// return mPackages.size();
// }
//
// @Override
// public RemoteViews getViewAt(int position) {
// Timber.v("getViewAt( %d )", position);
//
// RemoteViews row = new RemoteViews(mContext.getPackageName(), R.layout.widget_row);
// ToastCard toastCard = new ToastCard(mContext, mPackages.get(position));
//
// row.setTextViewText(R.id.package_name, toastCard.appName);
// row.setImageViewBitmap(R.id.package_icon, PackageHelper.drawableToBitmap(toastCard.packageIcon));
//
// int color = mContext.getResources().getColor(R.color.colorPrimary);
// if (toastCard.palette != null) {
// color = toastCard.palette.getMutedColor(color);
// }
// row.setInt(R.id.row, "setBackgroundColor", color);
//
// return (row);
// }
//
// @Override
// public RemoteViews getLoadingView() {
// Timber.d("getLoadingView");
//
// return new RemoteViews(mContext.getPackageName(), R.layout.widget_loading);
// }
//
// @Override
// public int getViewTypeCount() {
// return 1;
// }
//
// @Override
// public long getItemId(int position) {
// return position;
// }
//
// @Override
// public boolean hasStableIds() {
// return false;
// }
// }
// Path: app/src/main/java/org/mars3142/android/toaster/service/WidgetService.java
import org.mars3142.android.toaster.factory.WidgetViewsFactory;
import timber.log.Timber;
import android.content.Intent;
import android.widget.RemoteViewsService;
/*
* This file is part of Toaster
*
* Copyright (c) 2014, 2017 Peter Siegmund
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.mars3142.android.toaster.service;
/**
* @author mars3142
*/
public class WidgetService extends RemoteViewsService {
@Override
public RemoteViewsFactory onGetViewFactory(Intent intent) {
Timber.d("onGetViewFactory");
| return (new WidgetViewsFactory(this.getApplicationContext()));
|
mars3142/toaster | app/src/main/java/org/mars3142/android/toaster/listener/DeleteListener.java | // Path: app/src/main/java/org/mars3142/android/toaster/task/AsyncDelete.java
// public class AsyncDelete extends AsyncTask<Void, Void, Integer> {
//
// private Context mContext;
// private Uri mUri;
// private String mWhere;
// private String[] mSelectionArgs;
//
// public AsyncDelete(Context context, Uri uri, String where, String[] selectionArgs) {
// mContext = context;
// mUri = uri;
// mWhere = where;
// mSelectionArgs = selectionArgs;
// }
//
// protected Integer doInBackground(Void... params) {
// Integer rows = -1;
// try {
// rows = mContext.getContentResolver().delete(mUri, mWhere, mSelectionArgs);
// } catch (Exception ex) {
// Timber.e("Error while delete");
// }
//
// return rows;
// }
// }
| import org.mars3142.android.toaster.task.AsyncDelete;
import android.content.Context;
import android.content.DialogInterface;
import android.net.Uri;
| /*
* This file is part of Toaster
*
* Copyright (c) 2014, 2017 Peter Siegmund
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.mars3142.android.toaster.listener;
/**
* Listener for calling a delete on the database provider
*
* @author mars3142
*/
public class DeleteListener
implements DialogInterface.OnClickListener {
private static final String TAG = DeleteListener.class.getSimpleName();
private final Context mContext;
private final Uri mUri;
private final String mWhere;
private final String[] mSelectionArgs;
public DeleteListener(Context context, Uri uri) {
this(context, uri, null, null);
}
public DeleteListener(Context context, Uri uri, String where, String[] selectionArgs) {
mContext = context;
mUri = uri;
mWhere = where;
mSelectionArgs = selectionArgs;
}
@Override
public void onClick(DialogInterface dialog, int which) {
if (mUri != null) {
| // Path: app/src/main/java/org/mars3142/android/toaster/task/AsyncDelete.java
// public class AsyncDelete extends AsyncTask<Void, Void, Integer> {
//
// private Context mContext;
// private Uri mUri;
// private String mWhere;
// private String[] mSelectionArgs;
//
// public AsyncDelete(Context context, Uri uri, String where, String[] selectionArgs) {
// mContext = context;
// mUri = uri;
// mWhere = where;
// mSelectionArgs = selectionArgs;
// }
//
// protected Integer doInBackground(Void... params) {
// Integer rows = -1;
// try {
// rows = mContext.getContentResolver().delete(mUri, mWhere, mSelectionArgs);
// } catch (Exception ex) {
// Timber.e("Error while delete");
// }
//
// return rows;
// }
// }
// Path: app/src/main/java/org/mars3142/android/toaster/listener/DeleteListener.java
import org.mars3142.android.toaster.task.AsyncDelete;
import android.content.Context;
import android.content.DialogInterface;
import android.net.Uri;
/*
* This file is part of Toaster
*
* Copyright (c) 2014, 2017 Peter Siegmund
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.mars3142.android.toaster.listener;
/**
* Listener for calling a delete on the database provider
*
* @author mars3142
*/
public class DeleteListener
implements DialogInterface.OnClickListener {
private static final String TAG = DeleteListener.class.getSimpleName();
private final Context mContext;
private final Uri mUri;
private final String mWhere;
private final String[] mSelectionArgs;
public DeleteListener(Context context, Uri uri) {
this(context, uri, null, null);
}
public DeleteListener(Context context, Uri uri, String where, String[] selectionArgs) {
mContext = context;
mUri = uri;
mWhere = where;
mSelectionArgs = selectionArgs;
}
@Override
public void onClick(DialogInterface dialog, int which) {
if (mUri != null) {
| AsyncDelete task = new AsyncDelete(mContext, mUri, mWhere, mSelectionArgs);
|
mars3142/toaster | app/src/main/java/org/mars3142/android/toaster/receiver/PackageReceiver.java | // Path: app/src/main/java/org/mars3142/android/toaster/table/ToasterTable.java
// public class ToasterTable
// implements BaseColumns {
//
// private static final String TAG = ToasterTable.class.getSimpleName();
//
// public static final String TABLE_NAME = "toaster";
// public static final String TIMESTAMP = "timestamp";
// public static final String PACKAGE = "package";
// public static final String MESSAGE = "message";
// public static final String VERSION_CODE = "version_code";
// public static final String VERSION_NAME = "version_name";
// public static final Uri TOASTER_URI = Uri.parse("content://" + ToasterProvider.AUTHORITY + "/toaster");
// public static final Uri PACKAGE_URI = Uri.parse("content://" + ToasterProvider.AUTHORITY + "/packages");
// public static final String CONTENT_TYPE = ContentResolver.CURSOR_DIR_BASE_TYPE + "/vnd.mars3142.content.toaster";
// public static final String CONTENT_ITEM_TYPE = ContentResolver.CURSOR_ITEM_BASE_TYPE + "/vnd.mars3142.content.toaster";
//
// public static void onCreate(SQLiteDatabase db) {
// db.execSQL("CREATE TABLE " + TABLE_NAME +
// " (" +
// _ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
// TIMESTAMP + " LONG, " +
// PACKAGE + " TEXT, " +
// MESSAGE + " TEXT, " +
// VERSION_CODE + " INTEGER, " +
// VERSION_NAME + " TEXT " +
// ");");
// }
//
// public static void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// if (newVersion > oldVersion) {
// switch (oldVersion) {
// case 1:
// try {
// db.execSQL("ALTER TABLE " + TABLE_NAME + " ADD COLUMN " + VERSION_CODE + " INTEGER;");
// db.execSQL("ALTER TABLE " + TABLE_NAME + " ADD COLUMN " + VERSION_NAME + " TEXT;");
// } catch (SQLException ex) {
// // upgrade already done
// }
// break;
//
// default:
// db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
// onCreate(db);
// }
// }
// }
//
// public static void onDowngrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// // nothing
// }
// }
| import timber.log.Timber;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.util.Log;
import org.mars3142.android.toaster.BuildConfig;
import org.mars3142.android.toaster.R;
import org.mars3142.android.toaster.table.ToasterTable; | /*
* This file is part of Toaster
*
* Copyright (c) 2014, 2017 Peter Siegmund
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.mars3142.android.toaster.receiver;
/**
* @author mars3142
*/
public class PackageReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Timber.d("onReceive");
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
if (preferences.getBoolean(context.getString(R.string.delete_key), false)) {
String packageName = intent.getData().getSchemeSpecificPart();
if (intent.getBooleanExtra(Intent.EXTRA_DATA_REMOVED, false)) { | // Path: app/src/main/java/org/mars3142/android/toaster/table/ToasterTable.java
// public class ToasterTable
// implements BaseColumns {
//
// private static final String TAG = ToasterTable.class.getSimpleName();
//
// public static final String TABLE_NAME = "toaster";
// public static final String TIMESTAMP = "timestamp";
// public static final String PACKAGE = "package";
// public static final String MESSAGE = "message";
// public static final String VERSION_CODE = "version_code";
// public static final String VERSION_NAME = "version_name";
// public static final Uri TOASTER_URI = Uri.parse("content://" + ToasterProvider.AUTHORITY + "/toaster");
// public static final Uri PACKAGE_URI = Uri.parse("content://" + ToasterProvider.AUTHORITY + "/packages");
// public static final String CONTENT_TYPE = ContentResolver.CURSOR_DIR_BASE_TYPE + "/vnd.mars3142.content.toaster";
// public static final String CONTENT_ITEM_TYPE = ContentResolver.CURSOR_ITEM_BASE_TYPE + "/vnd.mars3142.content.toaster";
//
// public static void onCreate(SQLiteDatabase db) {
// db.execSQL("CREATE TABLE " + TABLE_NAME +
// " (" +
// _ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
// TIMESTAMP + " LONG, " +
// PACKAGE + " TEXT, " +
// MESSAGE + " TEXT, " +
// VERSION_CODE + " INTEGER, " +
// VERSION_NAME + " TEXT " +
// ");");
// }
//
// public static void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// if (newVersion > oldVersion) {
// switch (oldVersion) {
// case 1:
// try {
// db.execSQL("ALTER TABLE " + TABLE_NAME + " ADD COLUMN " + VERSION_CODE + " INTEGER;");
// db.execSQL("ALTER TABLE " + TABLE_NAME + " ADD COLUMN " + VERSION_NAME + " TEXT;");
// } catch (SQLException ex) {
// // upgrade already done
// }
// break;
//
// default:
// db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
// onCreate(db);
// }
// }
// }
//
// public static void onDowngrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// // nothing
// }
// }
// Path: app/src/main/java/org/mars3142/android/toaster/receiver/PackageReceiver.java
import timber.log.Timber;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.util.Log;
import org.mars3142.android.toaster.BuildConfig;
import org.mars3142.android.toaster.R;
import org.mars3142.android.toaster.table.ToasterTable;
/*
* This file is part of Toaster
*
* Copyright (c) 2014, 2017 Peter Siegmund
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.mars3142.android.toaster.receiver;
/**
* @author mars3142
*/
public class PackageReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Timber.d("onReceive");
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
if (preferences.getBoolean(context.getString(R.string.delete_key), false)) {
String packageName = intent.getData().getSchemeSpecificPart();
if (intent.getBooleanExtra(Intent.EXTRA_DATA_REMOVED, false)) { | int rows = context.getContentResolver().delete(ToasterTable.TOASTER_URI, ToasterTable.PACKAGE + " = ?", new String[]{packageName}); |
mars3142/toaster | app/src/main/java/org/mars3142/android/toaster/service/ToasterService.java | // Path: app/src/main/java/org/mars3142/android/toaster/table/ToasterTable.java
// public class ToasterTable
// implements BaseColumns {
//
// private static final String TAG = ToasterTable.class.getSimpleName();
//
// public static final String TABLE_NAME = "toaster";
// public static final String TIMESTAMP = "timestamp";
// public static final String PACKAGE = "package";
// public static final String MESSAGE = "message";
// public static final String VERSION_CODE = "version_code";
// public static final String VERSION_NAME = "version_name";
// public static final Uri TOASTER_URI = Uri.parse("content://" + ToasterProvider.AUTHORITY + "/toaster");
// public static final Uri PACKAGE_URI = Uri.parse("content://" + ToasterProvider.AUTHORITY + "/packages");
// public static final String CONTENT_TYPE = ContentResolver.CURSOR_DIR_BASE_TYPE + "/vnd.mars3142.content.toaster";
// public static final String CONTENT_ITEM_TYPE = ContentResolver.CURSOR_ITEM_BASE_TYPE + "/vnd.mars3142.content.toaster";
//
// public static void onCreate(SQLiteDatabase db) {
// db.execSQL("CREATE TABLE " + TABLE_NAME +
// " (" +
// _ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
// TIMESTAMP + " LONG, " +
// PACKAGE + " TEXT, " +
// MESSAGE + " TEXT, " +
// VERSION_CODE + " INTEGER, " +
// VERSION_NAME + " TEXT " +
// ");");
// }
//
// public static void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// if (newVersion > oldVersion) {
// switch (oldVersion) {
// case 1:
// try {
// db.execSQL("ALTER TABLE " + TABLE_NAME + " ADD COLUMN " + VERSION_CODE + " INTEGER;");
// db.execSQL("ALTER TABLE " + TABLE_NAME + " ADD COLUMN " + VERSION_NAME + " TEXT;");
// } catch (SQLException ex) {
// // upgrade already done
// }
// break;
//
// default:
// db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
// onCreate(db);
// }
// }
// }
//
// public static void onDowngrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// // nothing
// }
// }
//
// Path: app/src/main/java/org/mars3142/android/toaster/task/AsyncInsert.java
// public class AsyncInsert extends AsyncTask<Void, Void, Uri>{
//
// private Context mContext;
// private Uri mUri;
// private ContentValues mValues;
//
// public AsyncInsert(Context context, Uri uri, ContentValues values) {
// mContext = context;
// mUri = uri;
// mValues = values;
// }
//
// @Override
// protected Uri doInBackground(Void... params) {
// Uri result = null;
// try {
// result = mContext.getContentResolver().insert(mUri, mValues);
// } catch (Exception ex) {
// Timber.e("Error while insert");
// }
//
// return result;
// }
// }
| import java.util.Calendar;
import timber.log.Timber;
import android.accessibilityservice.AccessibilityService;
import android.app.Notification;
import android.content.ContentValues;
import android.content.Intent;
import android.os.Parcelable;
import android.view.accessibility.AccessibilityEvent;
import org.mars3142.android.toaster.BuildConfig;
import org.mars3142.android.toaster.table.ToasterTable;
import org.mars3142.android.toaster.task.AsyncInsert;
| /*
* This file is part of Toaster
*
* Copyright (c) 2014, 2017 Peter Siegmund
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.mars3142.android.toaster.service;
/**
* Accessibility service who fetches the notification
* <p/>
* <p>Sends the data to the database provider and informs every widget to update</p>
*
* @author mars3142
*/
public class ToasterService extends AccessibilityService {
@Override
public void onAccessibilityEvent(AccessibilityEvent event) {
Timber.d("Event: %s", event);
if (event.getEventType() != AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED) {
Timber.d("Unexpected event type - ignoring");
return; // event is not a notification
}
long timestamp = Calendar.getInstance().getTimeInMillis();
String sourcePackageName = (String) event.getPackageName();
String message = "";
for (CharSequence text : event.getText()) {
message += text + "\n";
}
if (message.length() > 0) {
message = message.substring(0, message.length() - 1);
}
Parcelable parcelable = event.getParcelableData();
if (!(parcelable instanceof Notification)) {
ContentValues cv = new ContentValues();
| // Path: app/src/main/java/org/mars3142/android/toaster/table/ToasterTable.java
// public class ToasterTable
// implements BaseColumns {
//
// private static final String TAG = ToasterTable.class.getSimpleName();
//
// public static final String TABLE_NAME = "toaster";
// public static final String TIMESTAMP = "timestamp";
// public static final String PACKAGE = "package";
// public static final String MESSAGE = "message";
// public static final String VERSION_CODE = "version_code";
// public static final String VERSION_NAME = "version_name";
// public static final Uri TOASTER_URI = Uri.parse("content://" + ToasterProvider.AUTHORITY + "/toaster");
// public static final Uri PACKAGE_URI = Uri.parse("content://" + ToasterProvider.AUTHORITY + "/packages");
// public static final String CONTENT_TYPE = ContentResolver.CURSOR_DIR_BASE_TYPE + "/vnd.mars3142.content.toaster";
// public static final String CONTENT_ITEM_TYPE = ContentResolver.CURSOR_ITEM_BASE_TYPE + "/vnd.mars3142.content.toaster";
//
// public static void onCreate(SQLiteDatabase db) {
// db.execSQL("CREATE TABLE " + TABLE_NAME +
// " (" +
// _ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
// TIMESTAMP + " LONG, " +
// PACKAGE + " TEXT, " +
// MESSAGE + " TEXT, " +
// VERSION_CODE + " INTEGER, " +
// VERSION_NAME + " TEXT " +
// ");");
// }
//
// public static void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// if (newVersion > oldVersion) {
// switch (oldVersion) {
// case 1:
// try {
// db.execSQL("ALTER TABLE " + TABLE_NAME + " ADD COLUMN " + VERSION_CODE + " INTEGER;");
// db.execSQL("ALTER TABLE " + TABLE_NAME + " ADD COLUMN " + VERSION_NAME + " TEXT;");
// } catch (SQLException ex) {
// // upgrade already done
// }
// break;
//
// default:
// db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
// onCreate(db);
// }
// }
// }
//
// public static void onDowngrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// // nothing
// }
// }
//
// Path: app/src/main/java/org/mars3142/android/toaster/task/AsyncInsert.java
// public class AsyncInsert extends AsyncTask<Void, Void, Uri>{
//
// private Context mContext;
// private Uri mUri;
// private ContentValues mValues;
//
// public AsyncInsert(Context context, Uri uri, ContentValues values) {
// mContext = context;
// mUri = uri;
// mValues = values;
// }
//
// @Override
// protected Uri doInBackground(Void... params) {
// Uri result = null;
// try {
// result = mContext.getContentResolver().insert(mUri, mValues);
// } catch (Exception ex) {
// Timber.e("Error while insert");
// }
//
// return result;
// }
// }
// Path: app/src/main/java/org/mars3142/android/toaster/service/ToasterService.java
import java.util.Calendar;
import timber.log.Timber;
import android.accessibilityservice.AccessibilityService;
import android.app.Notification;
import android.content.ContentValues;
import android.content.Intent;
import android.os.Parcelable;
import android.view.accessibility.AccessibilityEvent;
import org.mars3142.android.toaster.BuildConfig;
import org.mars3142.android.toaster.table.ToasterTable;
import org.mars3142.android.toaster.task.AsyncInsert;
/*
* This file is part of Toaster
*
* Copyright (c) 2014, 2017 Peter Siegmund
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.mars3142.android.toaster.service;
/**
* Accessibility service who fetches the notification
* <p/>
* <p>Sends the data to the database provider and informs every widget to update</p>
*
* @author mars3142
*/
public class ToasterService extends AccessibilityService {
@Override
public void onAccessibilityEvent(AccessibilityEvent event) {
Timber.d("Event: %s", event);
if (event.getEventType() != AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED) {
Timber.d("Unexpected event type - ignoring");
return; // event is not a notification
}
long timestamp = Calendar.getInstance().getTimeInMillis();
String sourcePackageName = (String) event.getPackageName();
String message = "";
for (CharSequence text : event.getText()) {
message += text + "\n";
}
if (message.length() > 0) {
message = message.substring(0, message.length() - 1);
}
Parcelable parcelable = event.getParcelableData();
if (!(parcelable instanceof Notification)) {
ContentValues cv = new ContentValues();
| cv.put(ToasterTable.PACKAGE, sourcePackageName);
|
mars3142/toaster | app/src/main/java/org/mars3142/android/toaster/service/ToasterService.java | // Path: app/src/main/java/org/mars3142/android/toaster/table/ToasterTable.java
// public class ToasterTable
// implements BaseColumns {
//
// private static final String TAG = ToasterTable.class.getSimpleName();
//
// public static final String TABLE_NAME = "toaster";
// public static final String TIMESTAMP = "timestamp";
// public static final String PACKAGE = "package";
// public static final String MESSAGE = "message";
// public static final String VERSION_CODE = "version_code";
// public static final String VERSION_NAME = "version_name";
// public static final Uri TOASTER_URI = Uri.parse("content://" + ToasterProvider.AUTHORITY + "/toaster");
// public static final Uri PACKAGE_URI = Uri.parse("content://" + ToasterProvider.AUTHORITY + "/packages");
// public static final String CONTENT_TYPE = ContentResolver.CURSOR_DIR_BASE_TYPE + "/vnd.mars3142.content.toaster";
// public static final String CONTENT_ITEM_TYPE = ContentResolver.CURSOR_ITEM_BASE_TYPE + "/vnd.mars3142.content.toaster";
//
// public static void onCreate(SQLiteDatabase db) {
// db.execSQL("CREATE TABLE " + TABLE_NAME +
// " (" +
// _ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
// TIMESTAMP + " LONG, " +
// PACKAGE + " TEXT, " +
// MESSAGE + " TEXT, " +
// VERSION_CODE + " INTEGER, " +
// VERSION_NAME + " TEXT " +
// ");");
// }
//
// public static void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// if (newVersion > oldVersion) {
// switch (oldVersion) {
// case 1:
// try {
// db.execSQL("ALTER TABLE " + TABLE_NAME + " ADD COLUMN " + VERSION_CODE + " INTEGER;");
// db.execSQL("ALTER TABLE " + TABLE_NAME + " ADD COLUMN " + VERSION_NAME + " TEXT;");
// } catch (SQLException ex) {
// // upgrade already done
// }
// break;
//
// default:
// db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
// onCreate(db);
// }
// }
// }
//
// public static void onDowngrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// // nothing
// }
// }
//
// Path: app/src/main/java/org/mars3142/android/toaster/task/AsyncInsert.java
// public class AsyncInsert extends AsyncTask<Void, Void, Uri>{
//
// private Context mContext;
// private Uri mUri;
// private ContentValues mValues;
//
// public AsyncInsert(Context context, Uri uri, ContentValues values) {
// mContext = context;
// mUri = uri;
// mValues = values;
// }
//
// @Override
// protected Uri doInBackground(Void... params) {
// Uri result = null;
// try {
// result = mContext.getContentResolver().insert(mUri, mValues);
// } catch (Exception ex) {
// Timber.e("Error while insert");
// }
//
// return result;
// }
// }
| import java.util.Calendar;
import timber.log.Timber;
import android.accessibilityservice.AccessibilityService;
import android.app.Notification;
import android.content.ContentValues;
import android.content.Intent;
import android.os.Parcelable;
import android.view.accessibility.AccessibilityEvent;
import org.mars3142.android.toaster.BuildConfig;
import org.mars3142.android.toaster.table.ToasterTable;
import org.mars3142.android.toaster.task.AsyncInsert;
| /*
* This file is part of Toaster
*
* Copyright (c) 2014, 2017 Peter Siegmund
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.mars3142.android.toaster.service;
/**
* Accessibility service who fetches the notification
* <p/>
* <p>Sends the data to the database provider and informs every widget to update</p>
*
* @author mars3142
*/
public class ToasterService extends AccessibilityService {
@Override
public void onAccessibilityEvent(AccessibilityEvent event) {
Timber.d("Event: %s", event);
if (event.getEventType() != AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED) {
Timber.d("Unexpected event type - ignoring");
return; // event is not a notification
}
long timestamp = Calendar.getInstance().getTimeInMillis();
String sourcePackageName = (String) event.getPackageName();
String message = "";
for (CharSequence text : event.getText()) {
message += text + "\n";
}
if (message.length() > 0) {
message = message.substring(0, message.length() - 1);
}
Parcelable parcelable = event.getParcelableData();
if (!(parcelable instanceof Notification)) {
ContentValues cv = new ContentValues();
cv.put(ToasterTable.PACKAGE, sourcePackageName);
cv.put(ToasterTable.MESSAGE, message);
cv.put(ToasterTable.TIMESTAMP, timestamp);
| // Path: app/src/main/java/org/mars3142/android/toaster/table/ToasterTable.java
// public class ToasterTable
// implements BaseColumns {
//
// private static final String TAG = ToasterTable.class.getSimpleName();
//
// public static final String TABLE_NAME = "toaster";
// public static final String TIMESTAMP = "timestamp";
// public static final String PACKAGE = "package";
// public static final String MESSAGE = "message";
// public static final String VERSION_CODE = "version_code";
// public static final String VERSION_NAME = "version_name";
// public static final Uri TOASTER_URI = Uri.parse("content://" + ToasterProvider.AUTHORITY + "/toaster");
// public static final Uri PACKAGE_URI = Uri.parse("content://" + ToasterProvider.AUTHORITY + "/packages");
// public static final String CONTENT_TYPE = ContentResolver.CURSOR_DIR_BASE_TYPE + "/vnd.mars3142.content.toaster";
// public static final String CONTENT_ITEM_TYPE = ContentResolver.CURSOR_ITEM_BASE_TYPE + "/vnd.mars3142.content.toaster";
//
// public static void onCreate(SQLiteDatabase db) {
// db.execSQL("CREATE TABLE " + TABLE_NAME +
// " (" +
// _ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
// TIMESTAMP + " LONG, " +
// PACKAGE + " TEXT, " +
// MESSAGE + " TEXT, " +
// VERSION_CODE + " INTEGER, " +
// VERSION_NAME + " TEXT " +
// ");");
// }
//
// public static void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// if (newVersion > oldVersion) {
// switch (oldVersion) {
// case 1:
// try {
// db.execSQL("ALTER TABLE " + TABLE_NAME + " ADD COLUMN " + VERSION_CODE + " INTEGER;");
// db.execSQL("ALTER TABLE " + TABLE_NAME + " ADD COLUMN " + VERSION_NAME + " TEXT;");
// } catch (SQLException ex) {
// // upgrade already done
// }
// break;
//
// default:
// db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
// onCreate(db);
// }
// }
// }
//
// public static void onDowngrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// // nothing
// }
// }
//
// Path: app/src/main/java/org/mars3142/android/toaster/task/AsyncInsert.java
// public class AsyncInsert extends AsyncTask<Void, Void, Uri>{
//
// private Context mContext;
// private Uri mUri;
// private ContentValues mValues;
//
// public AsyncInsert(Context context, Uri uri, ContentValues values) {
// mContext = context;
// mUri = uri;
// mValues = values;
// }
//
// @Override
// protected Uri doInBackground(Void... params) {
// Uri result = null;
// try {
// result = mContext.getContentResolver().insert(mUri, mValues);
// } catch (Exception ex) {
// Timber.e("Error while insert");
// }
//
// return result;
// }
// }
// Path: app/src/main/java/org/mars3142/android/toaster/service/ToasterService.java
import java.util.Calendar;
import timber.log.Timber;
import android.accessibilityservice.AccessibilityService;
import android.app.Notification;
import android.content.ContentValues;
import android.content.Intent;
import android.os.Parcelable;
import android.view.accessibility.AccessibilityEvent;
import org.mars3142.android.toaster.BuildConfig;
import org.mars3142.android.toaster.table.ToasterTable;
import org.mars3142.android.toaster.task.AsyncInsert;
/*
* This file is part of Toaster
*
* Copyright (c) 2014, 2017 Peter Siegmund
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.mars3142.android.toaster.service;
/**
* Accessibility service who fetches the notification
* <p/>
* <p>Sends the data to the database provider and informs every widget to update</p>
*
* @author mars3142
*/
public class ToasterService extends AccessibilityService {
@Override
public void onAccessibilityEvent(AccessibilityEvent event) {
Timber.d("Event: %s", event);
if (event.getEventType() != AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED) {
Timber.d("Unexpected event type - ignoring");
return; // event is not a notification
}
long timestamp = Calendar.getInstance().getTimeInMillis();
String sourcePackageName = (String) event.getPackageName();
String message = "";
for (CharSequence text : event.getText()) {
message += text + "\n";
}
if (message.length() > 0) {
message = message.substring(0, message.length() - 1);
}
Parcelable parcelable = event.getParcelableData();
if (!(parcelable instanceof Notification)) {
ContentValues cv = new ContentValues();
cv.put(ToasterTable.PACKAGE, sourcePackageName);
cv.put(ToasterTable.MESSAGE, message);
cv.put(ToasterTable.TIMESTAMP, timestamp);
| new AsyncInsert(this, ToasterTable.TOASTER_URI, cv).execute();
|
arconsis/droitatedDB | droitatedDB/src/main/java/org/droitateddb/EntityService.java | // Path: droitatedDB/src/main/java/org/droitateddb/schema/EntityInfo.java
// public class EntityInfo {
// private final String tableName;
// private final String className;
// private final Class<?> definition;
// private final boolean validation;
//
// public EntityInfo(final String className, final String tableName, final Class<?> definition) {
// this.className = className;
// this.tableName = tableName;
// this.definition = definition;
// this.validation = false;
// }
//
// public EntityInfo(final String className, final String tableName, final Class<?> definition, final boolean validation) {
// this.className = className;
// this.tableName = tableName;
// this.definition = definition;
// this.validation = validation;
// }
//
// public String className() {
// return className;
// }
//
// public String table() {
// return tableName;
// }
//
// public Class<?> definition() {
// return definition;
// }
//
// public boolean hasValidation() {
// return validation;
// }
// }
//
// Path: droitatedDB/src/main/java/org/droitateddb/Utilities.java
// static <T> T getFieldValue(Class<?> aClass, String fieldName, Object data) {
// return getFieldValue(data, getDeclaredField(aClass, fieldName));
// }
| import java.util.Collection;
import java.util.List;
import static org.droitateddb.Utilities.getFieldValue;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import org.droitateddb.cursor.CombinedCursorImpl;
import org.droitateddb.entity.Column;
import org.droitateddb.entity.Entity;
import org.droitateddb.entity.PrimaryKey;
import org.droitateddb.schema.EntityInfo;
import org.droitateddb.validation.AccumulatedValidationResult;
import org.droitateddb.validation.InvalidEntityException;
import org.droitateddb.validation.ValidationToggle;
import java.lang.reflect.Field;
import java.util.ArrayList; | /*
* Copyright (C) 2014 The droitated DB Authors
*
* 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 org.droitateddb;
/**
* Provides support for executing CRUD operations on {@link org.droitateddb.entity.Entity} classes, such getting them from the database or
* saving them to the database.<br>
* <br>
* Each operation opens a connection to the {@link SQLiteDatabase}. If you want only one db connection use
* {@link ConnectedEntityService}
*
* @param <E> Entity, for which this service will be used
* @author Falk Appel
* @author Alexander Frank
*/
public class EntityService<E> {
private final Context context;
private final Class<E> entityClass;
private String tableName; | // Path: droitatedDB/src/main/java/org/droitateddb/schema/EntityInfo.java
// public class EntityInfo {
// private final String tableName;
// private final String className;
// private final Class<?> definition;
// private final boolean validation;
//
// public EntityInfo(final String className, final String tableName, final Class<?> definition) {
// this.className = className;
// this.tableName = tableName;
// this.definition = definition;
// this.validation = false;
// }
//
// public EntityInfo(final String className, final String tableName, final Class<?> definition, final boolean validation) {
// this.className = className;
// this.tableName = tableName;
// this.definition = definition;
// this.validation = validation;
// }
//
// public String className() {
// return className;
// }
//
// public String table() {
// return tableName;
// }
//
// public Class<?> definition() {
// return definition;
// }
//
// public boolean hasValidation() {
// return validation;
// }
// }
//
// Path: droitatedDB/src/main/java/org/droitateddb/Utilities.java
// static <T> T getFieldValue(Class<?> aClass, String fieldName, Object data) {
// return getFieldValue(data, getDeclaredField(aClass, fieldName));
// }
// Path: droitatedDB/src/main/java/org/droitateddb/EntityService.java
import java.util.Collection;
import java.util.List;
import static org.droitateddb.Utilities.getFieldValue;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import org.droitateddb.cursor.CombinedCursorImpl;
import org.droitateddb.entity.Column;
import org.droitateddb.entity.Entity;
import org.droitateddb.entity.PrimaryKey;
import org.droitateddb.schema.EntityInfo;
import org.droitateddb.validation.AccumulatedValidationResult;
import org.droitateddb.validation.InvalidEntityException;
import org.droitateddb.validation.ValidationToggle;
import java.lang.reflect.Field;
import java.util.ArrayList;
/*
* Copyright (C) 2014 The droitated DB Authors
*
* 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 org.droitateddb;
/**
* Provides support for executing CRUD operations on {@link org.droitateddb.entity.Entity} classes, such getting them from the database or
* saving them to the database.<br>
* <br>
* Each operation opens a connection to the {@link SQLiteDatabase}. If you want only one db connection use
* {@link ConnectedEntityService}
*
* @param <E> Entity, for which this service will be used
* @author Falk Appel
* @author Alexander Frank
*/
public class EntityService<E> {
private final Context context;
private final Class<E> entityClass;
private String tableName; | private final EntityInfo entityInfo; |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.