Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
Merge branch 'app-presenter-tests'
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmason committed Jan 13, 2012
2 parents 4348982 + 88c1fac commit 2099604
Show file tree
Hide file tree
Showing 27 changed files with 1,443 additions and 558 deletions.
@@ -0,0 +1,122 @@
package org.zanata.common;

import java.io.Serializable;

public abstract class AbstractTranslationCount implements Serializable
{

private static final long serialVersionUID = 1L;

private int approved;
private int needReview;
private int untranslated;

public AbstractTranslationCount()
{
}

protected AbstractTranslationCount(int approved, int needReview, int untranslated)
{
this.approved = approved;
this.needReview = needReview;
this.untranslated = untranslated;
}

public void increment(ContentState state, int count)
{
set(state, get(state) + count);
}

public void decrement(ContentState state, int count)
{
set(state, get(state) - count);
}

public void set(ContentState state, int value)
{
switch (state)
{
case Approved:
approved = value;
break;
case NeedReview:
needReview = value;
break;
case New:
untranslated = value;
break;
default:
throw new RuntimeException("not implemented for state " + state.name());
}
}

public int get(ContentState state)
{
switch (state)
{
case Approved:
return approved;
case NeedReview:
return needReview;
case New:
return untranslated;
default:
throw new RuntimeException("not implemented for state " + state.name());
}
}

protected void add(AbstractTranslationCount other)
{
this.approved += other.approved;
this.needReview += other.needReview;
this.untranslated += other.untranslated;
}

protected void set(AbstractTranslationCount other)
{
this.approved = other.approved;
this.needReview = other.needReview;
this.untranslated = other.untranslated;
}

public int getTotal()
{
return approved + needReview + untranslated;
}

public int getApproved()
{
return approved;
}

public int getNeedReview()
{
return needReview;
}

public int getUntranslated()
{
return untranslated;
}

public int getNotApproved()
{
return untranslated + needReview;
}

@Override
public boolean equals(Object obj)
{
if (obj == this)
return true;
if (obj == null)
return false;
if (obj instanceof AbstractTranslationCount)
{
AbstractTranslationCount o = (AbstractTranslationCount) obj;
return (approved == o.approved && needReview == o.needReview && untranslated == o.untranslated);
}
return false;
}

}
@@ -1,117 +1,51 @@
package org.zanata.common;

import java.io.Serializable;

public final class TransUnitCount implements Serializable
public final class TransUnitCount extends AbstractTranslationCount
{

private static final long serialVersionUID = 1L;

private int approved;
private int needReview;
private int untranslated;

public TransUnitCount()
{
}

public TransUnitCount(int approved, int needReview, int untranslated)
{
this.approved = approved;
this.needReview = needReview;
this.untranslated = untranslated;
super(approved, needReview, untranslated);
}

public void increment(ContentState state)
{
increment(state, 1);
}

public void increment(ContentState state, int count)
{
set(state, get(state) + count);
}

public void decrement(ContentState state)
{
decrement(state, 1);
}

public void decrement(ContentState state, int count)
{
set(state, get(state) - count);
}

public void set(ContentState state, int value)
{
switch (state)
{
case Approved:
approved = value;
break;
case NeedReview:
needReview = value;
break;
case New:
untranslated = value;
break;
default:
throw new RuntimeException("not implemented for state " + state.name());
}
}

public int get(ContentState state)
{
switch (state)
{
case Approved:
return approved;
case NeedReview:
return needReview;
case New:
return untranslated;
default:
throw new RuntimeException("not implemented for state " + state.name());
}
}

public void add(TransUnitCount other)
{
this.approved += other.approved;
this.needReview += other.needReview;
this.untranslated += other.untranslated;
super.add(other);
}

public void set(TransUnitCount other)
{
this.approved = other.approved;
this.needReview = other.needReview;
this.untranslated = other.untranslated;
}

public int getTotal()
{
return approved + needReview + untranslated;
}

public int getApproved()
{
return approved;
super.set(other);
}

public int getNeedReview()
@Override
public boolean equals(Object obj)
{
return needReview;
}

public int getUntranslated()
{
return untranslated;
}

public int getNotApproved()
{
return untranslated + needReview;
if (obj == this)
return true;
if (obj == null)
return false;
if (obj instanceof TransUnitCount)
{
return super.equals(obj);
}
return false;
}

}
@@ -1,106 +1,27 @@
package org.zanata.common;

import java.io.Serializable;

public class TransUnitWords implements Serializable
public class TransUnitWords extends AbstractTranslationCount
{
private static final long serialVersionUID = 1L;

private int approved;
private int needReview;
private int untranslated;
private static final long serialVersionUID = 849734798480292025L;

public TransUnitWords()
{
}

public TransUnitWords(int approved, int needReview, int untranslated)
{
this.approved = approved;
this.needReview = needReview;
this.untranslated = untranslated;
}

public void increment(ContentState state, int count)
{
set(state, get(state) + count);
}

public void decrement(ContentState state, int count)
{
set(state, get(state) - count);
}

public void set(ContentState state, int value)
{
switch (state)
{
case Approved:
approved = value;
break;
case NeedReview:
needReview = value;
break;
case New:
untranslated = value;
break;
default:
throw new RuntimeException("not implemented for state " + state.name());
}
}

public int get(ContentState state)
{
switch (state)
{
case Approved:
return approved;
case NeedReview:
return needReview;
case New:
return untranslated;
default:
throw new RuntimeException("not implemented for state " + state.name());
}
super(approved, needReview, untranslated);
}

public void add(TransUnitWords other)
{
this.approved += other.approved;
this.needReview += other.needReview;
this.untranslated += other.untranslated;
super.add(other);
}

public void set(TransUnitWords other)
{
this.approved = other.approved;
this.needReview = other.needReview;
this.untranslated = other.untranslated;
}

public int getTotal()
{
return approved + needReview + untranslated;
}

public int getApproved()
{
return approved;
}

public int getNeedReview()
{
return needReview;
}

public int getUntranslated()
{
return untranslated;
}

public int getNotApproved()
{
return untranslated + needReview;
super.set(other);
}

public int getPer()
Expand All @@ -112,8 +33,22 @@ public int getPer()
}
else
{
double per = 100 * approved / total;
double per = 100 * getApproved() / total;
return (int) Math.ceil(per);
}
}

@Override
public boolean equals(Object obj)
{
if (obj == this)
return true;
if (obj == null)
return false;
if (obj instanceof TransUnitWords)
{
return super.equals(obj);
}
return false;
}
}

0 comments on commit 2099604

Please sign in to comment.