This repository has been archived by the owner on Nov 9, 2017. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
27 changed files
with
1,443 additions
and
558 deletions.
There are no files selected for viewing
122 changes: 122 additions & 0 deletions
122
common/zanata-common-api/src/main/java/org/zanata/common/AbstractTranslationCount.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
|
||
} |
96 changes: 15 additions & 81 deletions
96
common/zanata-common-api/src/main/java/org/zanata/common/TransUnitCount.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.