id
stringlengths 36
36
| text
stringlengths 1
1.25M
|
---|---|
88baf5e5-6b85-4da9-ab75-6629ae1d0333 | public InsertionChangeImpl(final int pos, final String s, final int oldDot, final int newDot) {
this.pos = pos;
this.changeString = s;
this.oldDot = oldDot;
this.newDot = newDot;
} |
69cca339-7771-496d-9645-bed2529c8a7f | @Override
public String getType() {
return ChangeType.INSERTION_TYPE.getType();
} |
8ac75bd3-c6cd-4de4-98c9-9e34e9ebed6f | @Override
public void apply(Document doc) {
doc.insert(pos, changeString);
doc.setDot(newDot);
} |
f095307f-744b-4932-93e7-dda321fe3ab1 | @Override
public void revert(Document doc) {
doc.delete(pos, changeString);
doc.setDot(oldDot);
} |
f90ef929-d665-4ff7-b2dd-c67bf2978881 | @Override
public String toString() {
return "InsertionChangeImpl{" +
"changeString='" + changeString + '\'' +
'}';
} |
a516548f-0bfd-49c6-8519-aeac5c3240b6 | @Override
public UndoManager createUndoManager(final Document doc, final int bufferSize) {
return new UndoManagerImpl(doc, bufferSize);
} |
12e19d11-397a-4a4a-9382-0dab49961fbc | @Override
public Change createDeletion(final int pos, final String s, final int oldDot, final int newDot) {
return new DeletionChangeImpl(pos, s, oldDot, newDot);
} |
d6ffce1d-9bb6-4b5f-9a52-cecd7b92f700 | @Override
public Change createInsertion(final int pos, final String s, final int oldDot, final int newDot) {
return new InsertionChangeImpl(pos, s, oldDot, newDot);
} |
005d72db-1ce2-4b74-9e73-58b432e39a05 | public UndoManagerImpl(final Document doc, final int bufferSize) {
UndoAssert.notNull(doc, "Document cannot be null");
UndoAssert.notValid(bufferSize, "Buffer size cannot be zero");
document = doc;
changListBufferSize = bufferSize;
undoLevel = bufferSize;
changeList = new LinkedList<Change>();
} |
21c7ab2d-d7b0-4d22-b3c4-5366cecd81fd | @Override
public void registerChange(final Change change) {
/*
Adding changes only till the size is not exhausted.
Else removing the change at the end of the stack
and adding a new on the top of the stack
*/
if (changeList.size() < changListBufferSize) {
changeList.addFirst(change);
} else {
System.out.println("Size exhausted. Removing last entry: " + changeList.removeLast().toString());
changeList.addFirst(change);
}
resetUndoLevel();
} |
2405e19d-b3fd-4fe6-9b7b-ea6cdc27ef4e | private void resetUndoLevel() {
undoLevel = 0;
canRedo = false;
} |
db1fbce7-f7de-4ef7-b0c6-721a909f8eaa | @Override
public boolean canUndo() {
/*
If no change is registered then Undo cannot be performed
*/
return changeList.size() > 0;
} |
90e3ad9d-3aed-444f-9597-3b9daa762d66 | @Override
public void undo() throws IllegalStateException {
if (!canUndo())
throw new IllegalStateException("Nothing to Undo");
if (undoLevel == changeList.size())
throw new IllegalStateException("Reached end of Undo Buffer");
changeList.get(undoLevel).revert(document);
/*
If undo is called before a new change is registered then
this will lead to the next change in the stack to be undone
*/
undoLevel++;
canRedo = true;
} |
5ce9c9e4-5df0-4332-b170-ef66e7d5af61 | @Override
public boolean canRedo() {
return canRedo;
} |
5243f243-b588-42c5-812b-08d0495a4f22 | @Override
public void redo() {
if (!canRedo())
throw new IllegalStateException("Nothing to Redo");
undoLevel--;
if (undoLevel < 0)
throw new IllegalStateException("Reached end of Redo Buffer");
changeList.get(undoLevel).apply(document);
} |
9f5c4fb3-c32a-44e1-8306-59a33ea874e7 | public DeletionChangeImpl(final int pos, final String s, final int oldDot, final int newDot) {
this.pos = pos;
this.changeString = s;
this.oldDot = oldDot;
this.newDot = newDot;
} |
53d60054-4c74-4ccd-9148-3c5c0bcd49a5 | @Override
public String getType() {
return ChangeType.DELETION_TYPE.getType();
} |
0c0d240d-74b2-4468-b144-2a8683c8d45b | @Override
public void apply(Document doc) {
doc.delete(pos, changeString);
doc.setDot(newDot);
} |
15621a9d-fbd3-4c57-90ef-0335f040b5de | @Override
public void revert(Document doc) {
doc.insert(pos, changeString);
doc.setDot(oldDot);
} |
4ab7d957-510d-4353-b89a-27a74e080b6a | @Override
public String toString() {
return "DeletionChangeImpl{" +
"changeString='" + changeString + '\'' +
'}';
} |
6099546f-ca72-496d-9a32-0c69b937b235 | public static void notNull(Object object, String message) {
if (object == null) {
throw new IllegalArgumentException(message);
}
} |
80ed9409-dea2-4ea0-9f41-804ace6ecfab | public static void notValid(int value, String message) {
if (value == 0) {
throw new IllegalArgumentException(message);
}
} |
ded4bed9-54ca-4b13-b9ab-5b81c0fb1268 | public void generate(Land[][] world) {
int width = world.length;
int depth = world[0].length;
int centerX = width/2;
int centerZ = depth/2;
float maxDist = (float)Math.sqrt((centerX)*(centerX) + (centerZ)*(centerZ));
System.out.println(maxDist);
for (int i = 0; i < width; i++) {
for (int j = 0; j < depth; j++) {
float grad = 1-((float)Math.sqrt((i-centerX)*(i-centerX) + (j-centerZ)*(j-centerZ))/maxDist);
grad *= grad*grad*grad*3;
world[i][j].height *= grad;
}
}
} |
0040de97-9e81-4b49-aa2e-48bc8c4ca7cf | public void generate(Land[][] world, float heightThreshold, float lakeLevel){
this.lakeLevel = lakeLevel;
this.world = world;
ArrayList<Land> startOptions = new ArrayList<Land>();
ArrayList<Land> riverStarts = new ArrayList<Land>();
for(int i = 0; i < world.length; i++){
for(int j = 0; j < world[0].length; j++){
if(world[i][j].height>=heightThreshold){
startOptions.add(world[i][j]);
j+=10;
i+=2;
}
}
}
int numRivers = (int) (Math.random()*startOptions.size());
System.out.println(numRivers);
int rand = 0;
for(int i = 0; i < numRivers; i++){
rand = (int) (Math.random()*startOptions.size());
if(rand == startOptions.size()){
rand--;
}
riverStarts.add(startOptions.get(rand));
startOptions.remove(rand);
}
for(int i = 0; i<riverStarts.size(); i++){
startRiver(riverStarts.get(i));
}
} |
8d5a3a37-3f91-4ebf-8df7-c8187ff3765a | public void startRiver(Land land){
land.isWeet = true;
int rand = (int)(Math.random()*4);
if(land.height > lakeLevel){
buildRiver(land, rand);
}
} |
01794153-2693-4286-a931-d1dd5b508553 | public boolean buildRiver(Land land, int direction){
land.isWeet = true;
int x = land.x;
int z = land.z;
if(land.height > lakeLevel){
if(direction == 0){
buildRiver(world[x-1][z], direction);
}else if(direction == 1){
buildRiver(world[x+1][z], direction);
}else if(direction == 2){
buildRiver(world[x][z-1], direction);
}else{
buildRiver(world[x][z+1], direction);
}
}
return true;
} |
ac32eb40-f10e-4b4d-b0cf-f4e7a3ecd454 | public void generate(Land[][] world, int heightScale) {
// seed for the world
seed = (float) (System.nanoTime()/10000000);
this.world = world;
// grid of results for the noise algorithm
functionResults = new float[(int) (world.length/xFreq)+4][(int) (world[0].length/zFreq)+4]; // adding 4 to create buffer on edges
int x = 0;
int z = 0;
// populate the results array
for(int i = 0; i<functionResults.length; i++){
for(int j = 0; j<functionResults[0].length; j++){
functionResults[i][j] = function(x-2*xFreq,z-2*zFreq); // making use of buffer
z+=zFreq;
}
x+=xFreq;
}
// interpolate the algorithm results and populate the world
for(int i = 0; i < world.length; i++){
for(int j = 0; j<world[0].length; j++){
world[i][j] = new Land(heightScale*interpolate(i,j),i,j);
}
}
} |
df0feb1c-6aa3-46d1-8956-1e6f270dbcf6 | public float function(int x, int z){
x = (z^x) << (x)^z;
x+=seed; // add seed to x for randomization (slight)
return Math.abs((1.0f - ((x * (x * x * prime1 + prime2) + prime3) & 0x7fffffff) * 0.000000000931322574615478515625f));
} |
133d69a8-c8c8-487b-8442-487463fe5c37 | public float interpolate(int x, int z){
int left= (int) (x/xFreq)+1;
int back = (z/zFreq);
float[] interps = new float[4];
for(int i = 0; i < 4; i++){
interps[i] = cubicInterpolate(functionResults[left-1][back], functionResults[left][back], functionResults[left+1][back], functionResults[left+2][back], ((float)(x%xFreq))/xFreq);
back++;
}
return cubicInterpolate(interps[0], interps[1], interps[2], interps[3], ((float)(z%zFreq))/zFreq);
} |
634660fd-c5d5-452a-be41-0023911eb296 | private float cubicInterpolate(float v0, float v1, float v2, float v3, float x) {
float P = (v3 - v2) - (v0 - v1);
float Q = (v0 - v1) - P;
float R = v2 - v0;
float S = v1;
return P*x*x*x + Q*x*x + R*x + S;
} |
a3ad3a2f-25a5-4e65-870f-f8308ea2aa40 | public float[][] generate(Land[][] world, float threshold) {
//build a boolean array of regions higher than threshold
int width = world.length;
int depth = world[0].length;
boolean[][] height = new boolean[width][depth];
for (int i = 0; i < width; i++) {
for (int j = 0; j < depth; j++) {
height[i][j] = (world[i][j].height >= threshold);
}
}
float[][] pressure = null;
//pick air direction, X or Z, + or - 1
int dir = 1 + Math.round(rGen.nextFloat() - 1) * 2; //direction is +1 or -1
if (rGen.nextFloat() > 0.5) {
pressure = flowX(dir, height);
} else {
pressure = flowZ(dir, height);
}
return pressure;
} |
0d97aaea-921f-4566-8450-c40a594b1896 | private float[][] flowX(int dir, boolean[][] height) {
//starting on one side, flow to the other
float[][] pressure = null;
return pressure;
} |
ee64aecf-a308-45fe-bf19-554cf81907b8 | private float[][] flowZ(int dir, boolean[][] height) {
//starting on one side, flow to the other
float[][] pressure = null;
return pressure;
} |
7a183023-d908-44e0-b639-00eb5538cfb4 | public static void update() {
long time = System.nanoTime();
dt = (time - lastTime)/1000000000f;
lastTime = time;
} |
e60619bc-7958-4d9f-bb59-89dc673ae742 | public Land(float height, int x, int z){
this.height = height;
this.x = x;
this.z = z;
} |
28d97365-7013-416f-9714-abbbc4af74de | public Camera() {
position = new Vector3f(0,-3,0);
rotation = new Vector3f(0,135,0);
} |
b855700f-da5e-43d8-b5d2-fe4e8aaf98a5 | public void update() {
glLoadIdentity(); //reset field of view to position = rotation = 0
float dt = Time.dt;
Vector3f velocity = new Vector3f();
//handle translation input
if (Keyboard.isKeyDown(Keyboard.KEY_W)) {
velocity.z += speed*dt;
} if (Keyboard.isKeyDown(Keyboard.KEY_S)) {
velocity.z -= speed*dt;
} if (Keyboard.isKeyDown(Keyboard.KEY_A)) {
velocity.x += speed*dt;
} if (Keyboard.isKeyDown(Keyboard.KEY_D)) {
velocity.x -= speed*dt;
} if (Keyboard.isKeyDown(Keyboard.KEY_SPACE)) {
velocity.y -= speed*dt;
} if (Keyboard.isKeyDown(Keyboard.KEY_LSHIFT)) {
velocity.y += speed*dt;
}
//handle rotation input
if (Keyboard.isKeyDown(Keyboard.KEY_Q)) {
rotation.y -= rotSpeed*dt;
} if (Keyboard.isKeyDown(Keyboard.KEY_E)) {
rotation.y += rotSpeed*dt;
}
//rotate the velocity based on the Y rotation
Vector3f vel = new Vector3f((float)(velocity.x*Math.cos(rotation.y*toRad) - velocity.z*Math.sin(rotation.y*toRad)),
velocity.y, (float)(velocity.x*Math.sin(rotation.y*toRad) + velocity.z*Math.cos(rotation.y*toRad)));
Vector3f.add(position, vel, position);
//translate world
GL11.glRotatef(rotation.y, 0, 1, 0);
GL11.glTranslatef(position.x, position.y, position.z);
} |
0211f4e5-5a27-4f1b-8d3c-a159e0cbbdd2 | public Driver() {
try {
Display.setDisplayMode(new DisplayMode(screenWidth, screenHeight));
Display.create();
} catch (LWJGLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
controller = new Controller();
Display.setTitle("Bahuta Island");
initGraphics();
controller.generate();
while (!Display.isCloseRequested()) {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
Time.update();
controller.update();
Display.update();
Display.sync(60);
}
Display.destroy();
} |
860e4928-a73b-48ce-b3eb-c4382fc68ec1 | public void initGraphics() {
GL11.glClearColor(135/255f, 1206/255f, 250/255f, 1.0f); // Blue Background
glEnable(GL_CULL_FACE);// Enables face culling (working)
glCullFace(GL_BACK); // Doesn't draw back faces
glEnable(GL_DEPTH_TEST);
glEnable(GL11.GL_TEXTURE_2D);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
GLU.gluPerspective(45.0f, Display.getWidth() / Display.getHeight(), 1.0f, 100.0f);
glMatrixMode(GL_MODELVIEW);
} |
fea8573d-db1f-4410-8fd3-0d0261a818e6 | public static void main(String[] args) {
new Driver();
} |
5f219aab-8bc4-43c2-af74-611d1358b88b | public Render() {
texture = loadTexture("Texture");
water = loadTexture("Water");
texture.bind();
} |
44beb670-5520-4a46-ab4e-7099bf38d1f6 | public void drawWater() {
int worldSize = Math.round(Controller.landSpacing * Controller.worldSize + 0.5f);
GL11.glColor3f(1, 1, 1);
water.bind();
GL11.glBegin(GL11.GL_QUADS);
GL11.glVertex3f(-1,0.1f, -1); //far left
GL11.glTexCoord2f(0, 0);
GL11.glVertex3f(-1, 0.1f, worldSize+2); //near left
GL11.glTexCoord2f(0, 1);
GL11.glVertex3f(worldSize+2, 0.1f, worldSize+2); //near right
GL11.glTexCoord2f(1, 1);
GL11.glVertex3f(worldSize+2, 0.1f, -1); //far right
GL11.glTexCoord2f(1, 0);
GL11.glEnd();
} |
d315113f-2064-4b4e-986c-b01b7b450c22 | public void update(Land[][] world) {
texture.bind();
GL11.glColor3f(.7f, .7f, .7f);
GL11.glBegin(GL11.GL_QUADS);
float wet = 0.5f;
//Draw the world
for (int i = 0; i < world.length-1; i++) { //x
for (int j = 0; j < world[0].length-1; j++) { //z
float size = Controller.landSpacing;
wet = 0;
if (world[i][j].isWeet) {
wet = 0.5f;
}
GL11.glVertex3f(0 + i*size, world[i][j].height, 0 + j*size); //far left
GL11.glTexCoord2f(0, 0+wet);
GL11.glVertex3f(0 + i*size, world[i][j+1].height, size + j*size); //near left
GL11.glTexCoord2f(0, 0.5f+wet);
GL11.glVertex3f(size + i*size, world[i+1][j+1].height, size + j*size); //near right
GL11.glTexCoord2f(1, 0.5f+wet);
GL11.glVertex3f(size + i*size, world[i+1][j].height, 0 + j*size); //far right
GL11.glTexCoord2f(1, 0+wet);
}
}
GL11.glEnd();
} |
2be13f7d-e9f5-4ba7-9d60-fcfd0c374b34 | public static Texture loadTexture(String name) {
Texture t = null;
try {
t = TextureLoader.getTexture("PNG", ResourceLoader.getResourceAsStream("res/"+name+".png"));
} catch (IOException e) {
e.printStackTrace();
System.exit(0);
}
return t;
} |
e57dac90-7f8e-4202-9182-4da05644ed32 | public Controller() {
draw = new Render();
cam = new Camera();
worldGen = new WorldGenerator();
radGrad = new RadialGradient();
airGen = new AirGenerator();
riverGen = new RiverGenerator();
world = new Land[worldSize][worldSize];
} |
5a3a3b85-d0d2-4d47-a1a4-313a015c07b4 | public void generate() {
worldGen.generate(world,scale);
radGrad.generate(world);
airGen.generate(world, 1.65f);
riverGen.generate(world, 0.80f, 0.1f);
} |
fe04affa-eef2-4fa5-9cf2-86a72536d182 | public void update() {
//render
draw.update(world);
draw.drawWater();
cam.update();
} |
985f2b95-46d1-4875-9830-69f5ce4caa1f | public Directory(String name) {
super(name);
this.nodes = new HashMap<String, Node>();
} |
a993c0c7-7857-4584-abbb-a169ded0eaf4 | public void appendChild(Node node) {
if (!this.nodes.containsKey(node.getName())) {
System.out.println(this.name + " append child " + node.getName());
this.nodes.put(node.getName(), node);
} else
System.out.println(this.name + " already contains child "
+ node.getName());
} |
fcf5db53-b5c5-4c07-843a-c4d2c80a853d | public boolean hasChild(String name) {
return this.nodes.containsKey(name);
} |
1dbda1c5-a1d5-435d-8951-0e5a18031f0d | public void generate(ArrayList<Node> input) {
for (Iterator<Node> iterator = input.iterator(); iterator.hasNext();) {
Node i = iterator.next();
if (!this.hasChild(i.getName())) {
this.appendChild(i);
i = nodes.get(i.getName());
iterator.remove();
i.generate(input);
} else {
i = nodes.get(i.getName());
iterator.remove();
i.generate(input);
}
}
} |
ac9f32a9-3363-4827-bd21-14a79bd045bd | public void print() {
this.doSpace(y);
System.out.println(name);
y++;
Node k;
Set<String> set = this.nodes.keySet();
for (String i : set) {
k = this.nodes.get(i);
k.print();
}
y--;
} |
be6e7933-6550-4fca-b032-b4d493d43339 | public File(String name) {
super(name);
} |
d113a09c-b5f9-4e98-b11f-74348383a438 | public void print() {
doSpace(y);
System.out.println(name + " This is File");
} |
7b6ee278-8e0a-41f9-a041-8224d0ce8ffa | public void print() {
}; |
553fcb6c-c6b6-4a7a-93ad-e5254e2244fd | public void generate(ArrayList<Node> input) {
}; |
0233d31f-dab8-4080-9bde-c069bcb62a6b | public void appendChild(Node node) {
}; |
38ede573-f10b-420a-a1ab-124f3691b251 | public boolean hasChild(String name) {
return false;
}; |
605cfe01-ec56-4d79-b8e7-2a395855a292 | public Node(String name) {
this.name = name;
} |
53ef436e-1701-4961-bcf3-2d445e9e489c | public String getName() {
return this.name;
} |
23e2baec-9edc-435a-99f6-2dc54c10a387 | public void doSpace(int i) {
for (int k = 0; k <= i; k++)
System.out.print("__.");
} |
10eb0b86-7b5b-4fac-8558-ddbe8af8890e | public static ArrayList<Node> userInput() {
// вроде же попроще можно эмм.. прочесть ввод. не?
// хз я не заморачивалась)
// это из гугла пример или учили?гугл.впринципе и препод тож про сканер говорил
// на новой строке отвечай )
// окай) а как проще?
// не помню уже. ща покопаюсь. напиши-ка что-нить
// ауу!
// я тута
// вот
// не буду удалять этот коммент )) смотрится стёбно )
// ))
Scanner scan = new Scanner(System.in);
String s;
do {
System.out.print("Enter path: ");
s = scan.next();
} while (!checkString(s));
String[] res = s.split("/");
ArrayList<Node> listRes = new ArrayList<Node>();
Node f;
for (String stName : res) {
if (stName.contains(".")) {
f = new File(stName);
listRes.add(f);
break;
} else {
f = new Directory(stName);
listRes.add(f);
}
}
return listRes;
} |
e7366996-e5cc-46ae-ae51-51b297eb1a32 | private static boolean checkString(String str) {
if ((str.isEmpty()) || (str.charAt(0) == '/')) {
System.out
.println("Your path is incorrect or empty! :(\n Try again!^^");
return false;
}
return true;
} |
83d6c88f-d84a-4d64-9af1-625884a9904c | public static int getChoise() {
Scanner scan = new Scanner(System.in);
System.out
.println("Enter:\n\t 1 add path \n\t 2 for print hierarchy \n\t etc for exit");
String s = scan.next();
return Integer.parseInt(s);
} |
cee92f44-8402-4f1b-a31d-190ad4d0707a | public static void main(String args[]) {
ArrayList<Node> input;
Directory dir = new Directory("root");
int choise = 1;
do {
choise = Slogger.getChoise();
switch (choise) {
case 1: {
input = Slogger.userInput();
dir.generate(input);
}
break;
case 2:
dir.print();
break;
}
} while ((choise == 1) || (choise == 2));
} |
2b3b2290-0578-4171-849d-88de2353e716 | public String getMessage() {
return message;
} |
aef2b9e5-d06f-479e-b2c4-ba4260def53f | public int getMessageRepetitions() {
return messageRepetitions;
} |
f2266849-296f-434a-b933-b6c35c323bfb | public String getAdditionalMessage() {
return additionalMessage;
} |
55122d4a-b7bb-4ecc-845a-2e3c47669eef | public DataSourceFactory getDataSourceFactory() {
return database;
} |
4210650c-8828-4d7d-b72a-3bda5e720e5e | public PhonebookAuthenticator(DBI jdbi) {
userDao = jdbi.onDemand(UserDAO.class);
} |
14ca31f7-40c1-4a74-9e74-cb7ed738be2f | public Optional<Boolean> authenticate(BasicCredentials c) throws AuthenticationException {
boolean validUser = (userDao.getUser(c.getUsername(), c.getPassword()) == 1);
if (validUser) {
return Optional.of(true);
}
return Optional.absent();
} |
a38c7654-4669-4ab8-a132-b9af797ca26e | public static void main(String[] args) throws Exception {
new App().run(args);
} |
52dd29ce-3ac3-4ea4-b3ac-98969a182005 | @Override
public void initialize(Bootstrap<PhonebookConfiguration> b) {
b.addBundle(new AssetsBundle());
b.addBundle(new ViewBundle());
} |
8478dc22-71f8-4b8b-bbad-11abe77c80cc | @Override
public void run(PhonebookConfiguration c, Environment e) throws Exception {
LOGGER.info("Method App#run() called");
for (int i = 0; i < c.getMessageRepetitions(); i++) {
System.out.println(c.getMessage());
}
System.out.println(c.getAdditionalMessage());
// Create a DBI factory and build a JDBI instance
final DBIFactory factory = new DBIFactory();
final DBI jdbi = factory
.build(e, c.getDataSourceFactory(), "mysql");
// Add the resource to the environment
e.jersey().register(new ManagerResource(jdbi, e.getValidator()));
e.jersey().register(new ContactResource(jdbi, e.getValidator()));
// build the client and add the resource to the environment
final Client client = new JerseyClientBuilder(e).build("REST Client");
client.addFilter(new HTTPBasicAuthFilter("john_doe", "secret"));
// e.jersey().register(new ClientResource(client));
// Authenticator, with caching support (CachingAuthenticator)
CachingAuthenticator<BasicCredentials, Boolean> authenticator = new CachingAuthenticator<BasicCredentials, Boolean>(
e.metrics(),
new PhonebookAuthenticator(jdbi),
CacheBuilderSpec.parse("maximumSize=10000, expireAfterAccess=10m"));
// Register the authenticator with the environment
e.jersey().register(new BasicAuthProvider<Boolean>(
authenticator, "Web Service Realm"));
// Add health checks
e.healthChecks().register("New Contact health check", new NewContactHealthCheck(client));
} |
bc8b763d-e240-413d-a976-7693cf39f160 | @Mapper(ManagerMapper.class)
@SqlQuery("select * from managers where id = :id")
Manager getManagerById(@Bind("id") int id); |
4fc7f45e-10b8-4d79-979b-f65e76656c8f | @SqlQuery("select * from managers")
List <Manager> getAllManagers(); |
dd7e7b35-7265-4d13-89d5-95177d131e1c | @Mapper(ContactMapper.class)
@SqlQuery("select * from locations where id = :id")
Contact getContactById(@Bind("id") int id); |
54c3228d-9f34-4050-b66a-257ff38663af | @SqlQuery("select * from locations")
List <Contact> getAllContacts(); |
1b249643-62e0-43f5-8e9f-bb0b4ca2f817 | @GetGeneratedKeys
@SqlUpdate("insert into locations (id, location_name) values (NULL, :location_name)")
int createContact(@Bind("location_name") String location_name); |
3b129009-7494-4e78-9e6a-028853839dfa | @SqlUpdate("update locations set location_name = :location_name,where id = :id")
void updateContact(@Bind("id") int id, @Bind("location_name") String location_name); |
c840bfcc-a59e-423a-bcee-6335d82d92e1 | @SqlUpdate("delete from locations where id = :id")
void deleteContact(@Bind("id") int id); |
9c4f903a-5e60-4f34-b2a2-7a1954d40d73 | @SqlQuery("select count(*) from users where username = :username and password = :password")
int getUser(@Bind("username") String username, @Bind("password") String password); |
f34b48c4-bd5c-4f42-b223-ccca54a6b07c | public Manager map(int index, ResultSet r, StatementContext ctx)
throws SQLException {
return new Manager(r.getInt("id"), r.getString("manager_name"));
} |
29f0afd3-9a68-4482-b850-ff3395071ad9 | public Contact map(int index, ResultSet r, StatementContext ctx)
throws SQLException {
return new Contact(r.getInt("id"), r.getString("location_name"));
} |
2c36843e-f7cd-4d61-ab84-8b21a03c960e | public Manager(){
this.id = 0;
this.manager_name = null;
} |
8f8342df-4c45-4504-a385-63534847bf7f | public Manager(int id, String manager_name){
this.id = id;
this.manager_name= manager_name;
} |
b2ef529b-3b71-4ae4-9ed2-154ffa7b55f3 | public int getId(){
return id;
} |
e29e33c9-2866-44d3-be82-63688ff6cb9a | public String getManager(){
return manager_name;
} |
f311760e-d015-4a83-893b-84ce591f0c2c | public Contact() {
this.id = 0;
this.location_name = null;
} |
ed070ef0-3b84-4cbe-94f4-431aab67d1d5 | public Contact(int id, String location_name){
this.id = id;
this.location_name = location_name;
} |
3180ed12-232c-4c84-90b8-4ce865db3cd2 | public int getId() {
return id;
} |
8adbbe0d-b14d-43f7-b427-3b30d9153f41 | public String getLocation(){
return location_name;
} |
efa8070c-c57e-46a2-83f6-fa65510bf5e2 | @JsonIgnore
@ValidationMethod(message="John Doe is not a valid person!")
public boolean isValidPerson() {
if (location_name.equals("YYY")) {
return false;
} else {
return true;
}
} |
30a15436-944c-4946-8e71-1039a5e5ca41 | public NewContactHealthCheck(Client client) {
super();
this.client = client;
} |
3b576505-8869-4150-b2d5-67ef7875eae6 | @Override
protected Result check() throws Exception {
WebResource contactResource = client
.resource("http://localhost:8080/contact");
ClientResponse response = contactResource.type(
MediaType.APPLICATION_JSON).post(
ClientResponse.class,
new Contact(0, "Health Check Location"));
if (response.getStatus() == 201) {
return Result.healthy();
}
else {
return Result.unhealthy("New Contact cannot be created!");
}
} |
dff87c9e-ff0c-4428-9936-4fed2c264ada | public ManagerResource(DBI jdbi, Validator validator) {
managerDao = jdbi.onDemand(ManagerDAO.class);
this.validator = validator;
} |
43fb0eca-6994-4634-9c17-cba8b4a4e03c | @GET
@Path("/all")
public Response getAllManagers(@Auth Boolean isAuthenticated){
int countRows = 2; //always be one ahead of index to keep while condition true
int index= 1; //first contact
ArrayList <Manager> managers = new ArrayList<Manager>();
while(index<countRows){
Manager manager = managerDao.getManagerById(index);
if(!(manager ==null)){
managers.add(manager);
index++; //keep the while condition true
countRows++;
}
else{
index++; //while condition will fail because there are no more entries in the table
}
}
return Response.ok(managers).build();
} |
fabc8cdb-4fb2-4465-bb51-37b14352430f | @GET
@Path("/{id}")
public Response getManager(@PathParam("id") int id, @Auth Boolean isAuthenticated) {
// retrieve information about the contact with the provided id
Manager manager = managerDao.getManagerById(id);
return Response
.ok(manager)
.build();
} |
8a7c409e-3886-4c73-8e23-642402ae27e7 | public ContactResource(DBI jdbi, Validator validator) {
contactDao = jdbi.onDemand(ContactDAO.class);
this.validator = validator;
} |
462bc5a2-2bc9-45ca-ba84-8cda32b43476 | @GET
@Path("/all")
public Response getAllContacts(@Auth Boolean isAuthenticated){
int countRows = 2; //always be one ahead of index to keep while condition true
int index= 1; //first contact
ArrayList <Contact> contacts = new ArrayList<Contact>();
while(index<countRows){
Contact contact = contactDao.getContactById(index);
if(!(contact ==null)){
contacts.add(contact);
index++; //keep the while condition true
countRows++;
}
else{
index++; //while condition will fail because there are no more entries in the table
}
}
return Response.ok(contacts).build();
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.