id
stringlengths
36
36
text
stringlengths
1
1.25M
4c71d54c-d634-4f11-83fa-13a1e841a79f
public void processsImage(File key, String out, int IMG_WIDTH, int IMG_HEIGHT) { BufferedImage originalImage = null; try { originalImage = ImageIO.read(key); int type = originalImage.getType() == 0 ? BufferedImage.TYPE_INT_ARGB : originalImage.getType(); BufferedImage key2 = resizeImage(originalImage, type, IMG_WIDTH, IMG_HEIGHT); String nName = key.getName().toString().substring(0, key.getName().indexOf(".")); ImageIO.write(key2, "jpg", new File(out + nName + "_" + IMG_HEIGHT + "x" + IMG_WIDTH + ".jpg")); System.out.println("Created: " + out + nName + "_" + IMG_HEIGHT + "x" + IMG_WIDTH + ".jpg"); } catch (IOException e) { JOptionPane.showMessageDialog(null, "Problem z zapisem", "ERROR", JOptionPane.ERROR_MESSAGE); //System.exit(0); } catch (NullPointerException e) { System.out.println("ERROR niepoprawny plik"); } }
de417f9d-fabe-4154-bef8-04f7ac131a4b
public Resizer(Gallery gal, int i, String writeFile, int IMG_WIDTH, int IMG_HEIGHT) { this.id = i; this.gal = gal; this.IMG_WIDTH = IMG_WIDTH; this.IMG_HEIGHT = IMG_HEIGHT; this.writeFile = writeFile; }
1337acc0-f243-45fb-9c21-e7721d2f843e
public void run() { try { File key; while ((key = gal.lockPicture()) != null) { System.out.println("Processing " + key + " thread " + id); ImgProcessor ip = new ImgProcessor(); ip.processsImage(key, writeFile, IMG_WIDTH, IMG_HEIGHT); gal.unlockPicture(key); Thread.sleep(5); } } catch (InterruptedException e) { e.printStackTrace(); } }
8e32e4e5-4c72-42fc-ba83-d453b97b80fa
public Craft() { ImageIcon ii = new ImageIcon(this.getClass().getResource(craft)); image = ii.getImage(); width = image.getWidth(null); height = image.getHeight(null); missiles = new ArrayList(); visible = true; x = 40; y = 60; }
5ed90c45-c520-4ae0-ae31-376f07133a2e
public void move() { x += dx; y += dy; if (x < 1) { x = 1; } if (y < 1) { y = 1; } }
838ae692-387f-4e6a-90a2-9dba217da665
public int getX() { return x; }
b3467160-42e2-4394-b123-bb13cfde27b4
public int getY() { return y; }
e6c56654-cc12-49d8-b9c0-ec33dc9bb425
public Image getImage() { return image; }
699dbcd9-7b44-4a21-98e2-d7f1379e8309
public ArrayList getMissiles() { return missiles; }
b8492d35-ffb5-4fb3-a513-c5335656bf64
public void setVisible(boolean visible) { this.visible = visible; }
e02e43c5-7890-4ebe-9e31-6d49d4b2fe5c
public boolean isVisible() { return visible; }
f983fb33-5cf6-4c74-b647-88c3b577f404
public Rectangle getBounds() { return new Rectangle(x, y, width, height); }
f83a2c17-0021-4bc2-ac9e-df0dde86a182
public void keyPressed(KeyEvent e) { int key = e.getKeyCode(); if (key == KeyEvent.VK_SPACE) { fire(); } if (key == KeyEvent.VK_LEFT) { dx = -1; } if (key == KeyEvent.VK_RIGHT) { dx = 1; } if (key == KeyEvent.VK_UP) { dy = -1; } if (key == KeyEvent.VK_DOWN) { dy = 1; } }
57de93f1-71d5-47d2-b142-d78a90ae3698
public void fire() { missiles.add(new Missile(x + width, y + height/2)); }
d34ca324-c415-475b-a23f-7ac1928de675
public void keyReleased(KeyEvent e) { int key = e.getKeyCode(); if (key == KeyEvent.VK_LEFT) { dx = 0; } if (key == KeyEvent.VK_RIGHT) { dx = 0; } if (key == KeyEvent.VK_UP) { dy = 0; } if (key == KeyEvent.VK_DOWN) { dy = 0; } }
22973ce2-bbbf-463b-aee9-bb6256e18872
public Board() { addKeyListener(new TAdapter()); setFocusable(true); setBackground(Color.BLACK); setDoubleBuffered(true); ingame = true; setSize(400, 300); craft = new Craft(); initAliens(); timer = new Timer(5, this); timer.start(); }
ef6edc46-ddca-4a2e-8362-c0b3c82597ce
public void addNotify() { super.addNotify(); B_WIDTH = getWidth(); B_HEIGHT = getHeight(); System.out.println(B_WIDTH); }
3491a0ed-7214-438e-9347-7a2818a6c537
public void initAliens() { aliens = new ArrayList(); for (int i=0; i<pos.length; i++ ) { aliens.add(new Alien(pos[i][0], pos[i][1])); } }
a70b0a59-f14b-44ba-8425-98460d6b8a05
public void paint(Graphics g) { super.paint(g); if (ingame) { Graphics2D g2d = (Graphics2D)g; if (craft.isVisible()) g2d.drawImage(craft.getImage(), craft.getX(), craft.getY(), this); ArrayList ms = craft.getMissiles(); for (int i = 0; i < ms.size(); i++) { Missile m = (Missile)ms.get(i); g2d.drawImage(m.getImage(), m.getX(), m.getY(), this); } for (int i = 0; i < aliens.size(); i++) { Alien a = (Alien)aliens.get(i); if (a.isVisible()) g2d.drawImage(a.getImage(), a.getX(), a.getY(), this); } g2d.setColor(Color.WHITE); g2d.drawString("Aliens left: " + aliens.size(), 5, 15); } else { String msg = "Game Over"; Font small = new Font("Helvetica", Font.BOLD, 14); FontMetrics metr = this.getFontMetrics(small); g.setColor(Color.white); g.setFont(small); g.drawString(msg, (B_WIDTH - metr.stringWidth(msg)) / 2, B_HEIGHT / 2); } Toolkit.getDefaultToolkit().sync(); g.dispose(); }
605c374f-1448-4494-8ab5-b87f419e70f5
public void actionPerformed(ActionEvent e) { if (aliens.size()==0) { ingame = false; } ArrayList ms = craft.getMissiles(); for (int i = 0; i < ms.size(); i++) { Missile m = (Missile) ms.get(i); if (m.isVisible()) m.move(); else ms.remove(i); } for (int i = 0; i < aliens.size(); i++) { Alien a = (Alien) aliens.get(i); if (a.isVisible()) a.move(); else aliens.remove(i); } craft.move(); checkCollisions(); repaint(); }
aa626886-ef98-43e4-8bcf-16fced133242
public void checkCollisions() { Rectangle r3 = craft.getBounds(); for (int j = 0; j<aliens.size(); j++) { Alien a = (Alien) aliens.get(j); Rectangle r2 = a.getBounds(); if (r3.intersects(r2)) { craft.setVisible(false); a.setVisible(false); ingame = false; } } ArrayList ms = craft.getMissiles(); for (int i = 0; i < ms.size(); i++) { Missile m = (Missile) ms.get(i); Rectangle r1 = m.getBounds(); for (int j = 0; j<aliens.size(); j++) { Alien a = (Alien) aliens.get(j); Rectangle r2 = a.getBounds(); if (r1.intersects(r2)) { m.setVisible(false); a.setVisible(false); } } } }
ebc6ba01-df0f-47b5-a5ea-f00074737065
public void keyReleased(KeyEvent e) { craft.keyReleased(e); }
65e12ef5-d1e5-4ad4-9ae1-579698ff39d9
public void keyPressed(KeyEvent e) { craft.keyPressed(e); }
6526bb82-4b14-407f-95f7-498c910c3464
public Missile(int x, int y) { ImageIcon ii = new ImageIcon(this.getClass().getResource("missile.png")); image = ii.getImage(); visible = true; width = image.getWidth(null); height = image.getHeight(null); this.x = x; this.y = y; }
8a046d04-1192-418e-9aec-644a79001cd9
public Image getImage() { return image; }
7e3bdf7d-7d71-45ee-b489-54154204f527
public int getX() { return x; }
69202897-e0b0-49c0-9dc6-33da9bc3f5d8
public int getY() { return y; }
2396206f-a04b-4a60-87b6-2ddb9e927ed7
public boolean isVisible() { return visible; }
36559b85-349b-46e6-806e-454d57abb1f0
public void setVisible(Boolean visible) { this.visible = visible; }
29d31216-c167-4f35-923b-1222fb657f2c
public Rectangle getBounds() { return new Rectangle(x, y, width, height); }
4e96063c-8ff1-4c30-b514-5f0158be859f
public void move() { x += MISSILE_SPEED; if (x > BOARD_WIDTH) visible = false; }
cd96ae41-34b7-474e-bc4b-6ef1a9a8c208
public Collision() { add(new Board()); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setSize(400, 300); setLocationRelativeTo(null); setTitle("Collision"); setResizable(false); setVisible(true); }
b12e1324-3d60-44f9-bed4-a3665d8a9a12
public static void main(String[] args) { new Collision(); }
18eabe56-76f7-42bb-b9bf-003109c09ffb
public Alien(int x, int y) { ImageIcon ii = new ImageIcon(this.getClass().getResource(craft)); image = ii.getImage(); width = image.getWidth(null); height = image.getHeight(null); visible = true; this.x = x; this.y = y; }
d29f1c89-1e28-4833-b1b4-c989cbaa37e4
public void move() { if (x < 0) x = 400; x -= 1; }
5a02227e-7382-4d31-bb66-2c80a509e98f
public int getX() { return x; }
f3967b06-7819-4bef-a419-3831cf642a49
public int getY() { return y; }
405a422a-a743-4389-b76e-2bda8df807a8
public boolean isVisible() { return visible; }
fe635040-778f-4a0b-bb19-a7e772869e02
public void setVisible(Boolean visible) { this.visible = visible; }
5502e428-9f21-4e02-aa6c-9c49e618492c
public Image getImage() { return image; }
eb8de42b-8f7d-4ffb-a7db-42bd3c3f8701
public Rectangle getBounds() { return new Rectangle(x, y, width, height); }
ee7138e7-91db-4cc1-84ec-2a9dc33c6248
public static SessionFactory getSessionFactory() { return sessionFactory; }
4fda1dd8-0a20-4a4e-b1d0-ddbbe8f5ee6a
public static void closeSessionFactory() { sessionFactory.close(); }
af617777-55b3-4668-b8cc-f4543b0a503b
public void insertGarage( Garage garage );
2762c4fe-0721-4a09-9939-401cf531bff5
public Garage getGarage( int iId );
a7aa4ec6-e3d7-4a4b-b570-a44e31a80d0a
public Garage getGarageByCity( String iName );
086fa548-5849-40ae-b5a3-be8456d7eecf
public void insertGarage( Garage iGarage ) throws HibernateException { // Create the SessionFactory from hibernate.cfg.xml Session session = HibernateUtils.getSessionFactory().getCurrentSession(); try{ Transaction transaction = session.beginTransaction(); session.merge( iGarage ); transaction.commit(); } catch ( HibernateException e ) { throw new HibernateException( e.getMessage() ); } }
afb3a129-c74f-4481-9da9-b2b9a63c7921
public Garage getGarage( int iId ) throws HibernateException { // Create the SessionFactory from hibernate.cfg.xml Session session = HibernateUtils.getSessionFactory().getCurrentSession(); try{ session.beginTransaction(); // From Garage -> class mapped in configuration Query query = session.createQuery("FROM Garage WHERE id_hotel = :id_hotel"); query.setParameter("id_hotel", iId); List<?> lQuery = query.list(); return (Garage) lQuery.get(0); } catch (HibernateException e) { throw new HibernateException(e.getMessage()); } }
99bc4f27-d6b6-4ba7-85f6-d111ffdac6cb
public Garage getGarageByCity( String iCity ) throws HibernateException { // Create the SessionFactory from hibernate.cfg.xml Session session = HibernateUtils.getSessionFactory().getCurrentSession(); try{ session.beginTransaction(); // From Garage -> class mapped in configuration Query query = session.createQuery("FROM Garage WHERE city = :city"); query.setParameter("city", iCity); List<?> lQuery = query.list(); Garage oG = (Garage) lQuery.get(0); return oG; } catch (HibernateException e) { throw new HibernateException(e.getMessage()); } catch (IndexOutOfBoundsException ioobe) { // Protecting from empty list - returning null return null; } }
30378bda-0145-4570-b53e-73bae0019c0b
public static void main( String args[] ) { // Creating random instances to store in the database Garage gMad = new Garage(); gMad.setCity( "Madrid" ); gMad.setName( "SEAT" ); gMad.setIsOfficial(true); Garage gBar = new Garage(); gBar.setCity( "Barcelona" ); gBar.setName( "La Rueda" ); Garage gSev = new Garage(); gSev.setCity( "Sevilla" ); gSev.setName( "Sevilla Sur" ); IGarageDAO lGDI = new GarageDAOImpl(); System.out.println( "Insert garages" ); // Inserts to database lGDI.insertGarage( gMad ); lGDI.insertGarage( gBar ); lGDI.insertGarage( gSev ); // Retrieving from Database Garage gs = lGDI.getGarageByCity( "Sevilla" ); if ( null != gs ) System.out.println( "Garage Id: " + gs.getId() + ", name: " + gs.getName() + " ( " + gs.getCity() + " )"); else System.out.println("Query did not resolved to a value"); // Finish session factory: terminate program HibernateUtils.closeSessionFactory(); }
5449f596-a615-4623-86d8-e6ea10e3ea79
public void setId( int id ) { this.mIdGarage = id; }
4d95d4df-49a0-43b3-9ae8-900041f0f3f3
public int getId() { return this.mIdGarage; }
ac081b06-8d4d-49e1-ad2c-e5728bea058a
public void setCity( String name ) { this.mCity = name; }
478d092f-2928-4476-a8c7-50da9df6428d
public String getCity() { return this.mCity; }
ea444569-2ad0-43a9-85d4-853fca04780a
public void setName( String name ) { this.mName = name; }
0678f9ee-afef-4f91-bd88-5ad7226e1926
public String getName() { return this.mName; }
791748c2-9e43-4c41-b166-7d7243eb13d7
public void setIsOfficial( boolean iIsOfficial ) { this.mIsOfficial = iIsOfficial; }
1db5eead-dd6e-46a3-9b01-b2f27e9ab379
public BaconNode ( String[] name ) { this.name = name; }
a4610e45-079c-4828-aca5-3712669f439c
public String[] getName ( ) { return name; }
3a91c96c-d817-4160-82d2-404390390c34
public HashMap<String, String> getRoles ( ) { return roles; }
bf1ef955-eccf-43d6-bf9e-c094d62b3800
public void addRole ( String movie, String role ) { roles.put(movie, role); }
b96891b7-56a1-4074-a947-cd07e8dfe23b
public BaconEdge ( BaconNode v1, BaconNode v2, String movie ) { movies = new ArrayList<String>(); this.v1 = v1; this.v2 = v2; movies.add(movie); }
81a657f1-23db-4e9e-9ce4-bf7c5dccce78
public BaconNode getV1 ( ) { return v1; }
e8bb6765-4bb9-400f-8f16-7b264dbcd85a
public BaconNode getV2 ( ) { return v2; }
417b46cf-e1c1-467f-9c49-33268e988ab9
public String getMovie ( int i ) { return movies.get(i); }
a972fa69-50c2-43a8-ae57-f373300b17e2
public ArrayList<String> getMovies ( ) { return movies; }
9c744be2-63d1-4988-9565-f28ba38db035
public int getWeight ( ) { return movies.size(); }
8b91e074-db14-4e5e-8d85-a81ebd0984d2
public DatabaseManager ( ) { try { // load the sqlite-JDBC driver using the current class loader Class.forName ( DB_DRIVER_NAME ); // create a database connection connection = DriverManager.getConnection ( DB_CONNECTION_PREFIX + DB_FILENAME ); //prepare the shared statement for use later statement = connection.createStatement ( ); statement.setQueryTimeout ( QUERY_TIMEOUT ); // set timeout to 10 sec. } catch ( SQLException e ) { System.err.println ( e.getMessage ( ) ); System.exit(1); } catch ( ClassNotFoundException e ) { System.err.println ( e.getMessage ( ) ); System.exit ( 1 ); } }
69b696d7-0fa1-4cc1-8cb8-7327c6699015
public void configureDatabase ( ) { try { // If the table "movies" already exists in the data base statement.executeUpdate ( "DROP TABLE IF EXISTS movies" ); // Define the fields for the table "movies" statement.executeUpdate ( "create table movies (id INTEGER PRIMARY KEY, title TEXT, year DATE)" ); // If the table "actors" already exists in the data base statement.executeUpdate ( "DROP TABLE IF EXISTS actors" ); // Define the fields for the table "actors" statement.executeUpdate( "create table actors (id INTEGER PRIMARY KEY, first_name TEXT, last_name TEXT)" ); // If the table "roles" already exists in the data base statement.executeUpdate( "DROP TABLE IF EXISTS roles" ); // Define the fields for the table "roles" statement.executeUpdate( "create table roles (id INTEGER PRIMARY KEY, movie INTEGER FOREIGN KEY, " + "actor INTEGER FOREIGN KEY, role TEXT)" ); } catch ( SQLException e ) { System.err.println ( e.getMessage ( ) ); System.exit ( 1 ); } }
ae8fc144-fbf1-4a29-99cd-504c803d7a65
public void populateDatabase ( ) { //TODO: plaintext parsing }
88f5b0ca-3608-4300-88a8-3d798512eab7
public void addActor ( String lastname, String firstname ) { try { // Add the actor to the SQLite database statement.executeUpdate ( "INSERT INTO actors VALUES( NULL," + firstname + "," + lastname + ")" ); } catch ( SQLException e ) { System.err.println ( e.getMessage ( ) ); System.exit ( 1 ); } }
d9d70317-1df4-4661-beaa-a6331d61cf1b
public void addMovie ( String title, int year ) { try { // Add the movie to the SQLite database statement.executeUpdate ( "INSERT INTO movies VALUES( NULL," + title + "," + year + ")" ); } catch ( SQLException e ) { System.err.println ( e.getMessage ( ) ); System.exit ( 1 ); } }
7a6d1991-4247-4046-b205-43f7d7d944b9
public void addRole ( int movie, int actor, String role ) { try { // Add the movie to the SQLite database statement.executeUpdate ( "INSERT INTO movies VALUES( NULL," + movie + "," + actor + "," + role + ")" ); } catch ( SQLException e ) { System.err.println ( e.getMessage ( ) ); System.exit ( 1 ); } }
4d2960f2-a189-43fc-9596-9e0822715357
public int getMovieID ( String title, int year ) { try { ResultSet rs = statement.executeQuery("SELECT id FROM movies WHERE title = " + title + " AND year =" + year); return rs.getInt(1); } catch ( SQLException e ) { System.err.println ( e.getMessage ( ) ); System.exit ( 1 ); //never gets here; silly java return -1; } }
74938e08-7537-426c-88c5-a6ec1c979b87
public int getActorID ( String[] name ) { try { ResultSet rs = statement.executeQuery("SELECT id FROM actors WHERE last_name = " + name[0] + " AND first_name =" + name[1]); return rs.getInt(1); } catch ( SQLException e ) { System.err.println ( e.getMessage ( ) ); System.exit ( 1 ); //never gets here; silly java return -1; } }
601a44ae-2d6c-4d22-a3bc-c0aee949243b
public int getRoleID ( String role ) { try { ResultSet rs = statement.executeQuery("SELECT id FROM roles WHERE role = " + role); return rs.getInt(1); } catch ( SQLException e ) { System.err.println ( e.getMessage ( ) ); System.exit ( 1 ); //never gets here; silly java return -1; } }
1c94f313-fe4c-487c-ad91-487ae7c1a1ef
public String getMovieName ( int id ) { try { ResultSet rs = statement.executeQuery("SELECT title FROM movies WHERE id = " + id); return rs.getString(1); } catch ( SQLException e ) { System.err.println ( e.getMessage ( ) ); System.exit ( 1 ); //never gets here; silly java return "NULL"; } }
3f3abcd2-c69b-410c-9e6c-0560462d254c
public String[] getActorName ( int id ) { try { ResultSet rs = statement.executeQuery("SELECT last_name, first_name FROM actors " + "WHERE id = " + id); return new String[]{rs.getString(1), rs.getString(2)}; } catch ( SQLException e ) { System.err.println ( e.getMessage ( ) ); System.exit ( 1 ); //never gets here; silly java return new String[]{"NULL","NULL"}; } }
55c0f4f4-e6f9-4ad3-a1fd-2b3248cbe5f2
public String getRoleName ( int id ) { try { ResultSet rs = statement.executeQuery("SELECT role FROM roles WHERE id = " + id); return rs.getString(1); } catch ( SQLException e ) { System.err.println ( e.getMessage ( ) ); System.exit ( 1 ); //never gets here; silly java return "NULL"; } }
afb7d7a8-cbd3-4742-936b-311574d64d70
public int getMovieID ( int id ) { try { ResultSet rs = statement.executeQuery("SELECT movie FROM roles WHERE id = " + id); return rs.getInt(1); } catch ( SQLException e ) { System.err.println ( e.getMessage ( ) ); System.exit ( 1 ); //never gets here; silly java return -1; } }
db5dce90-aa92-4a3b-aff6-559ca4f6485c
public int getActorIDByRole ( int id ) { try { ResultSet rs = statement.executeQuery("SELECT actor FROM roles WHERE id = " + id); return rs.getInt(1); } catch ( SQLException e ) { System.err.println ( e.getMessage ( ) ); System.exit ( 1 ); //never gets here; silly java return -1; } }
9070ab22-a215-435a-8715-fbb4249bb8bc
public int getMovieIDByRole ( String role ) { try { ResultSet rs = statement.executeQuery("SELECT movie FROM roles WHERE role = " + role); return rs.getInt(1); } catch ( SQLException e ) { System.err.println ( e.getMessage ( ) ); System.exit ( 1 ); //never gets here; silly java return -1; } }
888f7766-c913-4d29-b93d-e8b2f297880b
public int getActorIDByRole ( String role ) { try { ResultSet rs = statement.executeQuery("SELECT actor FROM roles WHERE role = " + role); return rs.getInt(1); } catch ( SQLException e ) { System.err.println ( e.getMessage ( ) ); System.exit ( 1 ); //never gets here; silly java return -1; } }
4f27d8da-2db7-454b-97e8-27b906db174e
public void closeDatabase ( ) { try { if( connection != null ) connection.close ( ); if( statement != null ) statement.close ( ); } catch ( SQLException e ) { // connection close failed. System.err.println ( e ); System.exit ( 1 ); } }
174e68aa-c5c8-4ac9-9464-734af4ba9694
public ArrayList<String[]> getActorNames ( ) { //result set ArrayList<String[]> actors = new ArrayList<String[]>(); try { //get the actors ResultSet rs = statement.executeQuery("SELECT last_name, first_name FROM actors"); while(rs.next()) actors.add(new String[]{rs.getString(1), rs.getString(2)}); } catch ( SQLException e ) { // connection close failed. System.err.println ( e ); System.exit ( 1 ); } return actors; }
e79f70a0-36b9-4f90-865b-0aae06ecc44e
public ArrayList<String> getMoviesByActor ( String[] actor ) { //result set ArrayList<String> movies = new ArrayList<String>(); try { ResultSet rs = statement.executeQuery("SELECT title FROM movies " + "WHERE last_name = " + actor[0] + " AND first_name = " + actor[1]); while(rs.next()) movies.add(rs.getString(1)); } catch ( SQLException e ) { // connection close failed. System.err.println ( e ); System.exit ( 1 ); } return movies; }
95b75ffd-aded-45b1-872a-4dd42ddb01fb
public ArrayList<String[]> getActorsByMovie ( String movie, int year ) { //result set ArrayList<String[]> actors = new ArrayList<String[]>(); try { int movieID = getMovieID(movie, year); ResultSet rs = statement.executeQuery("SELECT actor FROM roles WHERE movie = " + movieID); while(rs.next()) actors.add(getActorName(rs.getInt(1))); } catch ( SQLException e ) { // connection close failed. System.err.println ( e ); System.exit ( 1 ); } return actors; }
d0515e65-093d-4e15-9f1f-8bb93f0a36b9
public static void main(String[] args) { //DB Junk dbm = new DatabaseManager(); dbm.configureDatabase(); dbm.populateDatabase(); //Graph Junk graph = new BaconGraph(); }
d6e30ad7-eea5-4b43-ab5c-df878a4cab18
public void baconize() { //add the vertices for(String[] actor : dbm.getActorNames()){ graph.addVertex(new BaconNode(actor)); //add the edges for(String movie : dbm.getMoviesByActor(actor)){ for(String[] otherActor : dbm.getActorsByMovie(movie, 0000)){ graph.addEdge(new BaconNode(actor), new BaconNode(otherActor), movie); } } } }
cffc532e-b5e4-4d50-bbc0-64764150f30d
public BaconGraph ( ) { graph = new Hashtable<BaconNode, ArrayList<BaconEdge>>(); }
11f940c5-a3ff-41c4-9b70-d9445ba3bfdd
public void addVertex ( BaconNode v ) { graph.put(v, new ArrayList<BaconEdge>()); }
1e15eb47-3799-49a4-b4e1-8c794b89d93c
public void addEdge ( BaconNode v1, BaconNode v2, String movie) { if(!graph.containsKey(v1)) addVertex(v1); if(!graph.containsKey(v2)) addVertex(v2); graph.get(v1).add(new BaconEdge(v1, v2, movie)); graph.get(v2).add(new BaconEdge(v1, v2, movie)); }
c15a95c2-4f55-4477-b85a-0738201198ce
public ArrayList<BaconEdge> getEdges ( BaconNode v ) { return graph.get(v); }
73d1c357-a380-432d-b988-0e29f37bb91d
public int getSize ( ) { return graph.size(); }
a755a7aa-b2dd-4583-ad40-3bf75ca8b3f4
public int getOutCount ( BaconNode v ) { return graph.get(v).size(); }
7af646c1-b87d-48bc-85fc-cc404a663ceb
public BaconNode getNode ( String[] actor ) { for(BaconNode v:graph.keySet()) if(v.getName()[0] == actor[0] && v.getName()[1] == actor[1]) return v; return null; }
29811670-713f-409e-89e3-928f9671db0f
public static void main (String [] args) throws FileNotFoundException{ Scanner scan = new Scanner(new FileReader("contactos.txt")); TreeSet<Contacto> contactos = new TreeSet<Contacto>(); while (scan.hasNextLine()){ String linea = scan.nextLine(); String[] sep = linea.split("-"); String nombre = sep[0]; String apellido = sep[1]; String direccion = sep[2]; ArrayList<String> tel = new ArrayList<String>(); tel.add(sep[3]); ArrayList<String> email = new ArrayList<String>(); email.add(sep[4]); Contacto contacto = new Contacto (nombre, apellido, tel, email); contacto.setDireccion(direccion); contactos.add(contacto); } scan.close(); AgendaTreeSet agenda = new AgendaTreeSet(contactos); System.out.println("******Imprimiendo todos los contactos******\n\n"); System.out.print(agenda.contactos()); //Agregando un contacto existente System.out.println("\n\n*****Agregando un contacto ya existente******\n"); System.out.println("Agregando a Peter Parker..."); if (agenda.addContacto(new Contacto("Peter", "Parker" , null ,null))){ System.out.println("El contacto fue agregado"); }else{ System.out.println("El contacto ya existe"); } //Eliminando contactos System.out.println("\n\n*****Borrando un contacto ya existente*****\n"); System.out.println("Borrando a Diego Garcia..."); if(agenda.eliminaContacto(new Contacto("Diego", "Garcia", null, null))){ System.out.println("El contacto fue borrado ;) (Thank God)"); }else{ System.out.println("El contacto no existe"); } System.out.println("\n\n*****Borrando un contacto no existente*****\n"); System.out.println("Borrando a Diego Garcia..."); if(agenda.eliminaContacto(new Contacto("Diego", "Garcia", null, null))){ System.out.println("El contacto fue borrado"); }else{ System.out.println("El contacto no existe"); } //Actualizar direccion de un contacto ya existente System.out.println("\n\n*****Actualizando la direccion de un contacto ya existente*****\n"); System.out.println("Actualizando la direccion de Saul Damaris..."); if(agenda.actualizarDir(new Contacto ("Saul" , "Damaris", null, null), "Lomas Verdes")){ System.out.println("La direccion ha sido actualizada"); }else{ System.out.println("El contacto no existe"); } System.out.println("\n\n*****Actualizando la direccion de un contacto no existente*****\n"); System.out.println("Actualizando la direccion de Diego Garcia..."); if(agenda.actualizarDir(new Contacto ("Diego" , "Garcia", null, null), "Satelite")){ System.out.println("La dirección ha sido actualizada"); }else{ System.out.println("El contacto no existe"); } //Agregando un telefono a un contacto existente System.out.println("\n\n*****Agregando telefono a un contacto ya existente*****\n"); System.out.println("Agregando un telefono a Diego Marquez..."); if(agenda.agregarTelefono(new Contacto("Diego","Marquez", null, null), "987654321")){ System.out.println("EL numero ha sido agregado"); }else{ System.out.println("El contacto no existe"); } //Agregando un telefono a un contacto no existente System.out.println("\n\n*****Agregando telefono a un contacto no existente*****\n"); System.out.println("Agregando un telefono a David Monroy..."); if(agenda.agregarTelefono(new Contacto("David","Monroy", null, null), "987654321")){ System.out.println("EL numero ha sido agregado"); }else{ System.out.println("El contacto no existe"); } //Agregando un email a un contacto existente System.out.println("\n\n*****Agregando un email a un contacto ya existente*****\n"); System.out.println("Agregando un email a Tony Stark..."); if(agenda.agregarEmail(new Contacto("Tony","Stark", null, null), "[email protected]")){ System.out.println("EL mail ha sido agregado"); }else{ System.out.println("El contacto no existe"); } //Agregando un email a un contacto no existente System.out.println("\n\n*****Agregando un email a un contacto no existente*****\n"); System.out.println("Agregando un email a Debora Quins..."); if(agenda.agregarEmail(new Contacto("Debora","Quins", null, null), "[email protected]")){ System.out.println("EL mail ha sido agregado"); }else{ System.out.println("El contacto no existe"); } //Borrando telefono de un contacto existente System.out.println("\n\n*****Borrando el telefono de un contacto existente*****\n"); System.out.println("Borrando el telefono de Jacob Resendiz..."); if(agenda.borrarTelefono(new Contacto("Jacob","Resendiz", null, null), "55000007")){ System.out.println("EL telefono ha sido eliminado"); }else{ System.out.println("El contacto no existe"); } //Borrando telefono de un contacto no existente System.out.println("\n\n*****Borrando el telefono de un contacto no existente*****\n"); System.out.println("Borrando el telefono de Juan Resendisz..."); if(agenda.borrarTelefono(new Contacto("Juan","Resendisz", null, null), "55000007")){ System.out.println("EL telefono ha sido eliminado"); }else{ System.out.println("El contacto no existe"); } //Borrando mail de un contacto existente System.out.println("\n\n*****Borrando el mail de un contacto existente*****\n"); System.out.println("Borrando el telefono de Patricio Estrella..."); if(agenda.borrarTelefono(new Contacto("Patricio","Estrella", null, null), "[email protected]")){ System.out.println("El mail ha sido eliminado"); }else{ System.out.println("El contacto no existe"); } //Borrando mail de un contacto no existente System.out.println("\n\n*****Borrando el mail de un contacto no existente*****\n"); System.out.println("Borrando el telefono de Eduardo ROdriguez..."); if(agenda.borrarTelefono(new Contacto("Eduardo","ROdriguez", null, null), "[email protected]")){ System.out.println("El mail ha sido eliminado"); }else{ System.out.println("El contacto no existe"); } System.out.println("\n\nIMPRIMIENDO CONTACTOS CON MODIFICACIONES\n\n"); System.out.println(agenda.contactos()); System.out.println("\n\nConsultando un contacto existente\n" + "Consultando el contacto Bruce Wayn...\n"); System.out.println(agenda.consultarContacto("Bruce", "Wayn")); System.out.println("\n\nConsultando un contacto no existente"); System.out.println("Consultando a Diego Garcia : "); System.out.println(agenda.consultarContacto("Diego", "Garcia")); }
82448467-47f1-441d-acf9-5b45387a4878
public Contacto(String nombre, String apellido, ArrayList<String> telefonos, ArrayList<String> email) { this.nombre = nombre; this.apellido = apellido; this.telefonos = telefonos; this.email = email; }
eae48dce-0d70-472f-8886-180ae63d7e26
public List<String> getTelefono() { return this.telefonos; }
f928794b-4724-485f-bcba-afd6dd305d24
public void addTelefono(String telefono) { this.telefonos.add(telefono); }