Esempio n. 1
0
    public static void printNeighbors(ArrayList neighbors) {
        int i = 0;
        for(Neighbor neighbor : neighbors) {
            Instance instance = neighbor.getInstance();

            System.out.println("\nNeighbor " + (i + 1) + ", distance: " + neighbor.getDistance());
            i++;
            for(Feature f : instance.getAttributes()) {
                System.out.print(f.getName() + ": ");
                if(f instanceof Category) {
                    System.out.println(((Category)f).getCategory().toString());
                }
                else if(f instanceof Distance) {
                    System.out.println(((Distance)f).getDistance().toString());
                }
                else if (f instanceof Expiration) {
                    System.out.println(((Expiration)f).getExpiry().toString());
                }
                else if (f instanceof Handset) {
                    System.out.print(((Handset)f).getOs().toString() + ", ");
                    System.out.println(((Handset)f).getDevice().toString());
                }
                else if (f instanceof Offer) {
                    System.out.println(((Offer)f).getOfferType().toString());
                }
                else if (f instanceof WSAction) {
                    System.out.println(((WSAction)f).getAction().toString());
                }
            }
        }
    }
Esempio n. 2
0
    public static WSAction.Action determineMajority(ArrayList neighbors) {
        int yea = 0, ney = 0;

        for(int i = 0; i < neighbors.size(); i++) { 			Neighbor neighbor = neighbors.get(i); 			Instance instance = neighbor.getInstance(); 			if(instance.isRedeemed()) { 				yea++; 			} 			else { 				ney++; 			} 		} 		 		if(yea > ney) {
            return WSAction.Action.Redeem;
        }
        else {