`
racingbird
  • 浏览: 23331 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论
文章列表

Ruby & MySQL

    博客分类:
  • Ruby
require "rubygems" require 'mysql' db = Mysql.connect('localhost', 'root','******','ruby') db.query("insert into people values(null,'卡夫',22)") begin query = db.query('select * from people') puts "There were #{query.num_rows} rows returned" query.eac ...

YAML

    博客分类:
  • Ruby
require 'yaml' class Person attr_accessor :name, :age end fred = Person.new fred.name = "Fred Bloggs" fred.age = 45 laura = Person.new laura.name = "Laura Smith" laura.age = 23 test_data = [fred, laura] puts YAML::dump(test_data) yaml_string =<<EN ...

PStore

    博客分类:
  • Ruby
  class Person attr_accessor :name, :job, :gender, :age end fred = Person.new fred.name = "Fred Bloggs" fred.age = 45 laura = Person.new laura.name = "Laura Smith" laura.age = 23 require 'pstore' store = PStore.new('storagefile') store.transaction do store ...
  public static void bubbleSort(int[] a){ for(int i=0; i<a.length-1; i++){ for(int j=0;j<a.length-i-1;j++){ if(a[j]>a[j+1]){ int tmp = a[j]; a[j] = a[j+1]; a[j+1] = tmp; } } } System.out.println(Arrays.toString(a)); }     method 2:   这是 i ...

仿真[汽车制造]

class Car{ private final int id; private boolean engine = false, driveTrain = false, wheels = false; public Car(int idn){ id = idn; } public Car(){ id = -1; } public synchronized int getId(){ return id; } public synchronized void addEngine(){ engine = tru ...

弹出框

  转自http://blog.csdn.net/arthur613/article/details/6163953   1.thickbox     目前用的比较多的,最新版本是thickbox3.1下载地址:http://jquery.com/demo/thickbox/#examples   2.colorBox 官方网站:http://colorpowered.com/colorbox/
package concurrency.waxomatic; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; import java.util.concurrent.locks.Condition; import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; ...
class Meal{ private final int orderNum; Meal(int orderNum){ this.orderNum = orderNum; } public String toString(){ return "Meal " + orderNum; } } class WaitPerson implements Runnable{ private Restaurant restaurant; public WaitPerson(Restaurant r){ restaurant = r ...
public Class Erased<T>{ private final int SIZE = 100; public static void f(Object arg){ if(arg instanceof T){} // Error T var = new T(); // Error T[] array = new T[SIZE]; // Error T[] array = (T)new Object[SIZE]; // Unchecked warning } }   Erased.java 中创建类型实例无法实 ...

多路分发3

使用常量相关的方法   常量相关的方法允许我们为每个enum实例提供方法的不同实现, 这使得常量相关的方法似乎是实现多路分发的完美解决方案。 不过,通过这种方式,enum实例虽然可以具有不同的行为, 但他们任然不是类型,不能将其作为方法签名中的参数类型 来使用。最好的办法是将enum用在switch语句中   import static enumerated.Outcome.*; public enum RoShamBo3 implements Competitor<RoShamBo3>{ PAPER{ public Outcome c ...
直接将RoShamBo1.java翻译为基于enum的版本是有问题的,因为enum实例不是类型, 不能将enum实例作为参数的类型,所以无法重载eval方法。   利用构造器来初始化每个enum实例,并以"一组"结果作为参数。二者放在一块,形成了 类似查询表的结构。   public interface Competitor<T extends Competitor<T>> { Outcome compete(T competitor); } public class RoShamBo { public ...

多路分发

 多路分发   Number.plus(Number)   Number是各种数字对象的超类。 当声明a.plus(b)时,并不知道a,b的确切类型。 如何正确地交互? Java只支持单路分发,如果要执行的操作包含了不止一个类型未知的对象时, 那么Java的动态绑定机制只能处理其中一个的类型。所以必须自己来判定其他的 类型,从而实现自己的动态绑定行为。   解决的办法就是多路分发,如果想使用2路分发,那么必须有2个方法调用, 第一个方法调用决定第一个未知类型,第二个方法调用决定第二个未知类型。 所以必须为每一个类型提供给一个实际的方法调用   一般而言,需要有 ...
public enum Input { NICKEL(5), DIME(10), QUARTER(25), DOLLAR(100), TOOTHPASTER(200), CHIPS(75), SODA(100), SOAP(50), ABORT_TRANSACTION{ public int amount(){ //Disallow throw new RuntimeException("ABORT.acmount()"); } }, STOP{ // This must be the last instance ...

使用enum的责任链

package enumerated; import java.util.Iterator; class Mail { enum GeneralDelivery{ YES, NO1, NO2, NO3, NO4, NO5 } enum Scannability{ UNSCANNABLE, YES1, YES2, YES3, YES4 } enum Readability{ ILLEGIBLE, YES1, YES2, YES3, YES4 } enum Address{ INCORRECT, OK1, OK2, OK3, OK ...
EnumSet与HashSet相比,非常快。     public enum AlalmPoints{ STAIR1, STAIR2, LOBBY, OFFICE1, OFFICE2; } public class EnumSets { EnumSet<AlarmPoints> points = EnumSet.noneOf(AlarmPoint.class); //Enmpty set points.add(STAIR1); }       EnumMap ,它要求其中的键(key)必须来自已个enum. 由于enum本身的限制 ...
Global site tag (gtag.js) - Google Analytics