Search in sources :

Example 1 with Shelter

use of com.example.peter.homelessapp.model.Shelter in project FindMyHome by DjangoBlockchained.

the class UserUnitTest method testEquals.

@Test
public void testEquals() {
    User a = new HomelessUser();
    User b = new HomelessUser();
    // if both usernames are null, return false
    assertFalse(a.equals(b));
    // different names, null usernames - still false (obv)
    a.setName("Sanjana");
    b.setName("Peter");
    assertFalse((a.equals(b)));
    // same names, null usernames - still false
    b.setName("Sanjana");
    // a.getName() = sanjana
    assertFalse(a.equals(b));
    // same names, one username null - false
    b.setUsername("pzupke3");
    // a.getUsername() = NULL
    assertFalse((a.equals(b)));
    // same names, different non-null usernames - false
    a.setUsername("skadivet6");
    // b.getUsername() = pzupke3
    assertFalse((a.equals(b)));
    // same names, same non-null usernames - true!
    a.setUsername("pzupke3");
    // b.getUsername() = pzupke3
    assertTrue(a.equals(b));
    // different names, same non-null usernames - true!
    b.setName("Peter");
    assertTrue((a.equals(b)));
    // same objects, true!
    b = a;
    assertTrue(a.equals(b));
    // one of the objects is null - false
    b = null;
    assertFalse((a.equals(b)));
    // one of the objects not an instance of user - false
    Shelter x = new Shelter();
    assertFalse((a.equals(x)));
}
Also used : HomelessUser(com.example.peter.homelessapp.model.HomelessUser) HomelessUser(com.example.peter.homelessapp.model.HomelessUser) User(com.example.peter.homelessapp.model.User) Shelter(com.example.peter.homelessapp.model.Shelter) Test(org.junit.Test)

Example 2 with Shelter

use of com.example.peter.homelessapp.model.Shelter in project FindMyHome by DjangoBlockchained.

the class AdminScreenActivity method readShelters.

private void readShelters() {
    try {
        InputStream is = getResources().openRawResource(R.raw.shelters);
        BufferedReader br1 = new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8));
        br1.readLine();
        String s = br1.readLine();
        while (s != null) {
            String[] tokens = s.split(",(?=([^\"]*\"[^\"]*\")*[^\"]*$)");
            Integer capacity = Shelter.parseCapacity(tokens[2]);
            new Shelter(tokens[0], tokens[1], capacity, tokens[3], Double.parseDouble(tokens[4]), Double.parseDouble(tokens[5]), tokens[6], tokens[7], tokens[8]);
            s = br1.readLine();
        }
        br1.close();
    } catch (IOException e) {
        android.util.Log.d("", "error!");
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) BufferedReader(java.io.BufferedReader) Shelter(com.example.peter.homelessapp.model.Shelter) IOException(java.io.IOException)

Example 3 with Shelter

use of com.example.peter.homelessapp.model.Shelter in project FindMyHome by DjangoBlockchained.

the class ApplicationScreenActivity method readShelters.

private void readShelters() {
    try {
        InputStream is = getResources().openRawResource(R.raw.shelters);
        BufferedReader br1 = new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8));
        br1.readLine();
        String s = br1.readLine();
        while (s != null) {
            String[] tokens = s.split(",(?=([^\"]*\"[^\"]*\")*[^\"]*$)");
            Integer capacity = Shelter.parseCapacity(tokens[2]);
            new Shelter(tokens[0], tokens[1], capacity, tokens[3], Double.parseDouble(tokens[4]), Double.parseDouble(tokens[5]), tokens[6], tokens[7], tokens[8]);
            s = br1.readLine();
        }
        br1.close();
    } catch (IOException e) {
        android.util.Log.d("", "error!");
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) BufferedReader(java.io.BufferedReader) Shelter(com.example.peter.homelessapp.model.Shelter) IOException(java.io.IOException)

Example 4 with Shelter

use of com.example.peter.homelessapp.model.Shelter in project FindMyHome by DjangoBlockchained.

the class ClaimScreenActivity method showAlreadyCheckedInAlert.

private void showAlreadyCheckedInAlert(int beds, String currentShelter) {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle("Already Checked In");
    builder.setMessage("You are already checked in to the shelter '" + currentShelter + "'. Would you like to check out and check in to the new shelter?");
    builder.setPositiveButton("Check Out", (dialog, id) -> {
        shelterRef = FirebaseDatabase.getInstance().getReference().child("shelters").child(// .getParent();
        currentShelter);
        shelterRef.addListenerForSingleValueEvent(new ValueEventListener() {

            @Override
            public void onDataChange(DataSnapshot dataSnapshot) {
                Shelter currShelter = dataSnapshot.getValue(Shelter.class);
                if (currShelter == null) {
                    return;
                }
                Shelter.checkOut(shelter, currShelter, currentUser);
                checkIn(beds);
                dialog.dismiss();
            }

            @Override
            public void onCancelled(DatabaseError databaseError) {
            }
        });
    });
    builder.setNegativeButton("Cancel", (dialog, id) -> dialog.dismiss());
    builder.create().show();
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) DatabaseError(com.google.firebase.database.DatabaseError) Shelter(com.example.peter.homelessapp.model.Shelter) ValueEventListener(com.google.firebase.database.ValueEventListener) DataSnapshot(com.google.firebase.database.DataSnapshot)

Example 5 with Shelter

use of com.example.peter.homelessapp.model.Shelter in project FindMyHome by DjangoBlockchained.

the class checkOutTest method test.

@Test
public void test() throws Exception {
    HomelessUser test = new HomelessUser();
    Shelter s = new Shelter();
    s.setCapacity(1);
    s.checkIn(test, 1);
    assert (s.checkOut(test));
    assert (!s.checkOut(test));
}
Also used : HomelessUser(com.example.peter.homelessapp.model.HomelessUser) Shelter(com.example.peter.homelessapp.model.Shelter) Test(org.junit.Test)

Aggregations

Shelter (com.example.peter.homelessapp.model.Shelter)5 HomelessUser (com.example.peter.homelessapp.model.HomelessUser)2 BufferedReader (java.io.BufferedReader)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 InputStreamReader (java.io.InputStreamReader)2 Test (org.junit.Test)2 AlertDialog (android.support.v7.app.AlertDialog)1 User (com.example.peter.homelessapp.model.User)1 DataSnapshot (com.google.firebase.database.DataSnapshot)1 DatabaseError (com.google.firebase.database.DatabaseError)1 ValueEventListener (com.google.firebase.database.ValueEventListener)1