/*
* Copyright (c) 2012 Denis Solonenko.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Public License v2.0
* which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
*/
package ru.orangesoftware.financisto2.test.builders;
import ru.orangesoftware.financisto2.db.DatabaseAdapter;
import ru.orangesoftware.financisto2.model.Attribute;
import ru.orangesoftware.financisto2.model.TransactionAttribute;
/**
* Created by IntelliJ IDEA.
* User: denis.solonenko
* Date: 7/5/12 11:43 PM
*/
public class AttributeBuilder {
private final DatabaseAdapter db;
private AttributeBuilder(DatabaseAdapter db) {
this.db = db;
}
public static AttributeBuilder withDb(DatabaseAdapter db) {
return new AttributeBuilder(db);
}
public Attribute createTextAttribute(String name) {
return createAttribute(name, Attribute.TYPE_TEXT);
}
public Attribute createNumberAttribute(String name) {
return createAttribute(name, Attribute.TYPE_NUMBER);
}
private Attribute createAttribute(String name, int type) {
Attribute a = new Attribute();
a.name = name;
a.type = type;
a.id = db.saveOrUpdate(a);
return a;
}
public static TransactionAttribute attributeValue(Attribute a, String value) {
TransactionAttribute ta = new TransactionAttribute();
ta.attributeId = a.id;
ta.value = value;
return ta;
}
}