Example usage for android.content Entity equals

List of usage examples for android.content Entity equals

Introduction

In this page you can find the example usage for android.content Entity equals.

Prototype

public boolean equals(Object obj) 

Source Link

Document

Indicates whether some other object is "equal to" this one.

Usage

From source file:it.polimi.geinterface.GroupEntityManager.java

/**
 * Method that computes the distance between selfEntity and another device, receiving the intersection 
 * between beacons contained in device's {@link MessageType#PROX_BEACONS} message and selfEntity 
 * lastSeenBeacons/*from  www .  j a  v a  2  s  .  c o m*/
 * @param beacons - intersection between selfEntity lastSeenBeacons and beacons contained in the 
 * {@link MessageType#PROX_BEACONS} received
 * @param sender - {@link Entity} which sent the {@link MessageType#PROX_BEACONS} message
 * @param logId - Parameter used only for logging
 */
private void evaluateProximityD2D(final ArrayList<Entity> beacons, final Entity sender, final String logId) {

    if (beacons.isEmpty() || sender.getEntityID().equalsIgnoreCase(selfEntity.getEntityID()))
        return;

    scheduler.schedule(new Runnable() {

        @Override
        public void run() {
            DistanceRange bestDistance = DistanceRange.SAME_BEACON;

            ArrayList<Entity> queue;

            synchronized (lastSeenBeacons) {
                queue = new ArrayList<>(lastSeenBeacons);
            }

            for (Entity common : beacons)
                for (Entity mine : queue)
                    if (common.equals(mine))
                        switch (common.getDistanceRange()) {
                        case IMMEDIATE:
                        case NEXT_TO:
                            bestDistance = (mine.getDistanceRange().ordinal() < bestDistance.ordinal())
                                    ? ((mine.getDistanceRange().ordinal() < common.getDistanceRange().ordinal())
                                            ? common.getDistanceRange()
                                            : mine.getDistanceRange())
                                    : bestDistance;
                            break;

                        default:
                            bestDistance = (mine.getDistanceRange().ordinal() <= DistanceRange.NEXT_TO.ordinal()
                                    && common.getDistanceRange().ordinal() < bestDistance.ordinal())
                                            ? common.getDistanceRange()
                                            : bestDistance;
                            break;
                        }

            /*
             * if security configuration allows sending of proximity messages, a PROXIMITY_UPDATE
             * message is sent; otherwise, a call to evaluateProximity is performed in order to
             * verify if a proximity event has to be fired (in fact it is not allowed to send
             * PROX_BEACONS messages, so it is impossible to receive PROXIMITY_UPDATE messages from
             * other devices).
             * 
             */
            if (securityManager.check_proximity_changes_enabled())
                sendProximityUpdateMessage(selfEntity, sender, bestDistance);
            else
                evaluateProximity(selfEntity, sender, bestDistance, logId);

            evaluateGeofenceD2D(selfEntity, sender, bestDistance, logId);
        }
    });
}

From source file:it.polimi.geinterface.GroupEntityManager.java

/**
 * Method used to handle a {@link MessageType#SYNC_REQ} message: if the <code>group</code> is matched
 * and the computed {@link DistanceRange} is less or equal than <code>distanceRange</code>, a 
 * {@link MessageType#SYNC_RESP} message is sent on the topic <code>topic</code>
 * @param topic - the topic where the {@link MessageType#SYNC_RESP} has to be sent
 * @param beacons - beacons contained in the {@link MessageType#SYNC_REQ} message
 * @param group - the {@link Group} that has to be matched
 * @param distanceRange - the {@link DistanceRange} that has to be matched
 *//*from w ww  .ja  v  a2 s .c o  m*/
private void handleSyncReq(final String topic, final ArrayList<Entity> beacons, final JSONObject group,
        final DistanceRange distanceRange) {

    scheduler.schedule(new Runnable() {

        @Override
        public void run() {

            PropertiesFilter filter = null;

            DistanceRange maxDistance = distanceRange;

            if (!((String) group.get(JsonStrings.FILTER)).equals(""))
                try {
                    filter = PropertiesFilter.parseFromString((String) group.get(JsonStrings.FILTER));
                } catch (Exception e) {
                    e.printStackTrace();
                }
            String entityId = (String) group.get(JsonStrings.ENTITY_ID);
            Type entityType = Type.valueOf((String) group.get(JsonStrings.ENTITY_TYPE));
            String groupDesc = (String) group.get(JsonStrings.GROUP_DESCRIPTOR);

            Group g = new Group.Builder(groupDesc).setEntityID(entityId).setEntityType(entityType)
                    .setFilter(filter).build();

            if (!g.evaluate(selfEntity))
                return;

            DistanceRange bestDistance = DistanceRange.SAME_WIFI;
            ArrayList<Entity> queue;

            synchronized (lastSeenBeacons) {
                queue = new ArrayList<>(lastSeenBeacons);
                //intersection to obtain common beacons
                beacons.retainAll(lastSeenBeacons);
            }

            Builder builder = new Builder(selfEntity.getEntityID(), Type.DEVICE);
            JSONObject selfProps = selfEntity.getProperties();
            builder.addProperties(selfProps);

            if (beacons.size() == 0) {
                if (DistanceRange.SAME_WIFI.ordinal() <= maxDistance.ordinal()) {
                    builder.setDistance(DistanceRange.SAME_WIFI);
                    networkClient.publishMessage(topic,
                            MessageUtils.buildSyncRespMessage(builder.build(), topic));
                }
                return;
            }

            for (Entity common : beacons)
                for (Entity mine : queue)
                    if (common.equals(mine))
                        switch (common.getDistanceRange()) {
                        case IMMEDIATE:
                        case NEXT_TO:
                            bestDistance = (mine.getDistanceRange().ordinal() < bestDistance.ordinal())
                                    ? ((mine.getDistanceRange().ordinal() < common.getDistanceRange().ordinal())
                                            ? common.getDistanceRange()
                                            : mine.getDistanceRange())
                                    : bestDistance;
                            break;

                        default:
                            bestDistance = (mine.getDistanceRange().ordinal() <= DistanceRange.NEXT_TO.ordinal()
                                    && common.getDistanceRange().ordinal() < bestDistance.ordinal())
                                            ? common.getDistanceRange()
                                            : bestDistance;
                            break;
                        }

            if (bestDistance.ordinal() <= maxDistance.ordinal()) {
                builder.setDistance(bestDistance);
                networkClient.publishMessage(topic, MessageUtils.buildSyncRespMessage(builder.build(), topic));
            }
        }
    });

}

From source file:it.polimi.geinterface.GroupEntityManager.java

/**
 * Method that checks if there is some geofence subscription matching with one or more
 * beacons contained in the {@link MessageType#PROX_BEACONS} message received.
 * @param e - {@link Entity} which has received the {@link MessageType#PROX_BEACONS} message
 * @param beacons - List of {@link Entity} of type {@link Type#BLE_BEACON} contained in the message
 *//*from w  ww.  j  av  a  2 s .c o  m*/
private void evaluateGeofence(final Entity e, final ArrayList<Entity> beacons, final String logId) {

    if (geofenceSubscriptionList.size() == 0)
        return;

    scheduler.schedule(new Runnable() {

        @Override
        public void run() {

            for (Subscription s : geofenceSubscriptionList) {
                Group g = s.getG2();
                Entity eSub = s.getE1();

                if (e.equals(eSub)) {

                    for (Entity beacon : beacons)
                        if (g.evaluate(beacon))
                            evaluateGeofenceEventFiring(s, beacon, beacon.getDistanceRange(), logId);
                } else {
                    if (g.evaluate(e)) {
                        if (beacons.size() == 0)
                            //if no beacons are detected in BLE scan, is verified if a geofence exit happened
                            evaluateGeofenceEventFiring(s, e, DistanceRange.SAME_WIFI, logId);
                        else
                            for (Entity beacon : beacons)
                                if (beacon.equals(eSub))
                                    evaluateGeofenceEventFiring(s, e, beacon.getDistanceRange(), logId);
                    }
                }
            }
        }
    });

}

From source file:it.polimi.geinterface.GroupEntityManager.java

/**
 * Method that checks if some geofence subscription is matched by two entities of type {@link Type#DEVICE}
 * @param e1 - first {@link Entity} to be checked
 * @param e2 - second {@link Entity} to be checked
 * @param distance - {@link DistanceRange} the two entities are one respect the other
 * @param logId - used only for logging//from   w  w  w  .ja v a2 s.co  m
 */
private void evaluateGeofenceD2D(final Entity e1, final Entity e2, final DistanceRange distance,
        final String logId) {

    if (geofenceSubscriptionList.size() == 0) {
        Log.i(TAG, "Nessuna geofenceSubscription presente");
        return;
    }

    scheduler.schedule(new Runnable() {

        @Override
        public void run() {

            for (Subscription s : geofenceSubscriptionList) {
                Entity subEntity = s.getE1();
                Group subGroup = s.getG2();

                if (e1.equals(subEntity)) {
                    Log.i(TAG, e1.getEntityID() + " geofence ENTITY matching");
                    if (subGroup.evaluate(e2)) {
                        Log.i(TAG, e1.getEntityID() + " geofence ENTITY matching AND " + e2.getEntityID()
                                + " gefence GROUP matching");
                        evaluateGeofenceEventFiring(s, e2, distance, logId);
                    }
                } else {
                    if (e2.equals(subEntity)) {
                        Log.i(TAG, e2.getEntityID() + " geofence ENTITY matching");
                        if (subGroup.evaluate(e1)) {
                            Log.i(TAG, e2.getEntityID() + " geofence ENTITY matching AND " + e1.getEntityID()
                                    + " gefence GROUP matching");
                            evaluateGeofenceEventFiring(s, e1, distance, logId);
                        }
                    }
                }
            }
        }
    });

}