id
stringlengths
36
36
text
stringlengths
1
1.25M
8c130ad0-7dc4-4c5a-a39f-6188739616a6
boolean backupFile(byte file[], String filepath) throws RemoteException;
d32e3b91-a477-4400-84aa-aa7e0d379529
byte[] getFile(String filepath) throws RemoteException;
f4d6a27e-eccc-4875-93a7-073c5e965782
public ReplicationServer(){ try{ registry = LocateRegistry.getRegistry(); }catch(Exception e){} }
43cbc5bb-f55b-4ee9-94fa-380c3f24a474
public boolean registerBackupServer(String serverName){ try{ BServerRMI tempStub = (BServerRMI) registry.lookup(serverName); if(!backupServers.add(tempStub)) return false; else return true; }catch(Exception e){ System.err.println("Couldn't register backup server " + e.toString()); return false; }...
0d8e77d0-4d08-4d82-bacd-73a3144d16c6
public boolean backupFile(byte file[], String filepath){ if(backupServers.isEmpty()) return false; try { for(int i=0; i<backupServers.size(); i++){ backupServers.get(i).backupFile(file, filepath); System.out.println("BACKED UP"); } } catch (RemoteException e) { return false; } return tr...
0031582f-3793-4646-8cc9-e55e890ad213
public byte[] retrieveBackup(String filepath){ if(backupServers.isEmpty()) return null; byte file[] = null; try { for(int i=0; i<backupServers.size(); i++){ file = backupServers.get(i).getFile(filepath); if(file != null) break; } } catch (RemoteException e) { return null; } return fil...
92d1e086-81da-4fc9-95da-962ce4cd386a
public static void main(String args[]){ //Set code base so RMI can see the classes (classpath) System.setProperty("java.rmi.server.codebase", DServerRMI.class.getProtectionDomain().getCodeSource().getLocation().toString()); try{ //Initialise ReplicationServer RServerObj = new ReplicationServer(); RSer...
cd9ed51e-c1ca-476e-8838-ad5b8bab49c7
public Cache(){ for(int i=0; i < cacheSize; i++){ files[i] = null; dates[i] = null; } }
1a34e681-5d93-4b13-b231-d85e41ba45b9
public void addToCache(File in, Date inDate){ boolean inCache = false; int oldest = 0; for(int i=0; i < cacheSize; i++){ if(files[i] != null && files[i].getName().equals(in.getName())){ inCache = true; dates[i] = inDate; break; } if(dates[oldest] != null && dates[i] != null && dates[i].bef...
b86d2dd5-ec8a-4e3c-9c43-c505b5f01be3
public boolean checkValidInCache(File check){ boolean inCache = false; int cachePos = 0; for(int i=0; i < cacheSize; i++){ if(files[i] != null && files[i].getName().equals(check.getName())){ inCache = true; cachePos = i; break; } } if(!inCache) return false; //Contact directory serve...
5639abd6-6373-427e-a2e7-005c64542a18
boolean registerBackupServer(String serverName) throws RemoteException;
d8ecb79a-8652-4783-b342-708eb655b791
boolean backupFile(byte file[], String filepath) throws RemoteException;
ff07bd14-c757-4cc2-a4da-511bcfae98ae
byte[] retrieveBackup(String filepath) throws RemoteException;
356118d0-a415-48b0-b4d6-3f6a536ab0bf
public DirectoryServer(){ try{ Registry registry = LocateRegistry.getRegistry(null); FServerRMI FServerStub = (FServerRMI) registry.lookup("FileServer"); String[] fileList = FServerStub.getFileList(); //Build hashmap of files (name -> filepath) File tempF; for(int i=0; i<fileList.length; ...
209f2e99-f653-4b1a-9065-eef417fd3d42
private HashMap<String, String> getFileDir(String breadcrumbs){ String crumbs[] = breadcrumbs.split("/"); if(crumbs.length == 1 && crumbs[0].equals("")) crumbs = new String[0]; if(crumbs.length == 0){ return fileFolderStruct.files; } else{ FileFolderMapPair temp = fileFolderStruct.folders.get(crumbs[...
505d63f2-0690-4346-9625-b1c75b87c200
private HashMap<String, FileFolderMapPair> getFolderDir(String breadcrumbs){ String crumbs[] = breadcrumbs.split("/"); if(crumbs.length == 1 && crumbs[0].equals("")) crumbs = new String[0]; if(crumbs.length == 0){ return fileFolderStruct.folders; } else{ FileFolderMapPair temp = fileFolderStruct.fold...
a8956223-d329-42b5-b6af-d037ac187ebd
private AtomicReference<HashMap<String, FileFolderMapPair>> getFolderRef(String breadcrumbs){ String crumbs[] = breadcrumbs.split("/"); if(crumbs.length == 1 && crumbs[0].equals("")) crumbs = new String[0]; if(crumbs.length == 0){ return new AtomicReference<HashMap<String, FileFolderMapPair>>(fileFolderStru...
de4d9f7d-3a5b-49a1-b2ea-4c62c2b8b238
public String[] getFileFolderList(String breadcrumbs){ HashMap<String, String> fileDir = getFileDir(breadcrumbs); HashMap<String, FileFolderMapPair> folderDir = getFolderDir(breadcrumbs); if(folderDir == null && fileDir == null) return null; ArrayList<String> fileFolderList = new ArrayList<String>(); i...
6af95b43-57c6-469f-9789-1e8febf2dc5e
public String getFilePath(String breadcrumbs, String file){ HashMap<String, String> fileDir = getFileDir(breadcrumbs); if(fileDir == null) return null; return fileDir.get(file); }
53ea8930-8069-4f26-95be-0ba31e0f261c
public boolean renameFile(String breadcrumbs, String currentFilename, String newFilename){ HashMap<String, String> fileDir = getFileDir(breadcrumbs); if(fileDir == null) return false; if(!fileDir.containsKey(currentFilename) || fileDir.containsKey(newFilename)) return false; else{ fileDir.put(newFilename,...
0e29e2b3-48cf-4b57-b4d5-ecd0d7c1ed96
public boolean createFolder(String breadcrumbs, String newFolderName){ // HashMap<String, FileFolderMapPair> folderDir = getFolderDir(breadcrumbs); // if(folderDir == null) return false; // // if(folderDir.containsKey(newFolderName)) return false; //Cannot rename to existing folder name // else{ // folderDir.pu...
9d8ce656-5eae-4b57-8920-c03bd6d9a750
public boolean addNewFile(String breadcrumbs, String filename, String filepath){ HashMap<String, String> fileDir = getFileDir(breadcrumbs); if(fileDir == null) fileDir = new HashMap<String, String>(); if(fileDir.containsKey(filename)) return false; else{ fileDir.put(filename, filepath); return true;...
1a0b42f2-be53-4a16-bbce-111f09d741ee
public boolean checkTimestamp(String filename, Date time){ if(editTimes.containsKey(filename) && editTimes.get(filename) != null && editTimes.get(filename).equals(time)) return true; else return false; }
5fa063d7-b796-469d-bf6e-83775fc73493
public void updateTimestamp(String filename, Date time){ if(editTimes.containsKey(filename)) editTimes.remove(filename); editTimes.put(filename, time); }
171160f0-ca76-4a28-a115-b5766c6b1eb1
public static void main(String args[]){ //Set code base so RMI can see the classes (classpath) System.setProperty("java.rmi.server.codebase", DServerRMI.class.getProtectionDomain().getCodeSource().getLocation().toString()); try { Registry registry = LocateRegistry.getRegistry(); //Initialise Lock Ser...
5a17a70b-40ba-40de-aefc-63300077fff7
public static void main(String[] args) { try { AppGameContainer game = new AppGameContainer( new Core("Fort")); game.setDisplayMode(Window.WIDTH, Window.HEIGHT, false); game.start(); }catch(SlickException e) { System.out.println("Error creating game container"); e.printStackTrace(); } }
c49d47c4-7444-4cf6-a7df-833db83c3a51
public Core(String name) { super(name); }
f5d087af-9556-422f-a701-9affd7046371
public void init() { }
93d36c01-e33a-417b-a4af-2ee94fdb9978
public void initStatesList(GameContainer gc) { gc.setMinimumLogicUpdateInterval(33); gc.setTargetFrameRate(120); gc.setAlwaysRender(true); gc.setShowFPS(true); gc.setVSync(false); // <---------------- option to sync the display with the vertical refresh this.addState(new GameState()); //this.addState...
4144ced6-5a8d-46f9-b668-7dc951379733
public void init(GameContainer gc, StateBasedGame game) throws SlickException { world = new World(); world.generateMap(); keyInput = new KeyInput(Window.HEIGHT); }
74e3c7eb-fc4d-4b87-b7af-a3cf7111217a
public void update(GameContainer gc, StateBasedGame game, int delta) throws SlickException { keyInput.update(gc,game,delta); }
8cfe1273-ffcf-49ec-a5e8-67be50880fbf
public void render(GameContainer gc, StateBasedGame game, Graphics g) throws SlickException { world.render(g); }
bd6812bc-1e72-4691-9dd1-90416ff7643c
public int getID(){return States.GAME;}
a8d46afe-aea2-4016-b0b2-d25e418f60b8
public void init(GameContainer gc, StateBasedGame game) throws SlickException { }
ce634d24-ad78-4a78-907d-1527a81a77a1
public void update(GameContainer gc, StateBasedGame game, int delta) throws SlickException { }
660a6976-83e1-496f-a4c0-a6accb4cdf74
public void render(GameContainer gc, StateBasedGame game, Graphics g) throws SlickException { }
957bb4a5-2683-4831-b429-c3b428ccd66d
public int getID(){return States.START_MENU;}
70b664d6-eb87-4dd6-80f6-afebc3cfacf2
public KeyInput(int height) { input = new Input(height); }
78f91000-3baf-44d7-bb70-94fe4afd3ada
public void update(GameContainer gc, StateBasedGame game, int delta) { if(input.isKeyDown(Input.KEY_LEFT))Window.X -= 20; if(input.isKeyDown(Input.KEY_RIGHT))Window.X += 20; if(input.isKeyDown(Input.KEY_UP))Window.Y -= 20; if(input.isKeyDown(Input.KEY_DOWN))Window.Y+= 20; }
62af5b89-4299-48d8-93c0-a7b2b08b288c
public Tile() { setColors(); }
ece8451b-4848-43f8-a744-4d6928f87fd7
public Tile(Image image, int id) { this.image = image; this.ID = id; setColors(); }
555eab6e-b351-4f4a-a31e-a25af587b989
public Tile(Color c, int id) { this.color = c; this.ID = id; setColors(); }
f8aab0be-b56e-4b58-b024-f226cb43a131
private void setColors() { BLACK = Color.black; WHITE = Color.white; BLUE = Color.blue; GREEN = Color.green; GRAY = Color.gray; BROWN = new Color(87,59,12); YELLOW = Color.yellow; }
f6379747-b23b-4f3f-aac8-a872e1643a09
public void setID(int id){this.ID = id;}
9c0b328a-cc4c-4090-98fa-9850bc52d6d5
public void setColor(Color c){this.color = c;}
751e8b50-82df-432e-b89d-f13a47554fa5
public void setImage(Image image){this.image = image;}
0533129d-147c-4548-99de-b2b98ac73ec5
public Image getImage(){return this.image;}
ef68e674-c1fe-4abf-bb44-e436fb714722
public void render(Graphics g, float x, float y) { g.setColor(color); g.fillRect(x , y, TileMap.TILESIZE, TileMap.TILESIZE); }
b3d28381-2db2-4d55-b7bb-262c112b1bf7
public Tileset() { loadTileImages(); }
ecbde054-97f2-4c82-bfab-5a5f32691ceb
private void loadTileset() { }
a86497c4-e680-40a6-9de7-371b6750681c
private void loadTileImages() { images = new ArrayList<Image>(); try { images.add(Tile.BLANK, new Image("res/black.png")); images.add(Tile.DIRT, new Image("res/dirt.png")); images.add(Tile.GRASS, new Image("res/grass.png")); images.add(Tile.WATER, new Image("res/water.png")); }catch(SlickException...
a60e96dd-11d4-4118-b60b-a3765f4b6911
public ArrayList<Image> getTileImages(){return this.images;}
ff9014c5-942d-466a-aec2-71a5603c774f
public TileMap(int tilesize) { this.TILESIZE = tilesize; tileset = new Tileset(); }
4a26f3c5-c884-4b1f-9f08-bed5d0f9b76d
public void setTiles(int[][] map) { tiles = new Tile[map.length][map[0].length]; for(int i = 0; i < tiles.length; i++) { for(int j = 0; j < tiles[0].length; j++) { if(map[i][j] <= 35) { tiles[i][j] = new Tile(tileset.getTileImages().get(Tile.WATER), Tile.WATER); } if(map[i][j] > 35...
a95e8db0-4a9f-4221-927b-c351e0abf795
public void render(Graphics g) { for(int i = (int)Window.X / TILESIZE; i < (Window.X + Window.WIDTH) / TILESIZE; i++) { for(int j = (int)Window.Y / TILESIZE; j < (Window.Y + Window.HEIGHT) / TILESIZE; j++) { Image image = tileset.getTileImages().get(Tile.BLANK); if(i > 0 && i + Window.HEIGHT / TIL...
b092fae2-779e-433a-b905-04f0bb93377a
public World() { tilemap = new TileMap(12); worldGen = new WorldGenerator(); }
702e673f-2ead-4408-8751-36a47d5b2f47
public void loadTileset(String s) { }
f0506fcd-e54e-4d77-8d58-36126b4bfef1
public void generateMap() { tilemap.setTiles(worldGen.generateMap(3)); }
082bef66-1b19-4112-b8a6-0873a586857c
public void render(Graphics g) { tilemap.render(g); }
acede0fb-1921-4267-a99e-800dc512b911
public WorldGenerator() { }
b1134080-4eff-4537-9f49-d2da745fb545
public int[][] generateMap(int mapSize) { int[][] map = null; //sets map size (must be 2^n + 1) switch(mapSize) { case 1: map = new int[33][33]; break; case 2: map = new int[65][65]; break; case 3: map = new int[1025][1025]; break; } String seed = generateSeed()...
1a97f6b2-3882-4eca-943e-1500443f25e6
private int[][] fillHeight(int[][] map) { int length = map.length / 2; //fill center tile map[(map.length - 1) / 2][(map[0].length - 1) / 2] = (map[0][0] + map[0][map[0].length - 1] + map[map.length - 1][0] + map[map.length - 1][map[0].length - 1]) / 4 + random(); while (length > 0) { //do diam...
4fc63c46-7d05-4837-a71c-570d5297d1c4
private int[][] diamond(int[][] map, int x, int y, int length) { if(y - length == 0) { map[y-length][x] = (map[y][x] + map[y - length][x - length] + map[y - length][x + length]) / 3 + random(); } if(y + length == map.length - 1) { map[y+length][x] = (map[y][x] + map[y + length][x - lengt...
9c825759-7dbb-4803-9ea0-bb544c8f03d0
private int[][] square(int[][] map, int x, int y, int length) { //System.out.println("Test: " + x + ", " + y); //System.out.println("\tUpperLeft: " + (x - (length / 2)) + ", " + (y - (length / 2))); map[y - length / 2][x - length / 2] = (map[y - length][x - length] + map[y - length][x] + map[y][x ...
79c0165c-2643-4c29-a806-d92fe94e76d5
public int random() { Random r = new Random(); int one = r.nextInt(100); return (one - r.nextInt(100)) / smooth; }
b121ae1d-a9ef-4f75-8e04-a6cbed773852
public int[][] smooth(int[][] map) { map = heightBump(map); for(int i = 0; i < map.length - 1; i++) { for(int j = 0; j < map[0].length - 1; j++) { if((i == 0 && j == 0) || (i == map.length - 1 && j == 0) || (i == 0 && j == map[0].length - 1) || (i == map.length -1 && j == map[0].length -1)) ...
caa952ec-1f96-4c48-a74c-538d3cfef0d7
private int[][] heightBump(int[][] map) { for(int i = 0; i < map.length - 1; i++) { for(int j = 0; j < map[0].length - 1; j++) { if(map[i][j] % 10 >= 5) map[i][j] = map[i][j] + (10 - map[i][j] % 10); else map[i][j] = map[i][j] - (map[i][j] % 10); } } return map; }
28b301fd-b5b8-4c7d-ad06-6fdb9484f7a9
private String generateSeed() { Random r = new Random(); //set the four corner seeds for the map String seed = ""; for(int i = 0; i < 4; i++) { int temp = r.nextInt(100); if(temp < 10) seed += "0" + temp; else seed += temp; } System.out.println("Seed: " + seed); return seed; ...
8a1a9796-a650-47d9-89d4-fa29566bb316
public void start() { vertx.eventBus().registerHandler("ping-address", new Handler<Message<String>>() { @Override public void handle(Message<String> message) { message.reply("pong!"); container.logger().info("Sent back pong"); } }); container.logger().info("PingVerticle ...
6c31448f-edd2-436f-bfc6-0a8d80788683
@Override public void handle(Message<String> message) { message.reply("pong!"); container.logger().info("Sent back pong"); }
23858eb8-ab9e-416c-b7ae-be8806ec68e6
public void start() { final Logger logger = container.logger(); JsonObject jdbcConfig = new JsonObject() .putString("address", "jdbc.test") .putString("url", "jdbc:mysql://localhost:3306/vertx_test") .putString("username", "root") .putString("driver", "com.mysql.jdbc.Driver") .putString("password", ""); ...
5b279264-c961-4815-add5-9b20ac217afe
@Override public void handle(AsyncResult<String> msg) { logger.info(msg.succeeded()); logger.info(msg.result()); logger.info("connected!"); }
81e7ac24-7f5b-45f5-a85d-30ef9d21be0b
@Override public void handle(final HttpServerRequest request) { EventBus eventBus = vertx.eventBus(); if(request.path().equals("/test")) { request.response().putHeader("content-type", "text/plain"); request.response().end("This is Test. Hello World!"); } else if(request.path().equals("/save")...
eacf6623-a755-4d02-9852-8ae5d8535c7d
@Override public void handle(Message msg) { logger.info("response success"); request.response().putHeader("content-type", "text/plain"); request.response().end(msg.body().toString()); }
826f3b0a-856e-4b98-80c4-a8b02ec67e99
@Test public void testVerticle() { HelloWorld vert = new HelloWorld(); // do something with verticle }
8e5ddbbf-0d19-47dd-9460-91a5aaf5a54b
@Test public void __vertxDummy() { }
316d2819-de36-441e-a949-db90c7d4cc75
@Test public void __vertxDummy() { }
e9aaef6b-36f5-486a-8036-ba5ec1a78415
@Test public void __vertxDummy() { }
ec9e5c22-8195-450d-aa19-e48f8d6ee926
@Test public void testPing() { container.logger().info("in testPing()"); vertx.eventBus().send("ping-address", "ping!", new Handler<Message<String>>() { @Override public void handle(Message<String> reply) { assertEquals("pong!", reply.body()); /* If we get here, the test i...
5a94ac16-ff18-4780-b562-51825a8f0ad2
@Override public void handle(Message<String> reply) { assertEquals("pong!", reply.body()); /* If we get here, the test is complete You must always call `testComplete()` at the end. Remember that testing is *asynchronous* so we cannot assume the test is complete by the time...
2de87506-e5b9-4e2a-855d-793486c3b2fb
@Test public void testSomethingElse() { // Whatever testComplete(); }
21b468fe-dc38-4fe3-aabd-73fc2fd3eb87
@Override public void start() { // Make sure we call initialize() - this sets up the assert stuff so assert functionality works correctly initialize(); // Deploy the module - the System property `vertx.modulename` will contain the name of the module so you // don't have to hardecode it in your tests ...
f5b2178e-18af-4dd1-bed8-87e8e249f9ae
@Override public void handle(AsyncResult<String> asyncResult) { // Deployment is asynchronous and this this handler will be called when it's complete (or failed) assertTrue(asyncResult.succeeded()); assertNotNull("deploymentID should not be null", asyncResult.result()); // If deployed corr...
ae158d1f-5e96-4255-b49e-8be9008cd9fe
public void start() { VertxAssert.initialize(vertx); // You can also assert from other verticles!! VertxAssert.assertEquals("foo", "foo"); // And complete tests from other verticles VertxAssert.testComplete(); }
b6e6dd6c-6b08-49fb-8b01-eefc9e76eb6f
@Test /* This demonstrates using the Vert.x API from within a test. */ public void testHTTP() { // Create an HTTP server which just sends back OK response immediately vertx.createHttpServer().requestHandler(new Handler<HttpServerRequest>() { public void handle(HttpServerRequest req) { req...
55f06937-f8af-49b5-b769-d4e1e3a4161d
public void handle(HttpServerRequest req) { req.response().end(); }
37906097-5c73-4a0c-a7c3-b42117eac201
@Override public void handle(AsyncResult<HttpServer> asyncResult) { assertTrue(asyncResult.succeeded()); // The server is listening so send an HTTP request vertx.createHttpClient().setPort(8181).getNow("/",new Handler<HttpClientResponse>() { @Override public void handle...
52455912-1ca5-4ed7-bbe2-91543e98ad80
@Override public void handle(HttpClientResponse resp) { assertEquals(200, resp.statusCode()); /* If we get here, the test is complete You must always call `testComplete()` at the end. Remember that testing is *asynchronous* so we cannot assume the te...
a568eb75-7cd3-4844-833e-89ba14c8591e
@Test /* This test deploys some arbitrary verticle - note that the call to testComplete() is inside the Verticle `SomeVerticle` */ public void testDeployArbitraryVerticle() { assertEquals("bar", "bar"); container.deployVerticle(SomeVerticle.class.getName()); }
b4f0b448-7874-4e80-bebd-c2a52dafc2ff
@Test public void testCompleteOnTimer() { vertx.setTimer(1000, new Handler<Long>() { @Override public void handle(Long timerID) { assertNotNull(timerID); // This demonstrates how tests are asynchronous - the timer does not fire until 1 second later - // which is almost certain...
02128b94-3475-42d5-890d-f20f62864843
@Override public void handle(Long timerID) { assertNotNull(timerID); // This demonstrates how tests are asynchronous - the timer does not fire until 1 second later - // which is almost certainly after the test method has completed. testComplete(); }
25e443bf-959a-4129-bd56-83872dbfe272
@Test public void __vertxDummy() { }
39aeedf8-7d93-4354-b1bd-b90f77404128
public AppUser(){ babyOwned = new HashSet<Long>(); babySubed = new HashSet<Long>(); }
6b87b688-4cf6-4f39-8334-bf2e1460437b
public AppUser(String userName,String userEmail){ this.babyOwned = new HashSet<Long>(); this.babySubed = new HashSet<Long>(); this.userName = userName; this.userEmail = userEmail; }
b261c5c8-a5c3-4e30-a1ec-a69c89ff7b54
public static Objectify ofy() { return com.googlecode.objectify.ObjectifyService.ofy(); }
22be19a8-2834-4eb1-85c0-7ccb4a5f45be
public static ObjectifyFactory factory() { return com.googlecode.objectify.ObjectifyService.factory(); }
27150ecb-fc0e-4203-a0c7-513672c64c86
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException{ // user service to add in servlet UserService userService = UserServiceFactory.getUserService(); User user = userService.getCurrentUser(); String firstName = req.getParameter("firstName"); String lastName = req.ge...
2d3a8507-631f-41fd-9c63-ce23070a3212
private Date getBirthDay (String dateOfBirth) throws ParseException { return sdf.parse(" "+dateOfBirth+ " 00:00:00 "); }
f7c124ce-4803-4b5e-a7a1-df97912d9b77
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { resp.setContentType("text/plain"); resp.getWriter().println("Hello, world"); }
b1c830b1-37cc-472b-b656-e790a82642bc
@SuppressWarnings("unused") private Baby() { firstName="Tom's"; lastName="Baby"; gender = "M"; dateOfBirth = new Date(); createDate = new Date(); newUpdateDate = new Date(); visitTime = 0; pictureNum = 0; diaryNum = 0; // need to be changed to logo coverImageUrl = "http://www.full-stop.net/wp-con...