Ejemplo n.º 1
0
 public String toString() {
   if (end == null) {
     return new String("Open link starting in " + start.getName());
   } else {
     return new String("Link between " + start.getName() + " and " + end.getName());
   }
 }
Ejemplo n.º 2
0
  // public MazeImpl(Point point, long seed) {
  public MazeImpl(Point point, long seed, BlockingQueue eventQueue, Client client) {
    this.eventQueue = eventQueue;
    this.client = client;
    System.out.println("MazeImpl constructor Client name:" + client.getName());

    maxX = point.getX();
    assert (maxX > 0);
    maxY = point.getY();
    assert (maxY > 0);

    // Initialize the maze matrix of cells
    mazeVector = new Vector(maxX);
    for (int i = 0; i < maxX; i++) {
      Vector colVector = new Vector(maxY);

      for (int j = 0; j < maxY; j++) {
        colVector.insertElementAt(new CellImpl(), j);
      }

      mazeVector.insertElementAt(colVector, i);
    }

    thread = new Thread(this);

    // Initialized the random number generator
    randomGen = new Random(seed);

    // Build the maze starting at the corner
    if (seed == 0) buildEmptyMaze();
    else buildMaze(new Point(0, 0));

    thread.start();
  }
Ejemplo n.º 3
0
 public synchronized boolean updateProjectile(Client client) {
   if (!projectileMap.isEmpty()) {
     Collection deadPrj = new HashSet();
     Iterator it = projectileMap.keySet().iterator();
     synchronized (projectileMap) {
       while (it.hasNext()) {
         Object o = it.next();
         assert (o instanceof Projectile);
         // deadPrj.addAll(moveProjectile((Projectile)o));
         if (client.getName().equals((((Projectile) o).getOwner()).getName())) {
           deadPrj.addAll(moveProjectile((Projectile) o));
           break;
         }
       }
       it = deadPrj.iterator();
       while (it.hasNext()) {
         Object o = it.next();
         assert (o instanceof Projectile);
         Projectile prj = (Projectile) o;
         projectileMap.remove(prj);
         clientFired.remove(prj.getOwner());
       }
       deadPrj.clear();
     }
   }
   return true;
 }
Ejemplo n.º 4
0
 private void removeWish() {
   try {
     marketobj.removeWish(command.getItemName(), command.getPrice(), command.getClient());
     contr.updateLog(client.getName() + " removed wish for " + command.getItemName());
     getWishes();
   } catch (RemoteException e) {
     contr.remoteExceptionHandler(e);
   }
 }
Ejemplo n.º 5
0
 private void sell() {
   try {
     marketobj.Sell(command.getItemName(), command.getItemDescr(), command.getPrice(), client);
     contr.updateLog(client.getName() + " listed " + command.getItemName() + " for sale");
     getForSale();
   } catch (RemoteException e) {
     contr.remoteExceptionHandler(e);
   }
 }
 @Override
 public boolean equals(Object otherClient) {
   if (!(otherClient instanceof Client)) {
     return false;
   } else {
     Client newClient = (Client) otherClient;
     return this.getName().equals(newClient.getName()) && this.getId() == newClient.getId();
   }
 }
Ejemplo n.º 7
0
  @Test
  public void updateClient() {
    final String NAME = "ABC";

    client.setName(NAME);
    Client cl = jToggl.updateClient(client);

    Assert.assertNotNull(cl);
    Assert.assertEquals(NAME, cl.getName());
  }
Ejemplo n.º 8
0
 private void removeSell() {
   try {
     marketobj.removeSell(
         command.getItemName(), command.getItemDescr(), command.getPrice(), command.getClient());
     contr.updateLog(
         client.getName() + " removed " + command.getItemName() + " that was listed as for sale");
     getForSale();
   } catch (RemoteException e) {
     contr.remoteExceptionHandler(e);
   }
 }
  @Override
  public boolean delete(Client obj) {
    try {
      deleteClient.setString(1, obj.getName());
      deleteClient.executeUpdate();
      return true;

    } catch (SQLException e) {
      e.printStackTrace();
      return false;
    }
  }
Ejemplo n.º 10
0
 private AutomationClient(Client client) {
   super(
       client.getId(),
       client.getName(),
       client.getDescription(),
       client.getCreatedAt(),
       client.getCreatedBy(),
       client.getUpdatedAt(),
       client.getUpdatedBy(),
       client.isEnabled(),
       true);
 }
Ejemplo n.º 11
0
  /**
   * Internal helper for handling the death of a {@link Client}.
   *
   * @param source The {@link Client} that fired the projectile.
   * @param target The {@link Client} that was killed.
   */
  private synchronized void killClient(Client source, Client target) {
    assert (source != null);
    assert (target != null);
    Mazewar.consolePrintLn(source.getName() + " just vaporized " + target.getName());
    System.out.println(source.getName() + " just vaporized " + target.getName());

    Object o = clientMap.remove(target);
    assert (o instanceof Point);
    Point point = (Point) o;
    CellImpl cell = getCellImpl(point);
    cell.setContents(null);
    System.out.println("set contents to null!!!");
    // Pick a random starting point, and check to see if it is already occupied
    point = new Point(randomGen.nextInt(maxX), randomGen.nextInt(maxY));

    System.out.println(
        "Choose random point: " + randomGen.nextInt(maxX) + ":" + randomGen.nextInt(maxY));
    cell = getCellImpl(point);
    // Repeat until we find an empty cell
    while (cell.getContents() != null) {
      point = new Point(randomGen.nextInt(maxX), randomGen.nextInt(maxY));
      cell = getCellImpl(point);
      System.out.println("try to find an empty cell");
    }
    System.out.println(
        "Finish chossing point: " + randomGen.nextInt(maxX) + ":" + randomGen.nextInt(maxY));
    // Direction d = Direction.random();
    Direction d = Direction.North;
    /*
    while(cell.isWall(d)) {
            //d = Direction.random();
        d.turnLeft();
    }*/
    cell.setContents(target);

    System.out.println("set contents to target!!!");
    clientMap.put(target, new DirectedPoint(point, d));
    update();
    notifyClientKilled(source, target);
  }
  @Override
  public boolean save(Client obj) {
    try {
      saveClient =
          connection.prepareStatement(
              "" + "INSERT INTO Klient(name,surname,adress,phone)" + "VALUES(?,?,?,?)");
      saveClient.setString(1, obj.getName());
      saveClient.setString(2, obj.getSurname());

      return saveClient.execute();

    } catch (SQLException e) {
      e.printStackTrace();
      return false;
    }
  }
Ejemplo n.º 13
0
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.fragment_client, parent, false);

    mNameDisplay = (EditText) v.findViewById(R.id.client_name);

    mNameDisplay.setText(mClient.getName());

    mNameDisplay.addTextChangedListener(
        new TextWatcher() {
          @Override
          public void beforeTextChanged(CharSequence s, int start, int count, int after) {}

          @Override
          public void onTextChanged(CharSequence s, int start, int before, int count) {
            mClient.setName(s.toString());
          }

          @Override
          public void afterTextChanged(Editable s) {}
        });

    mEmailDisplay = (EditText) v.findViewById(R.id.client_email);

    mEmailDisplay.setText(mClient.getEmail());

    mEmailDisplay.addTextChangedListener(
        new TextWatcher() {
          @Override
          public void beforeTextChanged(CharSequence s, int start, int count, int after) {}

          @Override
          public void onTextChanged(CharSequence s, int start, int before, int count) {
            mClient.setEmail(s.toString());
          }

          @Override
          public void afterTextChanged(Editable s) {}
        });
    return v;
  }
  public void run() {
    MPacket received = null;
    MPacket current = null;
    int prevSeqNum = 0;
    Client client = null;
    if (Debug.debug) System.out.println("Starting ClientListenerThread");
    while (true) {
      try {
        received = (MPacket) mSocket.readObject();

        if (received.event == MPacket.HELLO) {
          MPacket helloResp = new MPacket(localClient.getName(), MPacket.HELLO, MPacket.HELLO_RESP);
          mSocket.writeObject(helloResp);
        }

        if (amServer.get()) {
          if (received.type == MPacket.ACTION_REQUEST) {
            if (Debug.debug) System.out.println("Received Request Packet: " + received);
            eventQueue.add(received);
          } else if (received.type == MPacket.REBROADCAST) {
            if (Debug.debug) System.out.println("Received Rebroadcast Packet: " + received);
            eventQueue.add(received);
          }
        } else {
          if (received.type == MPacket.ACTION || received.type == MPacket.SYNC) {
            if (Debug.debug) System.out.println("Received Sequence Packet: " + received);
            listenerQueue.add(received);
            System.out.println("LISTENER QUEUE: " + listenerQueue);
          } else if (received.type == MPacket.REBROADCAST) {
            if (Debug.debug) System.out.println("Received Rebroadcast Packet: " + received);
            eventQueue.add(received);
          }
        }
      } catch (IOException e) {
        e.printStackTrace();
      } catch (ClassNotFoundException e) {
        e.printStackTrace();
      }
    }
  }
 public static void serverLoop() {
   try {
     ss = new ServerSocket(RemoteControl.props.getInt("port", 11946));
   } catch (IOException e) {
     log.severe("RemoteControl could not bind to port");
   }
   try {
     while (loop) {
       Client c =
           RemoteControl.isParanoid()
               ? new SecureClient(ss.accept())
               : new NormalClient(ss.accept());
       clients.add(c);
       c.setName(c.getName().replace("Thread", "Client"));
       c.start();
     }
   } catch (IOException e) {
     log.info("RemoteControl could not set up connection to client" + " or was disabled");
   } catch (NullPointerException e) {
     // duhr, ss failed.
   }
 }
Ejemplo n.º 16
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.add_update_client);

    // set screen
    Set_Add_Update_Screen();

    // set visibility of view as per calling activity
    String called_from = getIntent().getStringExtra("called");

    if (called_from.equalsIgnoreCase("add")) {
      add_view.setVisibility(View.VISIBLE);
      update_view.setVisibility(View.GONE);
    } else {

      update_view.setVisibility(View.VISIBLE);
      add_view.setVisibility(View.GONE);
      CLIENT_ID = Integer.parseInt(getIntent().getStringExtra("CLIENT_ID"));

      Client c = dbHandler.Get_client(CLIENT_ID);

      add_name.setText(c.getName());
      add_address.setText(c.getAddress());
      add_notes.setText(c.getNotes());

      // dbHandler.close();
    }

    add_save_btn.setOnClickListener(
        new View.OnClickListener() {

          @Override
          public void onClick(View v) {
            // TODO Auto-generated method stub
            // check the value state is null or not

            dbHandler.Add_client(
                new Client(
                    CLIENT_ID,
                    add_name.getText().toString(),
                    add_address.getText().toString(),
                    add_notes.getText().toString()));
            Toast_msg = "Data inserted successfully";
            Show_Toast(Toast_msg);
            Reset_Text();
          }
        });

    update_btn.setOnClickListener(
        new View.OnClickListener() {

          @Override
          public void onClick(View v) {
            // TODO Auto-generated method stub

            valid_name = add_name.getText().toString();
            valid_address = add_address.getText().toString();
            valid_notes = add_notes.getText().toString();

            // check the value state is null or not
            if (valid_name != null && valid_address != null && valid_address.length() != 0) {

              dbHandler.Update_client(
                  new Client(CLIENT_ID, valid_name, valid_address, valid_notes));
              dbHandler.close();
              Toast_msg = "Data Update successfully";
              Show_Toast(Toast_msg);
              Reset_Text();
            } else {
              Toast_msg = "Sorry Some Fields are missing.\nPlease Fill up all.";
              Show_Toast(Toast_msg);
            }
          }
        });
    update_view_all.setOnClickListener(
        new View.OnClickListener() {

          @Override
          public void onClick(View v) {
            // TODO Auto-generated method stub
            Intent view_user = new Intent(Add_Update_Client.this, ClientActivity.class);
            view_user.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(view_user);
            finish();
          }
        });

    add_view_all.setOnClickListener(
        new View.OnClickListener() {

          @Override
          public void onClick(View v) {
            // TODO Auto-generated method stub
            Intent view_user = new Intent(Add_Update_Client.this, ClientActivity.class);
            view_user.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(view_user);
            finish();
          }
        });
  }
Ejemplo n.º 17
0
  public void paintComponent(Graphics g) {
    super.paintComponent(g); // paint background
    Graphics2D g2 = (Graphics2D) g;

    // Turn on antialiasing
    Map m = new HashMap();
    m.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2.addRenderingHints(m);

    // Figure out how large the maze is
    Point p = maze.getSize();

    double llx = 0.0, lly = 0.0, width = 0.0, height = 0.0, cellwidth = 0.0, cellheight = 0.0;
    // Do we need to update our cache?
    if ((panelSize == null) || (panelSize != getSize())) {
      panelSize = getSize();
      llx = (double) panelSize.width * 0.025;
      lly = (double) panelSize.height * 0.025;
      width = (double) panelSize.width - (double) panelSize.width * 0.05;
      height = (double) panelSize.height - (double) panelSize.height * 0.05;
      cellwidth = width / (double) p.getX();
      cellheight = height / (double) p.getY();
      buildWalls(llx, lly, cellwidth, cellheight);
      double diameter = java.lang.Math.min(cellwidth, cellheight) * 0.75;
      player =
          new Arc2D.Double(
              new Rectangle2D.Double(-diameter / 2.0, -diameter / 2.0, diameter, diameter),
              30.0,
              300.0,
              Arc2D.PIE);
      diameter = java.lang.Math.min(cellwidth, cellheight) * 0.30;
      projectile =
          new Arc2D.Double(
              new Rectangle2D.Double(-diameter / 2.0, -diameter / 2.0, diameter, diameter),
              0.0,
              360.0,
              Arc2D.PIE);
    }

    // Flip coordinate system
    g2.translate(0.0, (double) panelSize.height);
    g2.scale(1.0, -1.0);

    // Draw the maze walls
    g2.setStroke(new BasicStroke(2.0f));
    g2.setColor(Color.black);
    g2.draw(new Rectangle2D.Double(llx, lly, width, height));

    Iterator it = wallList.iterator();
    while (it.hasNext()) {
      Object o = it.next();
      if (o instanceof Shape) {
        g2.draw((Shape) o);
      } else {
        throw new Error();
      }
    }

    Font font = new Font("Arial", Font.PLAIN, 9);
    FontRenderContext frc = g2.getFontRenderContext();

    // Obtain the location of the distinguished client
    Point cp = maze.getClientPoint(client);

    for (int i = 0; i < p.getY(); i++) {
      for (int j = 0; j < p.getX(); j++) {
        boolean cellVisible = true;
        Line2D visLine =
            new Line2D.Double(
                llx + (cp.getX() + 0.5) * cellwidth,
                lly + (cp.getY() + 0.5) * cellheight,
                llx + (j + 0.5) * cellwidth,
                lly + (i + 0.5) * cellheight);

        /* Visibility testing */
        /* Iterator visIt = wallList.iterator();
        while(visIt.hasNext()) {
                Object o = visIt.next();
                if(o instanceof Line2D) {
                        Line2D l = (Line2D)o;
                        if(l.intersectsLine(visLine)) {
                                cellVisible = false;
                        }
                } else {
                        throw new Error();
                }

        } */
        if (cellVisible) {
          Cell cell = maze.getCell(new Point(j, i));
          Object o = cell.getContents();
          if (o != null) {
            if (o instanceof Client) {
              Client c = (Client) o;
              if (c instanceof GUIClient) {
                g2.setColor(Color.green);
              } else if (c instanceof RobotClient) {
                g2.setColor(Color.red);
              } else if (c instanceof RemoteClient) {
                g2.setColor(Color.magenta);
              }

              double xoffset = llx + j * cellwidth + (cellwidth / 2.0);
              double yoffset = lly + i * cellheight + (cellheight / 2.0);
              Direction orient = c.getOrientation();
              g2.translate(xoffset, yoffset);
              double rotation = 0.0;
              if (orient.equals(Direction.South)) {
                rotation = -java.lang.Math.PI / 2.0;
              } else if (orient.equals(Direction.North)) {
                rotation = java.lang.Math.PI / 2.0;
              } else if (orient.equals(Direction.West)) {
                rotation = java.lang.Math.PI;
              }
              g2.rotate(rotation);
              g2.fill(player);
              g2.rotate(-rotation);

              GlyphVector name = font.createGlyphVector(frc, c.getName());
              g2.scale(1.0, -1.0);
              g2.setColor(Color.black);
              g2.drawGlyphVector(name, 0.0f, 0.0f);
              g2.scale(1.0, -1.0);
              g2.translate(-xoffset, -yoffset);

            } else {
              if (o instanceof Projectile) {
                g2.setColor(Color.yellow);
                double xoffset = llx + j * cellwidth + (cellwidth / 2.0);
                double yoffset = lly + i * cellheight + (cellheight / 2.0);
                g2.translate(xoffset, yoffset);
                g2.fill(projectile);
                g2.translate(-xoffset, -yoffset);
              }
            }
          }
        }
      }
    }
  }
Ejemplo n.º 18
0
 private void initGame() {
   player1.startGame(NetUtilities.WHITE_PLAYER, player2.getName());
   player2.startGame(NetUtilities.BLACK_PLAYER, player1.getName());
 }
Ejemplo n.º 19
0
 @Override
 public int compare(Client client1, Client client2) {
   return client1.getName().compareTo(client2.getName());
 }
Ejemplo n.º 20
0
  public static void main(String[] args) throws Cena_mniej_niz_zero {

    PropertyConfigurator.configure("log4j.properties");
    logger.debug("Sample debug message");
    logger.info("Sample info message");
    logger.warn("Sample warn message");
    logger.error("Sample error message");
    logger.fatal("Sample fatal message");
    SampleReport obj = new SampleReport();
    obj.generateReport();

    List<Product> products = new ArrayList<Product>();

    Client customer1 = new Client("Waldek", "Kiepski", products);
    try {
      customer1.addProduct(new Product("plyta CD", -1));
      customer1.addProduct(new Product("plyta DVD", 2));
      customer1.addProduct(new Product("kabel USB", 8));
      customer1.addProduct(new Product("slon", 10000));

    } catch (Cena_mniej_niz_zero e) {
      logger.error(e);
    }

    customer1.printCustomers();
    customer1.printMangas();
    System.out.println("Ilosc produktow " + products.size());
    System.out.println("\n");

    // HIBERNATE

    List<Client> owners = new ArrayList<Client>();

    SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
    Session session = sessionFactory.openSession();
    session.beginTransaction();

    /*session.save(p);
    for(Car car :cars)
    {
    	session.save(car);
    }*/
    session.persist(customer1);

    List<Client> clients = session.getNamedQuery("Client.all").list();

    // session.save(garage2);
    // session.save(garage);
    session.get(Client.class, 1000);
    session.getTransaction().commit();
    int i = 1;
    do {
      owners.add((Client) session.get(Client.class, i));
      i++;
    } while (session.get(Client.class, i) != null);

    session.close();
    System.out.println(owners.size());

    for (Client client : clients) {
      System.out.print(client.getName());
    }
  }