Aviv Ben-Yosef abyx

View 0001-Fix-SortedSet-to-ensure-objects-comparable-with.patch
1 2 3 4 5 6 7 8 9 10
From 9c168445300c6fda62173d37fbbbffa1a2136e03 Mon Sep 17 00:00:00 2001
From: Aviv Ben-Yosef <aviv.by@gmail.com>
Date: Wed, 8 Jun 2011 11:10:11 +0300
Subject: [PATCH] Fix SortedSet to ensure objects comparable with <=>
 
Fixes 2 failing specs for SortedSet:
- SortedSet#add takes only values which responds <=>
- SortedSet#initialize takes only values which respond to <=>
---
lib/set.rb | 1 +
View RetrierTest.java
1 2 3 4 5 6 7 8 9 10
public class RetrierTest {
private static int count = 0;
 
@Rule public RetryRule rule = new RetryRule();
@Test
@Retry
public void failsFirst() throws Exception {
count++;
assertEquals(2, count);
View cart_dsl.rb
1 2 3 4 5 6 7 8 9 10
describe 'cart' do
it 'allows discount after purchasing certain amount' do
product = Product.new('Snickers', 3)
cart = Cart.new
6.times { cart << product }
 
cart.when_buying(product).times(5).get(1).free()
 
cart.total.should == 5*3
View appserver.rb
1 2 3 4 5
name "appserver"
description "An application server"
run_list(%w{
recipe[apache2]
})
View default_node.pp
1 2 3 4 5 6 7 8 9 10
class default_node {
package { 'apache2':
ensure => installed
}
service { 'apache2':
ensure => true,
enable => true,
require => Package['apache2'],
}
}
View gist:746606
1 2 3 4 5 6 7 8
public void bind() {
display.getSaveButton().addClickHandler(
new ClickHandler() {
@Override public void click(ClickEvent e) {
// Magic happens here
}
});
}
View AccountTest.java
1 2 3 4 5 6 7 8 9 10
public class AccountTest {
@Test public void contains() throws Exception {
SortedSet<Account> set = new TreeSet<Account>(Account.NAME_COMPARATOR);
Account first = new Account("first", 1);
set.add(first);
Account otherFirst = new Account("first", 2);
assertFalse(set.contains(otherFirst));
}
}
View Comparator.java
1 2 3 4 5 6 7 8 9 10
Comparator<Account> NAME_COMPARATOR = new Comparator<Account>() {
@Override public int compare(Account a1, Account a2) {
if (a1.name == null) {
if (a2.name == null) {
return 0;
}
return -1;
}
return a1.name.compareTo(a2.name);
}
View Account.java
1 2 3 4 5 6 7 8 9 10
public class Account {
private final String name;
private final int id;
public Account(String name, int id) {
this.name = name;
this.id = id;
}
public int getId() { return id; }
public String getName() { return name; }
@Override public int hashCode() {
Something went wrong with that request. Please try again.