Skip to content

Commit

Permalink
#1 #2 #3 model changes
Browse files Browse the repository at this point in the history
now implements Parcelable
  • Loading branch information
waj0 committed Apr 16, 2014
1 parent 6b85047 commit 3e1e44c
Show file tree
Hide file tree
Showing 2 changed files with 122 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -1,26 +1,58 @@
package cz.fi.android.formulamanager.app;

import android.os.Parcel;
import android.os.Parcelable;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
* Created by Majo on 9. 4. 2014.
* Just example formula class, it is not used yet
*/
public class Formula {
public class Formula implements Parcelable {

private Long id;
private String name;
private List<Parameter> params;

private String parsable;
private String description;
private String rawFormula;

public Formula() {
params = new ArrayList<Parameter>();
}

public Formula(Parcel parcel) {
this.id = parcel.readLong();
this.name = parcel.readString();
this.rawFormula = parcel.readString();

params = parcel.readArrayList(getClass().getClassLoader());
}

@Override
public int describeContents() {
return 0;
}

@Override
public void writeToParcel(Parcel parcel, int i) {
parcel.writeLong(this.id);
parcel.writeString(this.name);
parcel.writeString(this.rawFormula);

parcel.writeList(params);
}

public static final Parcelable.Creator CREATOR = new Parcelable.Creator() {
public Formula createFromParcel(Parcel in) {
return new Formula(in);
}

public Formula[] newArray(int size) {
return new Formula[size];
}
};

public Long getId() {
return id;
}
Expand All @@ -45,28 +77,33 @@ public void setParams(List<Parameter> params) {
this.params = params;
}

public String getParsable() {
return parsable;
}

public void setParsable(String parsable) {
this.parsable = parsable;
}

public String getDescription() {
return description;
public String getRawFormula() {
return rawFormula;
}

public void setDescription(String description) {
this.description = description;
public void setRawFormula(String rawFormula) {
this.rawFormula = rawFormula;
}

/**
* Adds parameter to formula, if it exists, method will edit it
* @param p parameter to be added/edited
*/
public void addParam(Parameter p) {
if(p != null) {
if(p == null) {
return;
}
int index = params.indexOf(p);
if (index > -1){
Parameter ex = params.get(index);
ex.setName(p.getName());
ex.setType(p.getType());
} else {
params.add(p);
}
}


public String getParamsAsString(){
String ret = "";
for(Parameter p : params) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,61 @@
package cz.fi.android.formulamanager.app;

import android.os.Parcel;
import android.os.Parcelable;

/**
* Created by Majo on 13. 4. 2014.
*/
public class Parameter {
public class Parameter implements Parcelable {

//types of parameters
public static final int PARAM_REGULAR = 0; //regular one value param
public static final int PARAM_INDEX = 1; //index in summation etc
public static final int PARAM_STEP = 2; //increment after each calculation

Long id;
String name;
int type;

public Parameter() {
}

public Parameter(Parcel in) {
this.id = in.readLong();
this.name = in.readString();
this.type = in.readInt();
}

@Override
public int describeContents() {
return 0;
}

@Override
public void writeToParcel(Parcel parcel, int i) {
parcel.writeLong(this.id);
parcel.writeString(this.name);
parcel.writeInt(this.type);
}

public static final Parcelable.Creator CREATOR = new Parcelable.Creator() {
public Parameter createFromParcel(Parcel in) {
return new Parameter(in);
}

public Parameter[] newArray(int size) {
return new Parameter[size];
}
};

public Long getId() {
return id;
}

public void setId(Long id) {
this.id = id;
}

public String getName() {
return name;
}
Expand All @@ -22,4 +71,21 @@ public int getType() {
public void setType(int type) {
this.type = type;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;

Parameter parameter = (Parameter) o;

if (!id.equals(parameter.id)) return false;

return true;
}

@Override
public int hashCode() {
return id.hashCode();
}
}

0 comments on commit 3e1e44c

Please sign in to comment.