repo_name stringlengths 7 104 | file_path stringlengths 13 198 | context stringlengths 67 7.15k | import_statement stringlengths 16 4.43k | code stringlengths 40 6.98k | prompt stringlengths 227 8.27k | next_line stringlengths 8 795 |
|---|---|---|---|---|---|---|
sih4sing5hong5/han3_ji7_tsoo1_kian3 | src/test/java/idsgen/CharComponentStructureAdjuster/TriElementsReplacerTest.java | // Path: src/main/java/idsrend/charcomponent/CharComponent.java
// public abstract class CharComponent
// {
// public abstract boolean 是文部件();
//
// public abstract boolean 是字部件();
//
// /**
// * 取得部件的字串形態
// *
// * @return 部件字串形態
// */
// public String 部件組字式()
// {
// return new String(Character.toChars(Unicode編號()));
// }
//
// /**
// * 取得部件Unicode編碼
// *
// * @return 部件Unicode編碼
// */
// public abstract int Unicode編號();
//
// /**
// * 提到這个部件下跤的組字式。
// *
// * @return 這个物件下跤的組字式
// */
// public abstract String 樹狀結構組字式();
//
// /**
// * 以此部件結構產生活字結構。用<code>ChineseCharacterTypeSetter</code>
// * (活字設定工具)來轉換成ChineseCharacterMovableType(活字)。
// *
// * @param chineseCharacterTypeSetter
// * 欲採用的活字設定工具
// * @param parent
// * 此活字結構的上層活字
// * @return 產生出來的活字結構
// */
// public abstract ChineseCharCompositeMoveabletype typeset(
// ChineseCharacterTypeSetter chineseCharacterTypeSetter,
// ChineseCharacterMovableTypeTzu parent);
//
// }
| import static org.junit.Assert.assertEquals;
import org.junit.Test;
import cc.ccomponent_adjuster.ExpSequenceNoLookup;
import idsrend.CharComponentStructureAdjuster.TriElementsReplacer;
import idsrend.charcomponent.CharComponent;
import idsrend.parser.IDSParser; | package idsgen.CharComponentStructureAdjuster;
public class TriElementsReplacerTest
{
protected TriElementsReplacer 代換工具 = new TriElementsReplacer();
@Test
public void 左右組字方式()
{
assertEquals("⿰口⿰禾火", 代換結果("⿲口禾火"));
}
@Test
public void 上下組字方式()
{
assertEquals("⿱立⿱日心", 代換結果("⿳立日心"));
}
@Test
public void 左右雙層組字方式()
{
assertEquals("⿱⿰糹⿰言糹攵", 代換結果("⿱⿲糹言糹攵"));
}
@Test
public void 巢狀三部件組合符號()
{
assertEquals("⿺辶⿱宀⿱珤⿰隹⿰貝招", 代換結果("⿺辶⿳宀珤⿲隹貝招"));
}
protected String 代換結果(String 組字式)
{
IDSParser 解析工具 = new IDSParser(組字式, new ExpSequenceNoLookup()); | // Path: src/main/java/idsrend/charcomponent/CharComponent.java
// public abstract class CharComponent
// {
// public abstract boolean 是文部件();
//
// public abstract boolean 是字部件();
//
// /**
// * 取得部件的字串形態
// *
// * @return 部件字串形態
// */
// public String 部件組字式()
// {
// return new String(Character.toChars(Unicode編號()));
// }
//
// /**
// * 取得部件Unicode編碼
// *
// * @return 部件Unicode編碼
// */
// public abstract int Unicode編號();
//
// /**
// * 提到這个部件下跤的組字式。
// *
// * @return 這个物件下跤的組字式
// */
// public abstract String 樹狀結構組字式();
//
// /**
// * 以此部件結構產生活字結構。用<code>ChineseCharacterTypeSetter</code>
// * (活字設定工具)來轉換成ChineseCharacterMovableType(活字)。
// *
// * @param chineseCharacterTypeSetter
// * 欲採用的活字設定工具
// * @param parent
// * 此活字結構的上層活字
// * @return 產生出來的活字結構
// */
// public abstract ChineseCharCompositeMoveabletype typeset(
// ChineseCharacterTypeSetter chineseCharacterTypeSetter,
// ChineseCharacterMovableTypeTzu parent);
//
// }
// Path: src/test/java/idsgen/CharComponentStructureAdjuster/TriElementsReplacerTest.java
import static org.junit.Assert.assertEquals;
import org.junit.Test;
import cc.ccomponent_adjuster.ExpSequenceNoLookup;
import idsrend.CharComponentStructureAdjuster.TriElementsReplacer;
import idsrend.charcomponent.CharComponent;
import idsrend.parser.IDSParser;
package idsgen.CharComponentStructureAdjuster;
public class TriElementsReplacerTest
{
protected TriElementsReplacer 代換工具 = new TriElementsReplacer();
@Test
public void 左右組字方式()
{
assertEquals("⿰口⿰禾火", 代換結果("⿲口禾火"));
}
@Test
public void 上下組字方式()
{
assertEquals("⿱立⿱日心", 代換結果("⿳立日心"));
}
@Test
public void 左右雙層組字方式()
{
assertEquals("⿱⿰糹⿰言糹攵", 代換結果("⿱⿲糹言糹攵"));
}
@Test
public void 巢狀三部件組合符號()
{
assertEquals("⿺辶⿱宀⿱珤⿰隹⿰貝招", 代換結果("⿺辶⿳宀珤⿲隹貝招"));
}
protected String 代換結果(String 組字式)
{
IDSParser 解析工具 = new IDSParser(組字式, new ExpSequenceNoLookup()); | CharComponent 部件樹 = 解析工具.解析().get(0); |
sih4sing5hong5/han3_ji7_tsoo1_kian3 | src/main/java/cc/layouttools/BisearchPasteAssembler.java | // Path: src/main/java/cc/movabletype/SeprateMovabletype.java
// public class SeprateMovabletype
// {
// /** 目前字體大細,所在 */
// private Vector<PlaneGeometry> 字;
// /** 為著保留字體闊,若維護矩陣顛倒愛去顧平移 */
// private Vector<PlaneGeometry> 原本字體;
// /** 加粗莫合併的外殼 */
// private Vector<PlaneGeometry> 字外殼;
// /** 這馬的範圍,是為著閃避「一字問題」 */
// private Rectangle2D.Double 這馬;
// /** 目標範圍,上尾印的時陣愛看印偌大 */
// private Rectangle2D.Double 目標;
//
// public SeprateMovabletype()
// {
// 字 = new Vector<PlaneGeometry>();
// 原本字體 = new Vector<PlaneGeometry>();
// 字外殼 = null;
// 這馬 = new Rectangle.Double();
// 目標 = new Rectangle.Double();
// }
//
// public SeprateMovabletype(PlaneGeometry 幾何)
// {
// this();
// 字.add(幾何);
// 原本字體.add(幾何);
// 這馬字範圍();
// }
| import cc.movabletype.SeprateMovabletype; | package cc.layouttools;
/**
* 利用二元搜尋來組合兩個活字,並且依據兩個活字之間筆劃的關係,調整兩活字的間距。
*
* @author Ihc
*/
public class BisearchPasteAssembler
{
// public BisearchPasteAssembler()
// {
// this.模組 = null;
// }
//
// /**
// * 建立二元搜尋貼合工具
// *
// * @param 模組
// * 要執行的二元搜尋貼合模組
// * @throws IllegalArgumentException
// * 若模組為null,則丟出此例外
// */
// public BisearchPasteAssembler(BisearchPasteAsmMod 模組) throws IllegalArgumentException
// {
// this.模組 = 模組;
// if (模組 == null)
// throw new IllegalArgumentException();
// }
/**
* 用初使化設定的模組,來產生調整後的各活字物件
*
* @param 模組
* 要執行的二元搜尋貼合模組
* @param 活字物件
* 要調整的活字物件
*/ | // Path: src/main/java/cc/movabletype/SeprateMovabletype.java
// public class SeprateMovabletype
// {
// /** 目前字體大細,所在 */
// private Vector<PlaneGeometry> 字;
// /** 為著保留字體闊,若維護矩陣顛倒愛去顧平移 */
// private Vector<PlaneGeometry> 原本字體;
// /** 加粗莫合併的外殼 */
// private Vector<PlaneGeometry> 字外殼;
// /** 這馬的範圍,是為著閃避「一字問題」 */
// private Rectangle2D.Double 這馬;
// /** 目標範圍,上尾印的時陣愛看印偌大 */
// private Rectangle2D.Double 目標;
//
// public SeprateMovabletype()
// {
// 字 = new Vector<PlaneGeometry>();
// 原本字體 = new Vector<PlaneGeometry>();
// 字外殼 = null;
// 這馬 = new Rectangle.Double();
// 目標 = new Rectangle.Double();
// }
//
// public SeprateMovabletype(PlaneGeometry 幾何)
// {
// this();
// 字.add(幾何);
// 原本字體.add(幾何);
// 這馬字範圍();
// }
// Path: src/main/java/cc/layouttools/BisearchPasteAssembler.java
import cc.movabletype.SeprateMovabletype;
package cc.layouttools;
/**
* 利用二元搜尋來組合兩個活字,並且依據兩個活字之間筆劃的關係,調整兩活字的間距。
*
* @author Ihc
*/
public class BisearchPasteAssembler
{
// public BisearchPasteAssembler()
// {
// this.模組 = null;
// }
//
// /**
// * 建立二元搜尋貼合工具
// *
// * @param 模組
// * 要執行的二元搜尋貼合模組
// * @throws IllegalArgumentException
// * 若模組為null,則丟出此例外
// */
// public BisearchPasteAssembler(BisearchPasteAsmMod 模組) throws IllegalArgumentException
// {
// this.模組 = 模組;
// if (模組 == null)
// throw new IllegalArgumentException();
// }
/**
* 用初使化設定的模組,來產生調整後的各活字物件
*
* @param 模組
* 要執行的二元搜尋貼合模組
* @param 活字物件
* 要調整的活字物件
*/ | public void 執行(BisearchPasteAsmMod 模組, SeprateMovabletype[] 活字物件) |
sih4sing5hong5/han3_ji7_tsoo1_kian3 | src/main/java/cc/layouttools/FullSurronder.java | // Path: src/main/java/cc/movabletype/PieceMovableTypeTzu.java
// public class PieceMovableTypeTzu extends ChineseCharacterMovableTypeTzu
// implements PieceMovableType
// {
// /**
// * 物件活字
// */
// private final SeprateMovabletype rectangularArea;
//
// /**
// * 建立字活字結構
// *
// * @param parent
// * 上一層的活字結構。若上層為樹狀的樹根,傳入null
// * @param chineseCharacterTzu
// * 字部件結構
// * @param rectangularArea
// * 物件活字
// */
// public PieceMovableTypeTzu(ChineseCharacterMovableTypeTzu parent,
// FinalCharComponent chineseCharacterTzu,
// SeprateMovabletype rectangularArea)
// {
// super(parent, chineseCharacterTzu);
// this.rectangularArea = rectangularArea;
// }
//
// @Override
// public SeprateMovabletype getPiece()
// {
// return rectangularArea;
// }
//
// /**
// * 取得合體活字下各個元件的活字物件
// *
// * @return 各個元件的活字物件
// */
// public SeprateMovabletype[] 取得活字物件()
// {
// SeprateMovabletype[] 活字物件 = new SeprateMovabletype[getChildren().length];
// for (int i = 0; i < getChildren().length; ++i)
// 活字物件[i] = new SeprateMovabletype((SeprateMovabletype)
// ((PieceMovableType) getChildren()[i]).getPiece());
// return 活字物件;
// }
// }
//
// Path: src/main/java/cc/movabletype/SeprateMovabletype.java
// public class SeprateMovabletype
// {
// /** 目前字體大細,所在 */
// private Vector<PlaneGeometry> 字;
// /** 為著保留字體闊,若維護矩陣顛倒愛去顧平移 */
// private Vector<PlaneGeometry> 原本字體;
// /** 加粗莫合併的外殼 */
// private Vector<PlaneGeometry> 字外殼;
// /** 這馬的範圍,是為著閃避「一字問題」 */
// private Rectangle2D.Double 這馬;
// /** 目標範圍,上尾印的時陣愛看印偌大 */
// private Rectangle2D.Double 目標;
//
// public SeprateMovabletype()
// {
// 字 = new Vector<PlaneGeometry>();
// 原本字體 = new Vector<PlaneGeometry>();
// 字外殼 = null;
// 這馬 = new Rectangle.Double();
// 目標 = new Rectangle.Double();
// }
//
// public SeprateMovabletype(PlaneGeometry 幾何)
// {
// this();
// 字.add(幾何);
// 原本字體.add(幾何);
// 這馬字範圍();
// }
| import cc.movabletype.PieceMovableTypeTzu;
import cc.movabletype.SeprateMovabletype; | package cc.layouttools;
/**
* 用於四面的包圍部件。從四面包住,像是「囗」等等。
*
* @author Ihc
*/
public class FullSurronder extends ObjMoveableTypeSurronder
{
/**
* 建立四面包圍工具
*
* @param 調整工具
* 使用此包圍工具的調整工具,並使用其自身合併相關函式
*/
public FullSurronder(MergePieceAdjuster 調整工具)
{
super(調整工具);
支援包圍部件.add("囗");
支援包圍部件.add("⼞");
支援包圍部件.add("⼝");
//這三個unicode都不一樣,直覺能包的都讓它能作用吧
}
@Override | // Path: src/main/java/cc/movabletype/PieceMovableTypeTzu.java
// public class PieceMovableTypeTzu extends ChineseCharacterMovableTypeTzu
// implements PieceMovableType
// {
// /**
// * 物件活字
// */
// private final SeprateMovabletype rectangularArea;
//
// /**
// * 建立字活字結構
// *
// * @param parent
// * 上一層的活字結構。若上層為樹狀的樹根,傳入null
// * @param chineseCharacterTzu
// * 字部件結構
// * @param rectangularArea
// * 物件活字
// */
// public PieceMovableTypeTzu(ChineseCharacterMovableTypeTzu parent,
// FinalCharComponent chineseCharacterTzu,
// SeprateMovabletype rectangularArea)
// {
// super(parent, chineseCharacterTzu);
// this.rectangularArea = rectangularArea;
// }
//
// @Override
// public SeprateMovabletype getPiece()
// {
// return rectangularArea;
// }
//
// /**
// * 取得合體活字下各個元件的活字物件
// *
// * @return 各個元件的活字物件
// */
// public SeprateMovabletype[] 取得活字物件()
// {
// SeprateMovabletype[] 活字物件 = new SeprateMovabletype[getChildren().length];
// for (int i = 0; i < getChildren().length; ++i)
// 活字物件[i] = new SeprateMovabletype((SeprateMovabletype)
// ((PieceMovableType) getChildren()[i]).getPiece());
// return 活字物件;
// }
// }
//
// Path: src/main/java/cc/movabletype/SeprateMovabletype.java
// public class SeprateMovabletype
// {
// /** 目前字體大細,所在 */
// private Vector<PlaneGeometry> 字;
// /** 為著保留字體闊,若維護矩陣顛倒愛去顧平移 */
// private Vector<PlaneGeometry> 原本字體;
// /** 加粗莫合併的外殼 */
// private Vector<PlaneGeometry> 字外殼;
// /** 這馬的範圍,是為著閃避「一字問題」 */
// private Rectangle2D.Double 這馬;
// /** 目標範圍,上尾印的時陣愛看印偌大 */
// private Rectangle2D.Double 目標;
//
// public SeprateMovabletype()
// {
// 字 = new Vector<PlaneGeometry>();
// 原本字體 = new Vector<PlaneGeometry>();
// 字外殼 = null;
// 這馬 = new Rectangle.Double();
// 目標 = new Rectangle.Double();
// }
//
// public SeprateMovabletype(PlaneGeometry 幾何)
// {
// this();
// 字.add(幾何);
// 原本字體.add(幾何);
// 這馬字範圍();
// }
// Path: src/main/java/cc/layouttools/FullSurronder.java
import cc.movabletype.PieceMovableTypeTzu;
import cc.movabletype.SeprateMovabletype;
package cc.layouttools;
/**
* 用於四面的包圍部件。從四面包住,像是「囗」等等。
*
* @author Ihc
*/
public class FullSurronder extends ObjMoveableTypeSurronder
{
/**
* 建立四面包圍工具
*
* @param 調整工具
* 使用此包圍工具的調整工具,並使用其自身合併相關函式
*/
public FullSurronder(MergePieceAdjuster 調整工具)
{
super(調整工具);
支援包圍部件.add("囗");
支援包圍部件.add("⼞");
支援包圍部件.add("⼝");
//這三個unicode都不一樣,直覺能包的都讓它能作用吧
}
@Override | public void 組合(PieceMovableTypeTzu 物件活字) |
sih4sing5hong5/han3_ji7_tsoo1_kian3 | src/main/java/cc/layouttools/FullSurronder.java | // Path: src/main/java/cc/movabletype/PieceMovableTypeTzu.java
// public class PieceMovableTypeTzu extends ChineseCharacterMovableTypeTzu
// implements PieceMovableType
// {
// /**
// * 物件活字
// */
// private final SeprateMovabletype rectangularArea;
//
// /**
// * 建立字活字結構
// *
// * @param parent
// * 上一層的活字結構。若上層為樹狀的樹根,傳入null
// * @param chineseCharacterTzu
// * 字部件結構
// * @param rectangularArea
// * 物件活字
// */
// public PieceMovableTypeTzu(ChineseCharacterMovableTypeTzu parent,
// FinalCharComponent chineseCharacterTzu,
// SeprateMovabletype rectangularArea)
// {
// super(parent, chineseCharacterTzu);
// this.rectangularArea = rectangularArea;
// }
//
// @Override
// public SeprateMovabletype getPiece()
// {
// return rectangularArea;
// }
//
// /**
// * 取得合體活字下各個元件的活字物件
// *
// * @return 各個元件的活字物件
// */
// public SeprateMovabletype[] 取得活字物件()
// {
// SeprateMovabletype[] 活字物件 = new SeprateMovabletype[getChildren().length];
// for (int i = 0; i < getChildren().length; ++i)
// 活字物件[i] = new SeprateMovabletype((SeprateMovabletype)
// ((PieceMovableType) getChildren()[i]).getPiece());
// return 活字物件;
// }
// }
//
// Path: src/main/java/cc/movabletype/SeprateMovabletype.java
// public class SeprateMovabletype
// {
// /** 目前字體大細,所在 */
// private Vector<PlaneGeometry> 字;
// /** 為著保留字體闊,若維護矩陣顛倒愛去顧平移 */
// private Vector<PlaneGeometry> 原本字體;
// /** 加粗莫合併的外殼 */
// private Vector<PlaneGeometry> 字外殼;
// /** 這馬的範圍,是為著閃避「一字問題」 */
// private Rectangle2D.Double 這馬;
// /** 目標範圍,上尾印的時陣愛看印偌大 */
// private Rectangle2D.Double 目標;
//
// public SeprateMovabletype()
// {
// 字 = new Vector<PlaneGeometry>();
// 原本字體 = new Vector<PlaneGeometry>();
// 字外殼 = null;
// 這馬 = new Rectangle.Double();
// 目標 = new Rectangle.Double();
// }
//
// public SeprateMovabletype(PlaneGeometry 幾何)
// {
// this();
// 字.add(幾何);
// 原本字體.add(幾何);
// 這馬字範圍();
// }
| import cc.movabletype.PieceMovableTypeTzu;
import cc.movabletype.SeprateMovabletype; | package cc.layouttools;
/**
* 用於四面的包圍部件。從四面包住,像是「囗」等等。
*
* @author Ihc
*/
public class FullSurronder extends ObjMoveableTypeSurronder
{
/**
* 建立四面包圍工具
*
* @param 調整工具
* 使用此包圍工具的調整工具,並使用其自身合併相關函式
*/
public FullSurronder(MergePieceAdjuster 調整工具)
{
super(調整工具);
支援包圍部件.add("囗");
支援包圍部件.add("⼞");
支援包圍部件.add("⼝");
//這三個unicode都不一樣,直覺能包的都讓它能作用吧
}
@Override
public void 組合(PieceMovableTypeTzu 物件活字)
{
/** 平推前先用的調整模組 */
FullSurOutsideAssembler 模組 = new FullSurOutsideAssembler(調整工具);
/** 平推後用的調整模組 */
FullSurInsideAssembler 後模組 = new FullSurInsideAssembler(調整工具);
/** 要使用的平推工具 */
FlatSurronder FlatSurronder = new FlatSurronder(調整工具, 模組, 後模組);
| // Path: src/main/java/cc/movabletype/PieceMovableTypeTzu.java
// public class PieceMovableTypeTzu extends ChineseCharacterMovableTypeTzu
// implements PieceMovableType
// {
// /**
// * 物件活字
// */
// private final SeprateMovabletype rectangularArea;
//
// /**
// * 建立字活字結構
// *
// * @param parent
// * 上一層的活字結構。若上層為樹狀的樹根,傳入null
// * @param chineseCharacterTzu
// * 字部件結構
// * @param rectangularArea
// * 物件活字
// */
// public PieceMovableTypeTzu(ChineseCharacterMovableTypeTzu parent,
// FinalCharComponent chineseCharacterTzu,
// SeprateMovabletype rectangularArea)
// {
// super(parent, chineseCharacterTzu);
// this.rectangularArea = rectangularArea;
// }
//
// @Override
// public SeprateMovabletype getPiece()
// {
// return rectangularArea;
// }
//
// /**
// * 取得合體活字下各個元件的活字物件
// *
// * @return 各個元件的活字物件
// */
// public SeprateMovabletype[] 取得活字物件()
// {
// SeprateMovabletype[] 活字物件 = new SeprateMovabletype[getChildren().length];
// for (int i = 0; i < getChildren().length; ++i)
// 活字物件[i] = new SeprateMovabletype((SeprateMovabletype)
// ((PieceMovableType) getChildren()[i]).getPiece());
// return 活字物件;
// }
// }
//
// Path: src/main/java/cc/movabletype/SeprateMovabletype.java
// public class SeprateMovabletype
// {
// /** 目前字體大細,所在 */
// private Vector<PlaneGeometry> 字;
// /** 為著保留字體闊,若維護矩陣顛倒愛去顧平移 */
// private Vector<PlaneGeometry> 原本字體;
// /** 加粗莫合併的外殼 */
// private Vector<PlaneGeometry> 字外殼;
// /** 這馬的範圍,是為著閃避「一字問題」 */
// private Rectangle2D.Double 這馬;
// /** 目標範圍,上尾印的時陣愛看印偌大 */
// private Rectangle2D.Double 目標;
//
// public SeprateMovabletype()
// {
// 字 = new Vector<PlaneGeometry>();
// 原本字體 = new Vector<PlaneGeometry>();
// 字外殼 = null;
// 這馬 = new Rectangle.Double();
// 目標 = new Rectangle.Double();
// }
//
// public SeprateMovabletype(PlaneGeometry 幾何)
// {
// this();
// 字.add(幾何);
// 原本字體.add(幾何);
// 這馬字範圍();
// }
// Path: src/main/java/cc/layouttools/FullSurronder.java
import cc.movabletype.PieceMovableTypeTzu;
import cc.movabletype.SeprateMovabletype;
package cc.layouttools;
/**
* 用於四面的包圍部件。從四面包住,像是「囗」等等。
*
* @author Ihc
*/
public class FullSurronder extends ObjMoveableTypeSurronder
{
/**
* 建立四面包圍工具
*
* @param 調整工具
* 使用此包圍工具的調整工具,並使用其自身合併相關函式
*/
public FullSurronder(MergePieceAdjuster 調整工具)
{
super(調整工具);
支援包圍部件.add("囗");
支援包圍部件.add("⼞");
支援包圍部件.add("⼝");
//這三個unicode都不一樣,直覺能包的都讓它能作用吧
}
@Override
public void 組合(PieceMovableTypeTzu 物件活字)
{
/** 平推前先用的調整模組 */
FullSurOutsideAssembler 模組 = new FullSurOutsideAssembler(調整工具);
/** 平推後用的調整模組 */
FullSurInsideAssembler 後模組 = new FullSurInsideAssembler(調整工具);
/** 要使用的平推工具 */
FlatSurronder FlatSurronder = new FlatSurronder(調整工具, 模組, 後模組);
| SeprateMovabletype[] 調整結果 = FlatSurronder.產生調整後活字(物件活字.取得活字物件()); |
sih4sing5hong5/han3_ji7_tsoo1_kian3 | src/main/java/cc/layouttools/UpHatSurrounder.java | // Path: src/main/java/cc/movabletype/PieceMovableTypeTzu.java
// public class PieceMovableTypeTzu extends ChineseCharacterMovableTypeTzu
// implements PieceMovableType
// {
// /**
// * 物件活字
// */
// private final SeprateMovabletype rectangularArea;
//
// /**
// * 建立字活字結構
// *
// * @param parent
// * 上一層的活字結構。若上層為樹狀的樹根,傳入null
// * @param chineseCharacterTzu
// * 字部件結構
// * @param rectangularArea
// * 物件活字
// */
// public PieceMovableTypeTzu(ChineseCharacterMovableTypeTzu parent,
// FinalCharComponent chineseCharacterTzu,
// SeprateMovabletype rectangularArea)
// {
// super(parent, chineseCharacterTzu);
// this.rectangularArea = rectangularArea;
// }
//
// @Override
// public SeprateMovabletype getPiece()
// {
// return rectangularArea;
// }
//
// /**
// * 取得合體活字下各個元件的活字物件
// *
// * @return 各個元件的活字物件
// */
// public SeprateMovabletype[] 取得活字物件()
// {
// SeprateMovabletype[] 活字物件 = new SeprateMovabletype[getChildren().length];
// for (int i = 0; i < getChildren().length; ++i)
// 活字物件[i] = new SeprateMovabletype((SeprateMovabletype)
// ((PieceMovableType) getChildren()[i]).getPiece());
// return 活字物件;
// }
// }
//
// Path: src/main/java/cc/movabletype/SeprateMovabletype.java
// public class SeprateMovabletype
// {
// /** 目前字體大細,所在 */
// private Vector<PlaneGeometry> 字;
// /** 為著保留字體闊,若維護矩陣顛倒愛去顧平移 */
// private Vector<PlaneGeometry> 原本字體;
// /** 加粗莫合併的外殼 */
// private Vector<PlaneGeometry> 字外殼;
// /** 這馬的範圍,是為著閃避「一字問題」 */
// private Rectangle2D.Double 這馬;
// /** 目標範圍,上尾印的時陣愛看印偌大 */
// private Rectangle2D.Double 目標;
//
// public SeprateMovabletype()
// {
// 字 = new Vector<PlaneGeometry>();
// 原本字體 = new Vector<PlaneGeometry>();
// 字外殼 = null;
// 這馬 = new Rectangle.Double();
// 目標 = new Rectangle.Double();
// }
//
// public SeprateMovabletype(PlaneGeometry 幾何)
// {
// this();
// 字.add(幾何);
// 原本字體.add(幾何);
// 這馬字範圍();
// }
| import cc.movabletype.PieceMovableTypeTzu;
import cc.movabletype.SeprateMovabletype; | package cc.layouttools;
/**
* 用於上蓋的包圍部件。蓋住上方,左右二邊只包含上方一小部份,像是「冖」、「宀」和「『學』上半部」等等。
*
* @author Ihc
*/
public class UpHatSurrounder extends ObjMoveableTypeSurronder
{
/**
* 建立上蓋包圍工具
*
* @param 調整工具
* 使用此包圍工具的調整工具,並使用其自身合併相關函式
*/
public UpHatSurrounder(MergePieceAdjuster 調整工具)
{
super(調整工具);
支援包圍部件.add("冖");
支援包圍部件.add("");//「冖」中研院造字
支援包圍部件.add("宀");
// 支援包圍部件.add("學");//TODO
}
@Override | // Path: src/main/java/cc/movabletype/PieceMovableTypeTzu.java
// public class PieceMovableTypeTzu extends ChineseCharacterMovableTypeTzu
// implements PieceMovableType
// {
// /**
// * 物件活字
// */
// private final SeprateMovabletype rectangularArea;
//
// /**
// * 建立字活字結構
// *
// * @param parent
// * 上一層的活字結構。若上層為樹狀的樹根,傳入null
// * @param chineseCharacterTzu
// * 字部件結構
// * @param rectangularArea
// * 物件活字
// */
// public PieceMovableTypeTzu(ChineseCharacterMovableTypeTzu parent,
// FinalCharComponent chineseCharacterTzu,
// SeprateMovabletype rectangularArea)
// {
// super(parent, chineseCharacterTzu);
// this.rectangularArea = rectangularArea;
// }
//
// @Override
// public SeprateMovabletype getPiece()
// {
// return rectangularArea;
// }
//
// /**
// * 取得合體活字下各個元件的活字物件
// *
// * @return 各個元件的活字物件
// */
// public SeprateMovabletype[] 取得活字物件()
// {
// SeprateMovabletype[] 活字物件 = new SeprateMovabletype[getChildren().length];
// for (int i = 0; i < getChildren().length; ++i)
// 活字物件[i] = new SeprateMovabletype((SeprateMovabletype)
// ((PieceMovableType) getChildren()[i]).getPiece());
// return 活字物件;
// }
// }
//
// Path: src/main/java/cc/movabletype/SeprateMovabletype.java
// public class SeprateMovabletype
// {
// /** 目前字體大細,所在 */
// private Vector<PlaneGeometry> 字;
// /** 為著保留字體闊,若維護矩陣顛倒愛去顧平移 */
// private Vector<PlaneGeometry> 原本字體;
// /** 加粗莫合併的外殼 */
// private Vector<PlaneGeometry> 字外殼;
// /** 這馬的範圍,是為著閃避「一字問題」 */
// private Rectangle2D.Double 這馬;
// /** 目標範圍,上尾印的時陣愛看印偌大 */
// private Rectangle2D.Double 目標;
//
// public SeprateMovabletype()
// {
// 字 = new Vector<PlaneGeometry>();
// 原本字體 = new Vector<PlaneGeometry>();
// 字外殼 = null;
// 這馬 = new Rectangle.Double();
// 目標 = new Rectangle.Double();
// }
//
// public SeprateMovabletype(PlaneGeometry 幾何)
// {
// this();
// 字.add(幾何);
// 原本字體.add(幾何);
// 這馬字範圍();
// }
// Path: src/main/java/cc/layouttools/UpHatSurrounder.java
import cc.movabletype.PieceMovableTypeTzu;
import cc.movabletype.SeprateMovabletype;
package cc.layouttools;
/**
* 用於上蓋的包圍部件。蓋住上方,左右二邊只包含上方一小部份,像是「冖」、「宀」和「『學』上半部」等等。
*
* @author Ihc
*/
public class UpHatSurrounder extends ObjMoveableTypeSurronder
{
/**
* 建立上蓋包圍工具
*
* @param 調整工具
* 使用此包圍工具的調整工具,並使用其自身合併相關函式
*/
public UpHatSurrounder(MergePieceAdjuster 調整工具)
{
super(調整工具);
支援包圍部件.add("冖");
支援包圍部件.add("");//「冖」中研院造字
支援包圍部件.add("宀");
// 支援包圍部件.add("學");//TODO
}
@Override | public void 組合(PieceMovableTypeTzu 物件活字) |
sih4sing5hong5/han3_ji7_tsoo1_kian3 | src/main/java/cc/layouttools/UpHatSurrounder.java | // Path: src/main/java/cc/movabletype/PieceMovableTypeTzu.java
// public class PieceMovableTypeTzu extends ChineseCharacterMovableTypeTzu
// implements PieceMovableType
// {
// /**
// * 物件活字
// */
// private final SeprateMovabletype rectangularArea;
//
// /**
// * 建立字活字結構
// *
// * @param parent
// * 上一層的活字結構。若上層為樹狀的樹根,傳入null
// * @param chineseCharacterTzu
// * 字部件結構
// * @param rectangularArea
// * 物件活字
// */
// public PieceMovableTypeTzu(ChineseCharacterMovableTypeTzu parent,
// FinalCharComponent chineseCharacterTzu,
// SeprateMovabletype rectangularArea)
// {
// super(parent, chineseCharacterTzu);
// this.rectangularArea = rectangularArea;
// }
//
// @Override
// public SeprateMovabletype getPiece()
// {
// return rectangularArea;
// }
//
// /**
// * 取得合體活字下各個元件的活字物件
// *
// * @return 各個元件的活字物件
// */
// public SeprateMovabletype[] 取得活字物件()
// {
// SeprateMovabletype[] 活字物件 = new SeprateMovabletype[getChildren().length];
// for (int i = 0; i < getChildren().length; ++i)
// 活字物件[i] = new SeprateMovabletype((SeprateMovabletype)
// ((PieceMovableType) getChildren()[i]).getPiece());
// return 活字物件;
// }
// }
//
// Path: src/main/java/cc/movabletype/SeprateMovabletype.java
// public class SeprateMovabletype
// {
// /** 目前字體大細,所在 */
// private Vector<PlaneGeometry> 字;
// /** 為著保留字體闊,若維護矩陣顛倒愛去顧平移 */
// private Vector<PlaneGeometry> 原本字體;
// /** 加粗莫合併的外殼 */
// private Vector<PlaneGeometry> 字外殼;
// /** 這馬的範圍,是為著閃避「一字問題」 */
// private Rectangle2D.Double 這馬;
// /** 目標範圍,上尾印的時陣愛看印偌大 */
// private Rectangle2D.Double 目標;
//
// public SeprateMovabletype()
// {
// 字 = new Vector<PlaneGeometry>();
// 原本字體 = new Vector<PlaneGeometry>();
// 字外殼 = null;
// 這馬 = new Rectangle.Double();
// 目標 = new Rectangle.Double();
// }
//
// public SeprateMovabletype(PlaneGeometry 幾何)
// {
// this();
// 字.add(幾何);
// 原本字體.add(幾何);
// 這馬字範圍();
// }
| import cc.movabletype.PieceMovableTypeTzu;
import cc.movabletype.SeprateMovabletype; | package cc.layouttools;
/**
* 用於上蓋的包圍部件。蓋住上方,左右二邊只包含上方一小部份,像是「冖」、「宀」和「『學』上半部」等等。
*
* @author Ihc
*/
public class UpHatSurrounder extends ObjMoveableTypeSurronder
{
/**
* 建立上蓋包圍工具
*
* @param 調整工具
* 使用此包圍工具的調整工具,並使用其自身合併相關函式
*/
public UpHatSurrounder(MergePieceAdjuster 調整工具)
{
super(調整工具);
支援包圍部件.add("冖");
支援包圍部件.add("");//「冖」中研院造字
支援包圍部件.add("宀");
// 支援包圍部件.add("學");//TODO
}
@Override
public void 組合(PieceMovableTypeTzu 物件活字)
{
/** 上蓋和下部拼合時的調整模組 */
UpHatAsmmod 模組 = new UpHatAsmmod(調整工具);
/** 將上下兩部件拼合的工具 */
BisearchPasteAssembler 貼合工具 = new BisearchPasteAssembler();
貼合工具.執行(模組, 物件活字.取得活字物件());
| // Path: src/main/java/cc/movabletype/PieceMovableTypeTzu.java
// public class PieceMovableTypeTzu extends ChineseCharacterMovableTypeTzu
// implements PieceMovableType
// {
// /**
// * 物件活字
// */
// private final SeprateMovabletype rectangularArea;
//
// /**
// * 建立字活字結構
// *
// * @param parent
// * 上一層的活字結構。若上層為樹狀的樹根,傳入null
// * @param chineseCharacterTzu
// * 字部件結構
// * @param rectangularArea
// * 物件活字
// */
// public PieceMovableTypeTzu(ChineseCharacterMovableTypeTzu parent,
// FinalCharComponent chineseCharacterTzu,
// SeprateMovabletype rectangularArea)
// {
// super(parent, chineseCharacterTzu);
// this.rectangularArea = rectangularArea;
// }
//
// @Override
// public SeprateMovabletype getPiece()
// {
// return rectangularArea;
// }
//
// /**
// * 取得合體活字下各個元件的活字物件
// *
// * @return 各個元件的活字物件
// */
// public SeprateMovabletype[] 取得活字物件()
// {
// SeprateMovabletype[] 活字物件 = new SeprateMovabletype[getChildren().length];
// for (int i = 0; i < getChildren().length; ++i)
// 活字物件[i] = new SeprateMovabletype((SeprateMovabletype)
// ((PieceMovableType) getChildren()[i]).getPiece());
// return 活字物件;
// }
// }
//
// Path: src/main/java/cc/movabletype/SeprateMovabletype.java
// public class SeprateMovabletype
// {
// /** 目前字體大細,所在 */
// private Vector<PlaneGeometry> 字;
// /** 為著保留字體闊,若維護矩陣顛倒愛去顧平移 */
// private Vector<PlaneGeometry> 原本字體;
// /** 加粗莫合併的外殼 */
// private Vector<PlaneGeometry> 字外殼;
// /** 這馬的範圍,是為著閃避「一字問題」 */
// private Rectangle2D.Double 這馬;
// /** 目標範圍,上尾印的時陣愛看印偌大 */
// private Rectangle2D.Double 目標;
//
// public SeprateMovabletype()
// {
// 字 = new Vector<PlaneGeometry>();
// 原本字體 = new Vector<PlaneGeometry>();
// 字外殼 = null;
// 這馬 = new Rectangle.Double();
// 目標 = new Rectangle.Double();
// }
//
// public SeprateMovabletype(PlaneGeometry 幾何)
// {
// this();
// 字.add(幾何);
// 原本字體.add(幾何);
// 這馬字範圍();
// }
// Path: src/main/java/cc/layouttools/UpHatSurrounder.java
import cc.movabletype.PieceMovableTypeTzu;
import cc.movabletype.SeprateMovabletype;
package cc.layouttools;
/**
* 用於上蓋的包圍部件。蓋住上方,左右二邊只包含上方一小部份,像是「冖」、「宀」和「『學』上半部」等等。
*
* @author Ihc
*/
public class UpHatSurrounder extends ObjMoveableTypeSurronder
{
/**
* 建立上蓋包圍工具
*
* @param 調整工具
* 使用此包圍工具的調整工具,並使用其自身合併相關函式
*/
public UpHatSurrounder(MergePieceAdjuster 調整工具)
{
super(調整工具);
支援包圍部件.add("冖");
支援包圍部件.add("");//「冖」中研院造字
支援包圍部件.add("宀");
// 支援包圍部件.add("學");//TODO
}
@Override
public void 組合(PieceMovableTypeTzu 物件活字)
{
/** 上蓋和下部拼合時的調整模組 */
UpHatAsmmod 模組 = new UpHatAsmmod(調整工具);
/** 將上下兩部件拼合的工具 */
BisearchPasteAssembler 貼合工具 = new BisearchPasteAssembler();
貼合工具.執行(模組, 物件活字.取得活字物件());
| SeprateMovabletype[] 調整結果 = 模組.取得調整後活字物件(); |
sih4sing5hong5/han3_ji7_tsoo1_kian3 | src/main/java/cc/movabletype/ChineseCharacterMovableTypeWen.java | // Path: src/main/java/cc/layouttools/ChineseCharacterTypeAdjuster.java
// public interface ChineseCharacterTypeAdjuster
// {
// /**
// * 調整獨體活字
// *
// * @param chineseCharacterMovableTypeWen
// * 欲調整之獨體活字
// */
// public void adjustWen(
// ChineseCharacterMovableTypeWen chineseCharacterMovableTypeWen);
//
// /**
// * 調整合體活字
// *
// * @param chineseCharacterMovableTypeTzu
// * 欲調整之合體活字
// */
// public void adjustTzu(
// ChineseCharacterMovableTypeTzu chineseCharacterMovableTypeTzu);
// }
//
// Path: src/main/java/cc/printtools/ChineseCharacterTypePrinter.java
// public interface ChineseCharacterTypePrinter
// {
// /**
// * 列印獨體活字
// *
// * @param chineseCharacterMovableTypeWen
// * 獨體活字
// */
// void printWen(ChineseCharacterMovableTypeWen chineseCharacterMovableTypeWen);
//
// /**
// * 列印合體活字
// *
// * @param chineseCharacterMovableTypeTzu
// * 合體活字
// */
// void printTzu(ChineseCharacterMovableTypeTzu chineseCharacterMovableTypeTzu);
// }
//
// Path: src/main/java/idsrend/charcomponent/NonFinalCharComponent.java
// public class NonFinalCharComponent extends CharComponent
// {
// /**
// * 部件的Unicode編碼
// */
// private final int codePoint;
//
// /**
// * 初使化一个新的文部件。
// *
// * @param 面頂彼个字部件
// * 樹狀結構面頂彼个字部件
// * @param 控制碼
// * 這个文部件字的統一碼控制碼
// */
// /**
// * 建立一個文部件
// *
// * @param parent
// * 上一層的部件結構。若上層為樹狀的樹根,傳入null
// * @param codePoint
// * 部件的Unicode編碼
// */
// public NonFinalCharComponent(int codePoint)
// {
// this.codePoint = codePoint;
// }
//
// public NonFinalCharComponent(String 組字式)
// {
// this(組字式.codePointAt(0));
// }
//
// @Override
// public boolean 是文部件()
// {
// return true;
// }
//
// @Override
// public boolean 是字部件()
// {
// return false;
// }
//
// @Override
// public String 樹狀結構組字式()
// {
// return 部件組字式();
// }
//
// /**
// * 取得部件Unicode編碼
// *
// * @return 部件Unicode編碼
// */
// public int Unicode編號()
// {
// return codePoint;
// }
//
// @Override
// public ChineseCharCompositeMoveabletype typeset(
// ChineseCharacterTypeSetter chineseCharacterTypeSetter,
// ChineseCharacterMovableTypeTzu parent)
// {
// return chineseCharacterTypeSetter.setWen(parent, this);
// }
// }
| import cc.layouttools.ChineseCharacterTypeAdjuster;
import cc.printtools.ChineseCharacterTypePrinter;
import idsrend.charcomponent.NonFinalCharComponent; | package cc.movabletype;
/**
* 漢字活字樹狀結構的葉子。「獨體為文,合體為字」,樹狀結構中的葉子為文,其他上層節點為字。
* <code>ChineseCharacterMovableTypeWen</code> 記錄活字的排版資訊。
*
* @author Ihc
*/
public class ChineseCharacterMovableTypeWen extends ChineseCharacterMovableType
{
/**
* 以<code>ChineseCharacter</code>部件結構建立文活字結構
*
* @param parent
* 上一層的活字結構。若上層為樹狀的樹根,傳入null
* @param chineseCharacterWen
* 文部件結構
*/
public ChineseCharacterMovableTypeWen(
ChineseCharacterMovableTypeTzu parent, | // Path: src/main/java/cc/layouttools/ChineseCharacterTypeAdjuster.java
// public interface ChineseCharacterTypeAdjuster
// {
// /**
// * 調整獨體活字
// *
// * @param chineseCharacterMovableTypeWen
// * 欲調整之獨體活字
// */
// public void adjustWen(
// ChineseCharacterMovableTypeWen chineseCharacterMovableTypeWen);
//
// /**
// * 調整合體活字
// *
// * @param chineseCharacterMovableTypeTzu
// * 欲調整之合體活字
// */
// public void adjustTzu(
// ChineseCharacterMovableTypeTzu chineseCharacterMovableTypeTzu);
// }
//
// Path: src/main/java/cc/printtools/ChineseCharacterTypePrinter.java
// public interface ChineseCharacterTypePrinter
// {
// /**
// * 列印獨體活字
// *
// * @param chineseCharacterMovableTypeWen
// * 獨體活字
// */
// void printWen(ChineseCharacterMovableTypeWen chineseCharacterMovableTypeWen);
//
// /**
// * 列印合體活字
// *
// * @param chineseCharacterMovableTypeTzu
// * 合體活字
// */
// void printTzu(ChineseCharacterMovableTypeTzu chineseCharacterMovableTypeTzu);
// }
//
// Path: src/main/java/idsrend/charcomponent/NonFinalCharComponent.java
// public class NonFinalCharComponent extends CharComponent
// {
// /**
// * 部件的Unicode編碼
// */
// private final int codePoint;
//
// /**
// * 初使化一个新的文部件。
// *
// * @param 面頂彼个字部件
// * 樹狀結構面頂彼个字部件
// * @param 控制碼
// * 這个文部件字的統一碼控制碼
// */
// /**
// * 建立一個文部件
// *
// * @param parent
// * 上一層的部件結構。若上層為樹狀的樹根,傳入null
// * @param codePoint
// * 部件的Unicode編碼
// */
// public NonFinalCharComponent(int codePoint)
// {
// this.codePoint = codePoint;
// }
//
// public NonFinalCharComponent(String 組字式)
// {
// this(組字式.codePointAt(0));
// }
//
// @Override
// public boolean 是文部件()
// {
// return true;
// }
//
// @Override
// public boolean 是字部件()
// {
// return false;
// }
//
// @Override
// public String 樹狀結構組字式()
// {
// return 部件組字式();
// }
//
// /**
// * 取得部件Unicode編碼
// *
// * @return 部件Unicode編碼
// */
// public int Unicode編號()
// {
// return codePoint;
// }
//
// @Override
// public ChineseCharCompositeMoveabletype typeset(
// ChineseCharacterTypeSetter chineseCharacterTypeSetter,
// ChineseCharacterMovableTypeTzu parent)
// {
// return chineseCharacterTypeSetter.setWen(parent, this);
// }
// }
// Path: src/main/java/cc/movabletype/ChineseCharacterMovableTypeWen.java
import cc.layouttools.ChineseCharacterTypeAdjuster;
import cc.printtools.ChineseCharacterTypePrinter;
import idsrend.charcomponent.NonFinalCharComponent;
package cc.movabletype;
/**
* 漢字活字樹狀結構的葉子。「獨體為文,合體為字」,樹狀結構中的葉子為文,其他上層節點為字。
* <code>ChineseCharacterMovableTypeWen</code> 記錄活字的排版資訊。
*
* @author Ihc
*/
public class ChineseCharacterMovableTypeWen extends ChineseCharacterMovableType
{
/**
* 以<code>ChineseCharacter</code>部件結構建立文活字結構
*
* @param parent
* 上一層的活字結構。若上層為樹狀的樹根,傳入null
* @param chineseCharacterWen
* 文部件結構
*/
public ChineseCharacterMovableTypeWen(
ChineseCharacterMovableTypeTzu parent, | NonFinalCharComponent chineseCharacterWen) |
sih4sing5hong5/han3_ji7_tsoo1_kian3 | src/main/java/cc/movabletype/ChineseCharacterMovableTypeWen.java | // Path: src/main/java/cc/layouttools/ChineseCharacterTypeAdjuster.java
// public interface ChineseCharacterTypeAdjuster
// {
// /**
// * 調整獨體活字
// *
// * @param chineseCharacterMovableTypeWen
// * 欲調整之獨體活字
// */
// public void adjustWen(
// ChineseCharacterMovableTypeWen chineseCharacterMovableTypeWen);
//
// /**
// * 調整合體活字
// *
// * @param chineseCharacterMovableTypeTzu
// * 欲調整之合體活字
// */
// public void adjustTzu(
// ChineseCharacterMovableTypeTzu chineseCharacterMovableTypeTzu);
// }
//
// Path: src/main/java/cc/printtools/ChineseCharacterTypePrinter.java
// public interface ChineseCharacterTypePrinter
// {
// /**
// * 列印獨體活字
// *
// * @param chineseCharacterMovableTypeWen
// * 獨體活字
// */
// void printWen(ChineseCharacterMovableTypeWen chineseCharacterMovableTypeWen);
//
// /**
// * 列印合體活字
// *
// * @param chineseCharacterMovableTypeTzu
// * 合體活字
// */
// void printTzu(ChineseCharacterMovableTypeTzu chineseCharacterMovableTypeTzu);
// }
//
// Path: src/main/java/idsrend/charcomponent/NonFinalCharComponent.java
// public class NonFinalCharComponent extends CharComponent
// {
// /**
// * 部件的Unicode編碼
// */
// private final int codePoint;
//
// /**
// * 初使化一个新的文部件。
// *
// * @param 面頂彼个字部件
// * 樹狀結構面頂彼个字部件
// * @param 控制碼
// * 這个文部件字的統一碼控制碼
// */
// /**
// * 建立一個文部件
// *
// * @param parent
// * 上一層的部件結構。若上層為樹狀的樹根,傳入null
// * @param codePoint
// * 部件的Unicode編碼
// */
// public NonFinalCharComponent(int codePoint)
// {
// this.codePoint = codePoint;
// }
//
// public NonFinalCharComponent(String 組字式)
// {
// this(組字式.codePointAt(0));
// }
//
// @Override
// public boolean 是文部件()
// {
// return true;
// }
//
// @Override
// public boolean 是字部件()
// {
// return false;
// }
//
// @Override
// public String 樹狀結構組字式()
// {
// return 部件組字式();
// }
//
// /**
// * 取得部件Unicode編碼
// *
// * @return 部件Unicode編碼
// */
// public int Unicode編號()
// {
// return codePoint;
// }
//
// @Override
// public ChineseCharCompositeMoveabletype typeset(
// ChineseCharacterTypeSetter chineseCharacterTypeSetter,
// ChineseCharacterMovableTypeTzu parent)
// {
// return chineseCharacterTypeSetter.setWen(parent, this);
// }
// }
| import cc.layouttools.ChineseCharacterTypeAdjuster;
import cc.printtools.ChineseCharacterTypePrinter;
import idsrend.charcomponent.NonFinalCharComponent; | package cc.movabletype;
/**
* 漢字活字樹狀結構的葉子。「獨體為文,合體為字」,樹狀結構中的葉子為文,其他上層節點為字。
* <code>ChineseCharacterMovableTypeWen</code> 記錄活字的排版資訊。
*
* @author Ihc
*/
public class ChineseCharacterMovableTypeWen extends ChineseCharacterMovableType
{
/**
* 以<code>ChineseCharacter</code>部件結構建立文活字結構
*
* @param parent
* 上一層的活字結構。若上層為樹狀的樹根,傳入null
* @param chineseCharacterWen
* 文部件結構
*/
public ChineseCharacterMovableTypeWen(
ChineseCharacterMovableTypeTzu parent,
NonFinalCharComponent chineseCharacterWen)
{
super(parent, chineseCharacterWen);
}
@Override | // Path: src/main/java/cc/layouttools/ChineseCharacterTypeAdjuster.java
// public interface ChineseCharacterTypeAdjuster
// {
// /**
// * 調整獨體活字
// *
// * @param chineseCharacterMovableTypeWen
// * 欲調整之獨體活字
// */
// public void adjustWen(
// ChineseCharacterMovableTypeWen chineseCharacterMovableTypeWen);
//
// /**
// * 調整合體活字
// *
// * @param chineseCharacterMovableTypeTzu
// * 欲調整之合體活字
// */
// public void adjustTzu(
// ChineseCharacterMovableTypeTzu chineseCharacterMovableTypeTzu);
// }
//
// Path: src/main/java/cc/printtools/ChineseCharacterTypePrinter.java
// public interface ChineseCharacterTypePrinter
// {
// /**
// * 列印獨體活字
// *
// * @param chineseCharacterMovableTypeWen
// * 獨體活字
// */
// void printWen(ChineseCharacterMovableTypeWen chineseCharacterMovableTypeWen);
//
// /**
// * 列印合體活字
// *
// * @param chineseCharacterMovableTypeTzu
// * 合體活字
// */
// void printTzu(ChineseCharacterMovableTypeTzu chineseCharacterMovableTypeTzu);
// }
//
// Path: src/main/java/idsrend/charcomponent/NonFinalCharComponent.java
// public class NonFinalCharComponent extends CharComponent
// {
// /**
// * 部件的Unicode編碼
// */
// private final int codePoint;
//
// /**
// * 初使化一个新的文部件。
// *
// * @param 面頂彼个字部件
// * 樹狀結構面頂彼个字部件
// * @param 控制碼
// * 這个文部件字的統一碼控制碼
// */
// /**
// * 建立一個文部件
// *
// * @param parent
// * 上一層的部件結構。若上層為樹狀的樹根,傳入null
// * @param codePoint
// * 部件的Unicode編碼
// */
// public NonFinalCharComponent(int codePoint)
// {
// this.codePoint = codePoint;
// }
//
// public NonFinalCharComponent(String 組字式)
// {
// this(組字式.codePointAt(0));
// }
//
// @Override
// public boolean 是文部件()
// {
// return true;
// }
//
// @Override
// public boolean 是字部件()
// {
// return false;
// }
//
// @Override
// public String 樹狀結構組字式()
// {
// return 部件組字式();
// }
//
// /**
// * 取得部件Unicode編碼
// *
// * @return 部件Unicode編碼
// */
// public int Unicode編號()
// {
// return codePoint;
// }
//
// @Override
// public ChineseCharCompositeMoveabletype typeset(
// ChineseCharacterTypeSetter chineseCharacterTypeSetter,
// ChineseCharacterMovableTypeTzu parent)
// {
// return chineseCharacterTypeSetter.setWen(parent, this);
// }
// }
// Path: src/main/java/cc/movabletype/ChineseCharacterMovableTypeWen.java
import cc.layouttools.ChineseCharacterTypeAdjuster;
import cc.printtools.ChineseCharacterTypePrinter;
import idsrend.charcomponent.NonFinalCharComponent;
package cc.movabletype;
/**
* 漢字活字樹狀結構的葉子。「獨體為文,合體為字」,樹狀結構中的葉子為文,其他上層節點為字。
* <code>ChineseCharacterMovableTypeWen</code> 記錄活字的排版資訊。
*
* @author Ihc
*/
public class ChineseCharacterMovableTypeWen extends ChineseCharacterMovableType
{
/**
* 以<code>ChineseCharacter</code>部件結構建立文活字結構
*
* @param parent
* 上一層的活字結構。若上層為樹狀的樹根,傳入null
* @param chineseCharacterWen
* 文部件結構
*/
public ChineseCharacterMovableTypeWen(
ChineseCharacterMovableTypeTzu parent,
NonFinalCharComponent chineseCharacterWen)
{
super(parent, chineseCharacterWen);
}
@Override | public void adjust(ChineseCharacterTypeAdjuster adjuster) |
sih4sing5hong5/han3_ji7_tsoo1_kian3 | src/main/java/cc/movabletype/ChineseCharacterMovableTypeWen.java | // Path: src/main/java/cc/layouttools/ChineseCharacterTypeAdjuster.java
// public interface ChineseCharacterTypeAdjuster
// {
// /**
// * 調整獨體活字
// *
// * @param chineseCharacterMovableTypeWen
// * 欲調整之獨體活字
// */
// public void adjustWen(
// ChineseCharacterMovableTypeWen chineseCharacterMovableTypeWen);
//
// /**
// * 調整合體活字
// *
// * @param chineseCharacterMovableTypeTzu
// * 欲調整之合體活字
// */
// public void adjustTzu(
// ChineseCharacterMovableTypeTzu chineseCharacterMovableTypeTzu);
// }
//
// Path: src/main/java/cc/printtools/ChineseCharacterTypePrinter.java
// public interface ChineseCharacterTypePrinter
// {
// /**
// * 列印獨體活字
// *
// * @param chineseCharacterMovableTypeWen
// * 獨體活字
// */
// void printWen(ChineseCharacterMovableTypeWen chineseCharacterMovableTypeWen);
//
// /**
// * 列印合體活字
// *
// * @param chineseCharacterMovableTypeTzu
// * 合體活字
// */
// void printTzu(ChineseCharacterMovableTypeTzu chineseCharacterMovableTypeTzu);
// }
//
// Path: src/main/java/idsrend/charcomponent/NonFinalCharComponent.java
// public class NonFinalCharComponent extends CharComponent
// {
// /**
// * 部件的Unicode編碼
// */
// private final int codePoint;
//
// /**
// * 初使化一个新的文部件。
// *
// * @param 面頂彼个字部件
// * 樹狀結構面頂彼个字部件
// * @param 控制碼
// * 這个文部件字的統一碼控制碼
// */
// /**
// * 建立一個文部件
// *
// * @param parent
// * 上一層的部件結構。若上層為樹狀的樹根,傳入null
// * @param codePoint
// * 部件的Unicode編碼
// */
// public NonFinalCharComponent(int codePoint)
// {
// this.codePoint = codePoint;
// }
//
// public NonFinalCharComponent(String 組字式)
// {
// this(組字式.codePointAt(0));
// }
//
// @Override
// public boolean 是文部件()
// {
// return true;
// }
//
// @Override
// public boolean 是字部件()
// {
// return false;
// }
//
// @Override
// public String 樹狀結構組字式()
// {
// return 部件組字式();
// }
//
// /**
// * 取得部件Unicode編碼
// *
// * @return 部件Unicode編碼
// */
// public int Unicode編號()
// {
// return codePoint;
// }
//
// @Override
// public ChineseCharCompositeMoveabletype typeset(
// ChineseCharacterTypeSetter chineseCharacterTypeSetter,
// ChineseCharacterMovableTypeTzu parent)
// {
// return chineseCharacterTypeSetter.setWen(parent, this);
// }
// }
| import cc.layouttools.ChineseCharacterTypeAdjuster;
import cc.printtools.ChineseCharacterTypePrinter;
import idsrend.charcomponent.NonFinalCharComponent; | package cc.movabletype;
/**
* 漢字活字樹狀結構的葉子。「獨體為文,合體為字」,樹狀結構中的葉子為文,其他上層節點為字。
* <code>ChineseCharacterMovableTypeWen</code> 記錄活字的排版資訊。
*
* @author Ihc
*/
public class ChineseCharacterMovableTypeWen extends ChineseCharacterMovableType
{
/**
* 以<code>ChineseCharacter</code>部件結構建立文活字結構
*
* @param parent
* 上一層的活字結構。若上層為樹狀的樹根,傳入null
* @param chineseCharacterWen
* 文部件結構
*/
public ChineseCharacterMovableTypeWen(
ChineseCharacterMovableTypeTzu parent,
NonFinalCharComponent chineseCharacterWen)
{
super(parent, chineseCharacterWen);
}
@Override
public void adjust(ChineseCharacterTypeAdjuster adjuster)
{
adjuster.adjustWen(this);
return;
}
@Override | // Path: src/main/java/cc/layouttools/ChineseCharacterTypeAdjuster.java
// public interface ChineseCharacterTypeAdjuster
// {
// /**
// * 調整獨體活字
// *
// * @param chineseCharacterMovableTypeWen
// * 欲調整之獨體活字
// */
// public void adjustWen(
// ChineseCharacterMovableTypeWen chineseCharacterMovableTypeWen);
//
// /**
// * 調整合體活字
// *
// * @param chineseCharacterMovableTypeTzu
// * 欲調整之合體活字
// */
// public void adjustTzu(
// ChineseCharacterMovableTypeTzu chineseCharacterMovableTypeTzu);
// }
//
// Path: src/main/java/cc/printtools/ChineseCharacterTypePrinter.java
// public interface ChineseCharacterTypePrinter
// {
// /**
// * 列印獨體活字
// *
// * @param chineseCharacterMovableTypeWen
// * 獨體活字
// */
// void printWen(ChineseCharacterMovableTypeWen chineseCharacterMovableTypeWen);
//
// /**
// * 列印合體活字
// *
// * @param chineseCharacterMovableTypeTzu
// * 合體活字
// */
// void printTzu(ChineseCharacterMovableTypeTzu chineseCharacterMovableTypeTzu);
// }
//
// Path: src/main/java/idsrend/charcomponent/NonFinalCharComponent.java
// public class NonFinalCharComponent extends CharComponent
// {
// /**
// * 部件的Unicode編碼
// */
// private final int codePoint;
//
// /**
// * 初使化一个新的文部件。
// *
// * @param 面頂彼个字部件
// * 樹狀結構面頂彼个字部件
// * @param 控制碼
// * 這个文部件字的統一碼控制碼
// */
// /**
// * 建立一個文部件
// *
// * @param parent
// * 上一層的部件結構。若上層為樹狀的樹根,傳入null
// * @param codePoint
// * 部件的Unicode編碼
// */
// public NonFinalCharComponent(int codePoint)
// {
// this.codePoint = codePoint;
// }
//
// public NonFinalCharComponent(String 組字式)
// {
// this(組字式.codePointAt(0));
// }
//
// @Override
// public boolean 是文部件()
// {
// return true;
// }
//
// @Override
// public boolean 是字部件()
// {
// return false;
// }
//
// @Override
// public String 樹狀結構組字式()
// {
// return 部件組字式();
// }
//
// /**
// * 取得部件Unicode編碼
// *
// * @return 部件Unicode編碼
// */
// public int Unicode編號()
// {
// return codePoint;
// }
//
// @Override
// public ChineseCharCompositeMoveabletype typeset(
// ChineseCharacterTypeSetter chineseCharacterTypeSetter,
// ChineseCharacterMovableTypeTzu parent)
// {
// return chineseCharacterTypeSetter.setWen(parent, this);
// }
// }
// Path: src/main/java/cc/movabletype/ChineseCharacterMovableTypeWen.java
import cc.layouttools.ChineseCharacterTypeAdjuster;
import cc.printtools.ChineseCharacterTypePrinter;
import idsrend.charcomponent.NonFinalCharComponent;
package cc.movabletype;
/**
* 漢字活字樹狀結構的葉子。「獨體為文,合體為字」,樹狀結構中的葉子為文,其他上層節點為字。
* <code>ChineseCharacterMovableTypeWen</code> 記錄活字的排版資訊。
*
* @author Ihc
*/
public class ChineseCharacterMovableTypeWen extends ChineseCharacterMovableType
{
/**
* 以<code>ChineseCharacter</code>部件結構建立文活字結構
*
* @param parent
* 上一層的活字結構。若上層為樹狀的樹根,傳入null
* @param chineseCharacterWen
* 文部件結構
*/
public ChineseCharacterMovableTypeWen(
ChineseCharacterMovableTypeTzu parent,
NonFinalCharComponent chineseCharacterWen)
{
super(parent, chineseCharacterWen);
}
@Override
public void adjust(ChineseCharacterTypeAdjuster adjuster)
{
adjuster.adjustWen(this);
return;
}
@Override | public void print(ChineseCharacterTypePrinter printer) |
sih4sing5hong5/han3_ji7_tsoo1_kian3 | src/main/java/cc/layouttools/FlatSurronder.java | // Path: src/main/java/cc/movabletype/SeprateMovabletype.java
// public class SeprateMovabletype
// {
// /** 目前字體大細,所在 */
// private Vector<PlaneGeometry> 字;
// /** 為著保留字體闊,若維護矩陣顛倒愛去顧平移 */
// private Vector<PlaneGeometry> 原本字體;
// /** 加粗莫合併的外殼 */
// private Vector<PlaneGeometry> 字外殼;
// /** 這馬的範圍,是為著閃避「一字問題」 */
// private Rectangle2D.Double 這馬;
// /** 目標範圍,上尾印的時陣愛看印偌大 */
// private Rectangle2D.Double 目標;
//
// public SeprateMovabletype()
// {
// 字 = new Vector<PlaneGeometry>();
// 原本字體 = new Vector<PlaneGeometry>();
// 字外殼 = null;
// 這馬 = new Rectangle.Double();
// 目標 = new Rectangle.Double();
// }
//
// public SeprateMovabletype(PlaneGeometry 幾何)
// {
// this();
// 字.add(幾何);
// 原本字體.add(幾何);
// 這馬字範圍();
// }
| import java.util.Vector;
import cc.movabletype.SeprateMovabletype; | 包圍工具列.add(new BisearchPasteSpacingTool(4.0)); // TODO 人工參數
包圍工具列.add(new BisearchPasteAssembler());
平推工具列 = new Vector<BisearchPasteAssembler>();
平推工具列.add(new BisearchPasteSpacingTool(4.0)); // TODO 人工參數
平推工具列.add(new BisearchPasteSpacingTool(0.5));
平推模組列 = new Vector<PasteFlatpushSticking>();
if (先上下後左右)
{
平推模組列.add(new PasteUpwardSticking(調整工具));
平推模組列.add(new PasteDownwardSticking(調整工具));
平推模組列.add(new PasteLeftwardSticking(調整工具));
平推模組列.add(new PasteRightwardSticking(調整工具));
}
else
{
平推模組列.add(new PasteLeftwardSticking(調整工具));
平推模組列.add(new PasteRightwardSticking(調整工具));
平推模組列.add(new PasteUpwardSticking(調整工具));
平推模組列.add(new PasteDownwardSticking(調整工具));
}
}
/**
* 將活字物件的調整後,並回傳。
*
* @param 活字物件
* 要調整的物件
* @return 活字物件調整後結果
*/ | // Path: src/main/java/cc/movabletype/SeprateMovabletype.java
// public class SeprateMovabletype
// {
// /** 目前字體大細,所在 */
// private Vector<PlaneGeometry> 字;
// /** 為著保留字體闊,若維護矩陣顛倒愛去顧平移 */
// private Vector<PlaneGeometry> 原本字體;
// /** 加粗莫合併的外殼 */
// private Vector<PlaneGeometry> 字外殼;
// /** 這馬的範圍,是為著閃避「一字問題」 */
// private Rectangle2D.Double 這馬;
// /** 目標範圍,上尾印的時陣愛看印偌大 */
// private Rectangle2D.Double 目標;
//
// public SeprateMovabletype()
// {
// 字 = new Vector<PlaneGeometry>();
// 原本字體 = new Vector<PlaneGeometry>();
// 字外殼 = null;
// 這馬 = new Rectangle.Double();
// 目標 = new Rectangle.Double();
// }
//
// public SeprateMovabletype(PlaneGeometry 幾何)
// {
// this();
// 字.add(幾何);
// 原本字體.add(幾何);
// 這馬字範圍();
// }
// Path: src/main/java/cc/layouttools/FlatSurronder.java
import java.util.Vector;
import cc.movabletype.SeprateMovabletype;
包圍工具列.add(new BisearchPasteSpacingTool(4.0)); // TODO 人工參數
包圍工具列.add(new BisearchPasteAssembler());
平推工具列 = new Vector<BisearchPasteAssembler>();
平推工具列.add(new BisearchPasteSpacingTool(4.0)); // TODO 人工參數
平推工具列.add(new BisearchPasteSpacingTool(0.5));
平推模組列 = new Vector<PasteFlatpushSticking>();
if (先上下後左右)
{
平推模組列.add(new PasteUpwardSticking(調整工具));
平推模組列.add(new PasteDownwardSticking(調整工具));
平推模組列.add(new PasteLeftwardSticking(調整工具));
平推模組列.add(new PasteRightwardSticking(調整工具));
}
else
{
平推模組列.add(new PasteLeftwardSticking(調整工具));
平推模組列.add(new PasteRightwardSticking(調整工具));
平推模組列.add(new PasteUpwardSticking(調整工具));
平推模組列.add(new PasteDownwardSticking(調整工具));
}
}
/**
* 將活字物件的調整後,並回傳。
*
* @param 活字物件
* 要調整的物件
* @return 活字物件調整後結果
*/ | public SeprateMovabletype[] 產生調整後活字(SeprateMovabletype[] 活字物件) |
sih4sing5hong5/han3_ji7_tsoo1_kian3 | src/main/java/cc/movabletype/ChineseCharacterMovableTypeTzu.java | // Path: src/main/java/cc/layouttools/ChineseCharacterTypeAdjuster.java
// public interface ChineseCharacterTypeAdjuster
// {
// /**
// * 調整獨體活字
// *
// * @param chineseCharacterMovableTypeWen
// * 欲調整之獨體活字
// */
// public void adjustWen(
// ChineseCharacterMovableTypeWen chineseCharacterMovableTypeWen);
//
// /**
// * 調整合體活字
// *
// * @param chineseCharacterMovableTypeTzu
// * 欲調整之合體活字
// */
// public void adjustTzu(
// ChineseCharacterMovableTypeTzu chineseCharacterMovableTypeTzu);
// }
//
// Path: src/main/java/cc/printtools/ChineseCharacterTypePrinter.java
// public interface ChineseCharacterTypePrinter
// {
// /**
// * 列印獨體活字
// *
// * @param chineseCharacterMovableTypeWen
// * 獨體活字
// */
// void printWen(ChineseCharacterMovableTypeWen chineseCharacterMovableTypeWen);
//
// /**
// * 列印合體活字
// *
// * @param chineseCharacterMovableTypeTzu
// * 合體活字
// */
// void printTzu(ChineseCharacterMovableTypeTzu chineseCharacterMovableTypeTzu);
// }
//
// Path: src/main/java/idsrend/charcomponent/FinalCharComponent.java
// public class FinalCharComponent extends CharComponent
// {
// /**
// * 部件的組合方式
// */
// private final CompositionMethods type;
// /**
// * 底下的各個部件
// */
// private final CharComponent[] children;
//
// @Override
// public boolean 是文部件()
// {
// return false;
// }
//
// @Override
// public boolean 是字部件()
// {
// return true;
// }
//
// /**
// * 取得部件的組合方式
// *
// * @return 部件的組合方式
// */
// public CompositionMethods CompositionMethods()
// {
// return type;
// }
//
// /**
// * 取得底下的各個部件
// *
// * @return 底下的各個部件
// */
// public CharComponent[] 底下元素()
// {
// return children;
// }
| import cc.layouttools.ChineseCharacterTypeAdjuster;
import cc.printtools.ChineseCharacterTypePrinter;
import idsrend.charcomponent.FinalCharComponent; | package cc.movabletype;
/**
* 漢字活字樹狀結構的上層節點。「獨體為文,合體為字」,樹狀結構中的葉子為文,其他上層節點為字。
* <code>ChineseCharacterMovableTypeTzu</code>記錄底下活字的排版資訊。
*
* @author Ihc
*/
public class ChineseCharacterMovableTypeTzu extends ChineseCharacterMovableType
{
/**
* 底下的各個活字
*/
protected ChineseCharCompositeMoveabletype[] children;
/**
* 以<code>ChineseCharacter</code>部件結構建立字活字結構
*
* @param parent
* 上一層的活字結構。若上層為樹狀的樹根,傳入null
* @param chineseCharacterTzu
* 字部件結構
*/
public ChineseCharacterMovableTypeTzu(
ChineseCharacterMovableTypeTzu parent, | // Path: src/main/java/cc/layouttools/ChineseCharacterTypeAdjuster.java
// public interface ChineseCharacterTypeAdjuster
// {
// /**
// * 調整獨體活字
// *
// * @param chineseCharacterMovableTypeWen
// * 欲調整之獨體活字
// */
// public void adjustWen(
// ChineseCharacterMovableTypeWen chineseCharacterMovableTypeWen);
//
// /**
// * 調整合體活字
// *
// * @param chineseCharacterMovableTypeTzu
// * 欲調整之合體活字
// */
// public void adjustTzu(
// ChineseCharacterMovableTypeTzu chineseCharacterMovableTypeTzu);
// }
//
// Path: src/main/java/cc/printtools/ChineseCharacterTypePrinter.java
// public interface ChineseCharacterTypePrinter
// {
// /**
// * 列印獨體活字
// *
// * @param chineseCharacterMovableTypeWen
// * 獨體活字
// */
// void printWen(ChineseCharacterMovableTypeWen chineseCharacterMovableTypeWen);
//
// /**
// * 列印合體活字
// *
// * @param chineseCharacterMovableTypeTzu
// * 合體活字
// */
// void printTzu(ChineseCharacterMovableTypeTzu chineseCharacterMovableTypeTzu);
// }
//
// Path: src/main/java/idsrend/charcomponent/FinalCharComponent.java
// public class FinalCharComponent extends CharComponent
// {
// /**
// * 部件的組合方式
// */
// private final CompositionMethods type;
// /**
// * 底下的各個部件
// */
// private final CharComponent[] children;
//
// @Override
// public boolean 是文部件()
// {
// return false;
// }
//
// @Override
// public boolean 是字部件()
// {
// return true;
// }
//
// /**
// * 取得部件的組合方式
// *
// * @return 部件的組合方式
// */
// public CompositionMethods CompositionMethods()
// {
// return type;
// }
//
// /**
// * 取得底下的各個部件
// *
// * @return 底下的各個部件
// */
// public CharComponent[] 底下元素()
// {
// return children;
// }
// Path: src/main/java/cc/movabletype/ChineseCharacterMovableTypeTzu.java
import cc.layouttools.ChineseCharacterTypeAdjuster;
import cc.printtools.ChineseCharacterTypePrinter;
import idsrend.charcomponent.FinalCharComponent;
package cc.movabletype;
/**
* 漢字活字樹狀結構的上層節點。「獨體為文,合體為字」,樹狀結構中的葉子為文,其他上層節點為字。
* <code>ChineseCharacterMovableTypeTzu</code>記錄底下活字的排版資訊。
*
* @author Ihc
*/
public class ChineseCharacterMovableTypeTzu extends ChineseCharacterMovableType
{
/**
* 底下的各個活字
*/
protected ChineseCharCompositeMoveabletype[] children;
/**
* 以<code>ChineseCharacter</code>部件結構建立字活字結構
*
* @param parent
* 上一層的活字結構。若上層為樹狀的樹根,傳入null
* @param chineseCharacterTzu
* 字部件結構
*/
public ChineseCharacterMovableTypeTzu(
ChineseCharacterMovableTypeTzu parent, | FinalCharComponent chineseCharacterTzu) |
sih4sing5hong5/han3_ji7_tsoo1_kian3 | src/main/java/cc/movabletype/ChineseCharacterMovableTypeTzu.java | // Path: src/main/java/cc/layouttools/ChineseCharacterTypeAdjuster.java
// public interface ChineseCharacterTypeAdjuster
// {
// /**
// * 調整獨體活字
// *
// * @param chineseCharacterMovableTypeWen
// * 欲調整之獨體活字
// */
// public void adjustWen(
// ChineseCharacterMovableTypeWen chineseCharacterMovableTypeWen);
//
// /**
// * 調整合體活字
// *
// * @param chineseCharacterMovableTypeTzu
// * 欲調整之合體活字
// */
// public void adjustTzu(
// ChineseCharacterMovableTypeTzu chineseCharacterMovableTypeTzu);
// }
//
// Path: src/main/java/cc/printtools/ChineseCharacterTypePrinter.java
// public interface ChineseCharacterTypePrinter
// {
// /**
// * 列印獨體活字
// *
// * @param chineseCharacterMovableTypeWen
// * 獨體活字
// */
// void printWen(ChineseCharacterMovableTypeWen chineseCharacterMovableTypeWen);
//
// /**
// * 列印合體活字
// *
// * @param chineseCharacterMovableTypeTzu
// * 合體活字
// */
// void printTzu(ChineseCharacterMovableTypeTzu chineseCharacterMovableTypeTzu);
// }
//
// Path: src/main/java/idsrend/charcomponent/FinalCharComponent.java
// public class FinalCharComponent extends CharComponent
// {
// /**
// * 部件的組合方式
// */
// private final CompositionMethods type;
// /**
// * 底下的各個部件
// */
// private final CharComponent[] children;
//
// @Override
// public boolean 是文部件()
// {
// return false;
// }
//
// @Override
// public boolean 是字部件()
// {
// return true;
// }
//
// /**
// * 取得部件的組合方式
// *
// * @return 部件的組合方式
// */
// public CompositionMethods CompositionMethods()
// {
// return type;
// }
//
// /**
// * 取得底下的各個部件
// *
// * @return 底下的各個部件
// */
// public CharComponent[] 底下元素()
// {
// return children;
// }
| import cc.layouttools.ChineseCharacterTypeAdjuster;
import cc.printtools.ChineseCharacterTypePrinter;
import idsrend.charcomponent.FinalCharComponent; | package cc.movabletype;
/**
* 漢字活字樹狀結構的上層節點。「獨體為文,合體為字」,樹狀結構中的葉子為文,其他上層節點為字。
* <code>ChineseCharacterMovableTypeTzu</code>記錄底下活字的排版資訊。
*
* @author Ihc
*/
public class ChineseCharacterMovableTypeTzu extends ChineseCharacterMovableType
{
/**
* 底下的各個活字
*/
protected ChineseCharCompositeMoveabletype[] children;
/**
* 以<code>ChineseCharacter</code>部件結構建立字活字結構
*
* @param parent
* 上一層的活字結構。若上層為樹狀的樹根,傳入null
* @param chineseCharacterTzu
* 字部件結構
*/
public ChineseCharacterMovableTypeTzu(
ChineseCharacterMovableTypeTzu parent,
FinalCharComponent chineseCharacterTzu)
{
super(parent, chineseCharacterTzu);
int childrenSize = chineseCharacterTzu.CompositionMethods().getNumberOfChildren();
this.children = new ChineseCharacterMovableType[childrenSize];
}
@Override | // Path: src/main/java/cc/layouttools/ChineseCharacterTypeAdjuster.java
// public interface ChineseCharacterTypeAdjuster
// {
// /**
// * 調整獨體活字
// *
// * @param chineseCharacterMovableTypeWen
// * 欲調整之獨體活字
// */
// public void adjustWen(
// ChineseCharacterMovableTypeWen chineseCharacterMovableTypeWen);
//
// /**
// * 調整合體活字
// *
// * @param chineseCharacterMovableTypeTzu
// * 欲調整之合體活字
// */
// public void adjustTzu(
// ChineseCharacterMovableTypeTzu chineseCharacterMovableTypeTzu);
// }
//
// Path: src/main/java/cc/printtools/ChineseCharacterTypePrinter.java
// public interface ChineseCharacterTypePrinter
// {
// /**
// * 列印獨體活字
// *
// * @param chineseCharacterMovableTypeWen
// * 獨體活字
// */
// void printWen(ChineseCharacterMovableTypeWen chineseCharacterMovableTypeWen);
//
// /**
// * 列印合體活字
// *
// * @param chineseCharacterMovableTypeTzu
// * 合體活字
// */
// void printTzu(ChineseCharacterMovableTypeTzu chineseCharacterMovableTypeTzu);
// }
//
// Path: src/main/java/idsrend/charcomponent/FinalCharComponent.java
// public class FinalCharComponent extends CharComponent
// {
// /**
// * 部件的組合方式
// */
// private final CompositionMethods type;
// /**
// * 底下的各個部件
// */
// private final CharComponent[] children;
//
// @Override
// public boolean 是文部件()
// {
// return false;
// }
//
// @Override
// public boolean 是字部件()
// {
// return true;
// }
//
// /**
// * 取得部件的組合方式
// *
// * @return 部件的組合方式
// */
// public CompositionMethods CompositionMethods()
// {
// return type;
// }
//
// /**
// * 取得底下的各個部件
// *
// * @return 底下的各個部件
// */
// public CharComponent[] 底下元素()
// {
// return children;
// }
// Path: src/main/java/cc/movabletype/ChineseCharacterMovableTypeTzu.java
import cc.layouttools.ChineseCharacterTypeAdjuster;
import cc.printtools.ChineseCharacterTypePrinter;
import idsrend.charcomponent.FinalCharComponent;
package cc.movabletype;
/**
* 漢字活字樹狀結構的上層節點。「獨體為文,合體為字」,樹狀結構中的葉子為文,其他上層節點為字。
* <code>ChineseCharacterMovableTypeTzu</code>記錄底下活字的排版資訊。
*
* @author Ihc
*/
public class ChineseCharacterMovableTypeTzu extends ChineseCharacterMovableType
{
/**
* 底下的各個活字
*/
protected ChineseCharCompositeMoveabletype[] children;
/**
* 以<code>ChineseCharacter</code>部件結構建立字活字結構
*
* @param parent
* 上一層的活字結構。若上層為樹狀的樹根,傳入null
* @param chineseCharacterTzu
* 字部件結構
*/
public ChineseCharacterMovableTypeTzu(
ChineseCharacterMovableTypeTzu parent,
FinalCharComponent chineseCharacterTzu)
{
super(parent, chineseCharacterTzu);
int childrenSize = chineseCharacterTzu.CompositionMethods().getNumberOfChildren();
this.children = new ChineseCharacterMovableType[childrenSize];
}
@Override | public void adjust(ChineseCharacterTypeAdjuster adjuster) |
sih4sing5hong5/han3_ji7_tsoo1_kian3 | src/main/java/cc/movabletype/ChineseCharacterMovableTypeTzu.java | // Path: src/main/java/cc/layouttools/ChineseCharacterTypeAdjuster.java
// public interface ChineseCharacterTypeAdjuster
// {
// /**
// * 調整獨體活字
// *
// * @param chineseCharacterMovableTypeWen
// * 欲調整之獨體活字
// */
// public void adjustWen(
// ChineseCharacterMovableTypeWen chineseCharacterMovableTypeWen);
//
// /**
// * 調整合體活字
// *
// * @param chineseCharacterMovableTypeTzu
// * 欲調整之合體活字
// */
// public void adjustTzu(
// ChineseCharacterMovableTypeTzu chineseCharacterMovableTypeTzu);
// }
//
// Path: src/main/java/cc/printtools/ChineseCharacterTypePrinter.java
// public interface ChineseCharacterTypePrinter
// {
// /**
// * 列印獨體活字
// *
// * @param chineseCharacterMovableTypeWen
// * 獨體活字
// */
// void printWen(ChineseCharacterMovableTypeWen chineseCharacterMovableTypeWen);
//
// /**
// * 列印合體活字
// *
// * @param chineseCharacterMovableTypeTzu
// * 合體活字
// */
// void printTzu(ChineseCharacterMovableTypeTzu chineseCharacterMovableTypeTzu);
// }
//
// Path: src/main/java/idsrend/charcomponent/FinalCharComponent.java
// public class FinalCharComponent extends CharComponent
// {
// /**
// * 部件的組合方式
// */
// private final CompositionMethods type;
// /**
// * 底下的各個部件
// */
// private final CharComponent[] children;
//
// @Override
// public boolean 是文部件()
// {
// return false;
// }
//
// @Override
// public boolean 是字部件()
// {
// return true;
// }
//
// /**
// * 取得部件的組合方式
// *
// * @return 部件的組合方式
// */
// public CompositionMethods CompositionMethods()
// {
// return type;
// }
//
// /**
// * 取得底下的各個部件
// *
// * @return 底下的各個部件
// */
// public CharComponent[] 底下元素()
// {
// return children;
// }
| import cc.layouttools.ChineseCharacterTypeAdjuster;
import cc.printtools.ChineseCharacterTypePrinter;
import idsrend.charcomponent.FinalCharComponent; | package cc.movabletype;
/**
* 漢字活字樹狀結構的上層節點。「獨體為文,合體為字」,樹狀結構中的葉子為文,其他上層節點為字。
* <code>ChineseCharacterMovableTypeTzu</code>記錄底下活字的排版資訊。
*
* @author Ihc
*/
public class ChineseCharacterMovableTypeTzu extends ChineseCharacterMovableType
{
/**
* 底下的各個活字
*/
protected ChineseCharCompositeMoveabletype[] children;
/**
* 以<code>ChineseCharacter</code>部件結構建立字活字結構
*
* @param parent
* 上一層的活字結構。若上層為樹狀的樹根,傳入null
* @param chineseCharacterTzu
* 字部件結構
*/
public ChineseCharacterMovableTypeTzu(
ChineseCharacterMovableTypeTzu parent,
FinalCharComponent chineseCharacterTzu)
{
super(parent, chineseCharacterTzu);
int childrenSize = chineseCharacterTzu.CompositionMethods().getNumberOfChildren();
this.children = new ChineseCharacterMovableType[childrenSize];
}
@Override
public void adjust(ChineseCharacterTypeAdjuster adjuster)
{
adjuster.adjustTzu(this);
return;
}
@Override | // Path: src/main/java/cc/layouttools/ChineseCharacterTypeAdjuster.java
// public interface ChineseCharacterTypeAdjuster
// {
// /**
// * 調整獨體活字
// *
// * @param chineseCharacterMovableTypeWen
// * 欲調整之獨體活字
// */
// public void adjustWen(
// ChineseCharacterMovableTypeWen chineseCharacterMovableTypeWen);
//
// /**
// * 調整合體活字
// *
// * @param chineseCharacterMovableTypeTzu
// * 欲調整之合體活字
// */
// public void adjustTzu(
// ChineseCharacterMovableTypeTzu chineseCharacterMovableTypeTzu);
// }
//
// Path: src/main/java/cc/printtools/ChineseCharacterTypePrinter.java
// public interface ChineseCharacterTypePrinter
// {
// /**
// * 列印獨體活字
// *
// * @param chineseCharacterMovableTypeWen
// * 獨體活字
// */
// void printWen(ChineseCharacterMovableTypeWen chineseCharacterMovableTypeWen);
//
// /**
// * 列印合體活字
// *
// * @param chineseCharacterMovableTypeTzu
// * 合體活字
// */
// void printTzu(ChineseCharacterMovableTypeTzu chineseCharacterMovableTypeTzu);
// }
//
// Path: src/main/java/idsrend/charcomponent/FinalCharComponent.java
// public class FinalCharComponent extends CharComponent
// {
// /**
// * 部件的組合方式
// */
// private final CompositionMethods type;
// /**
// * 底下的各個部件
// */
// private final CharComponent[] children;
//
// @Override
// public boolean 是文部件()
// {
// return false;
// }
//
// @Override
// public boolean 是字部件()
// {
// return true;
// }
//
// /**
// * 取得部件的組合方式
// *
// * @return 部件的組合方式
// */
// public CompositionMethods CompositionMethods()
// {
// return type;
// }
//
// /**
// * 取得底下的各個部件
// *
// * @return 底下的各個部件
// */
// public CharComponent[] 底下元素()
// {
// return children;
// }
// Path: src/main/java/cc/movabletype/ChineseCharacterMovableTypeTzu.java
import cc.layouttools.ChineseCharacterTypeAdjuster;
import cc.printtools.ChineseCharacterTypePrinter;
import idsrend.charcomponent.FinalCharComponent;
package cc.movabletype;
/**
* 漢字活字樹狀結構的上層節點。「獨體為文,合體為字」,樹狀結構中的葉子為文,其他上層節點為字。
* <code>ChineseCharacterMovableTypeTzu</code>記錄底下活字的排版資訊。
*
* @author Ihc
*/
public class ChineseCharacterMovableTypeTzu extends ChineseCharacterMovableType
{
/**
* 底下的各個活字
*/
protected ChineseCharCompositeMoveabletype[] children;
/**
* 以<code>ChineseCharacter</code>部件結構建立字活字結構
*
* @param parent
* 上一層的活字結構。若上層為樹狀的樹根,傳入null
* @param chineseCharacterTzu
* 字部件結構
*/
public ChineseCharacterMovableTypeTzu(
ChineseCharacterMovableTypeTzu parent,
FinalCharComponent chineseCharacterTzu)
{
super(parent, chineseCharacterTzu);
int childrenSize = chineseCharacterTzu.CompositionMethods().getNumberOfChildren();
this.children = new ChineseCharacterMovableType[childrenSize];
}
@Override
public void adjust(ChineseCharacterTypeAdjuster adjuster)
{
adjuster.adjustTzu(this);
return;
}
@Override | public void print(ChineseCharacterTypePrinter printer) |
sih4sing5hong5/han3_ji7_tsoo1_kian3 | src/main/java/cc/layouttools/VerticalAsmmod.java | // Path: src/main/java/cc/movabletype/SeprateMovabletype.java
// public class SeprateMovabletype
// {
// /** 目前字體大細,所在 */
// private Vector<PlaneGeometry> 字;
// /** 為著保留字體闊,若維護矩陣顛倒愛去顧平移 */
// private Vector<PlaneGeometry> 原本字體;
// /** 加粗莫合併的外殼 */
// private Vector<PlaneGeometry> 字外殼;
// /** 這馬的範圍,是為著閃避「一字問題」 */
// private Rectangle2D.Double 這馬;
// /** 目標範圍,上尾印的時陣愛看印偌大 */
// private Rectangle2D.Double 目標;
//
// public SeprateMovabletype()
// {
// 字 = new Vector<PlaneGeometry>();
// 原本字體 = new Vector<PlaneGeometry>();
// 字外殼 = null;
// 這馬 = new Rectangle.Double();
// 目標 = new Rectangle.Double();
// }
//
// public SeprateMovabletype(PlaneGeometry 幾何)
// {
// this();
// 字.add(幾何);
// 原本字體.add(幾何);
// 這馬字範圍();
// }
| import java.awt.geom.AffineTransform;
import cc.movabletype.SeprateMovabletype; | package cc.layouttools;
/**
* 適用於「⿱」垂直拼合部件,如「⿱將水」為「漿」,只要是垂直拼合,皆用此型態。先將兩活字寬度調整相同,再進行合併。
*
* @author Ihc
*/
public class VerticalAsmmod extends FlatSurAsmmod
{
/** 上面的物件活字 */ | // Path: src/main/java/cc/movabletype/SeprateMovabletype.java
// public class SeprateMovabletype
// {
// /** 目前字體大細,所在 */
// private Vector<PlaneGeometry> 字;
// /** 為著保留字體闊,若維護矩陣顛倒愛去顧平移 */
// private Vector<PlaneGeometry> 原本字體;
// /** 加粗莫合併的外殼 */
// private Vector<PlaneGeometry> 字外殼;
// /** 這馬的範圍,是為著閃避「一字問題」 */
// private Rectangle2D.Double 這馬;
// /** 目標範圍,上尾印的時陣愛看印偌大 */
// private Rectangle2D.Double 目標;
//
// public SeprateMovabletype()
// {
// 字 = new Vector<PlaneGeometry>();
// 原本字體 = new Vector<PlaneGeometry>();
// 字外殼 = null;
// 這馬 = new Rectangle.Double();
// 目標 = new Rectangle.Double();
// }
//
// public SeprateMovabletype(PlaneGeometry 幾何)
// {
// this();
// 字.add(幾何);
// 原本字體.add(幾何);
// 這馬字範圍();
// }
// Path: src/main/java/cc/layouttools/VerticalAsmmod.java
import java.awt.geom.AffineTransform;
import cc.movabletype.SeprateMovabletype;
package cc.layouttools;
/**
* 適用於「⿱」垂直拼合部件,如「⿱將水」為「漿」,只要是垂直拼合,皆用此型態。先將兩活字寬度調整相同,再進行合併。
*
* @author Ihc
*/
public class VerticalAsmmod extends FlatSurAsmmod
{
/** 上面的物件活字 */ | protected SeprateMovabletype upPiece; |
sih4sing5hong5/han3_ji7_tsoo1_kian3 | src/main/java/cc/movabletype/PieceMovableTypeTzu.java | // Path: src/main/java/idsrend/charcomponent/FinalCharComponent.java
// public class FinalCharComponent extends CharComponent
// {
// /**
// * 部件的組合方式
// */
// private final CompositionMethods type;
// /**
// * 底下的各個部件
// */
// private final CharComponent[] children;
//
// @Override
// public boolean 是文部件()
// {
// return false;
// }
//
// @Override
// public boolean 是字部件()
// {
// return true;
// }
//
// /**
// * 取得部件的組合方式
// *
// * @return 部件的組合方式
// */
// public CompositionMethods CompositionMethods()
// {
// return type;
// }
//
// /**
// * 取得底下的各個部件
// *
// * @return 底下的各個部件
// */
// public CharComponent[] 底下元素()
// {
// return children;
// }
| import idsrend.charcomponent.FinalCharComponent; | /**
*
*/
package cc.movabletype;
/**
* 物件活字樹狀結構的上層節點。把活字的資訊全部集中在同一個物件上(<code>Piece</code>,
* <code>RectangularArea</code>型態 ),方便函式傳遞與使用,而且物件上也有相對應操縱的函式。
*
* @author Ihc
* @see ChineseCharacterMovableTypeTzu
*/
public class PieceMovableTypeTzu extends ChineseCharacterMovableTypeTzu
implements PieceMovableType
{
/**
* 物件活字
*/
private final SeprateMovabletype rectangularArea;
/**
* 建立字活字結構
*
* @param parent
* 上一層的活字結構。若上層為樹狀的樹根,傳入null
* @param chineseCharacterTzu
* 字部件結構
* @param rectangularArea
* 物件活字
*/
public PieceMovableTypeTzu(ChineseCharacterMovableTypeTzu parent, | // Path: src/main/java/idsrend/charcomponent/FinalCharComponent.java
// public class FinalCharComponent extends CharComponent
// {
// /**
// * 部件的組合方式
// */
// private final CompositionMethods type;
// /**
// * 底下的各個部件
// */
// private final CharComponent[] children;
//
// @Override
// public boolean 是文部件()
// {
// return false;
// }
//
// @Override
// public boolean 是字部件()
// {
// return true;
// }
//
// /**
// * 取得部件的組合方式
// *
// * @return 部件的組合方式
// */
// public CompositionMethods CompositionMethods()
// {
// return type;
// }
//
// /**
// * 取得底下的各個部件
// *
// * @return 底下的各個部件
// */
// public CharComponent[] 底下元素()
// {
// return children;
// }
// Path: src/main/java/cc/movabletype/PieceMovableTypeTzu.java
import idsrend.charcomponent.FinalCharComponent;
/**
*
*/
package cc.movabletype;
/**
* 物件活字樹狀結構的上層節點。把活字的資訊全部集中在同一個物件上(<code>Piece</code>,
* <code>RectangularArea</code>型態 ),方便函式傳遞與使用,而且物件上也有相對應操縱的函式。
*
* @author Ihc
* @see ChineseCharacterMovableTypeTzu
*/
public class PieceMovableTypeTzu extends ChineseCharacterMovableTypeTzu
implements PieceMovableType
{
/**
* 物件活字
*/
private final SeprateMovabletype rectangularArea;
/**
* 建立字活字結構
*
* @param parent
* 上一層的活字結構。若上層為樹狀的樹根,傳入null
* @param chineseCharacterTzu
* 字部件結構
* @param rectangularArea
* 物件活字
*/
public PieceMovableTypeTzu(ChineseCharacterMovableTypeTzu parent, | FinalCharComponent chineseCharacterTzu, |
sih4sing5hong5/han3_ji7_tsoo1_kian3 | src/main/java/cc/char_indexingtool/CommonFontNoSearchbyDB.java | // Path: src/main/java/cc/tool/database/PgsqlConnection.java
// public class PgsqlConnection
// {
// /** 預設資料庫位置 */
// static public final String url = "jdbc:postgresql://localhost/漢字組建?useUnicode=true&characterEncoding=utf-8";
// /** 連線物件 */
// private Connection connection;
// /** 連線狀態 */
// private Statement statement;
//
// /**
// * 自動連線到資料庫,資料庫設定唯讀,這个帳號就無修改的權限。
// *
// * <pre>
// * ALTER DATABASE "漢字組建" set default_transaction_read_only=on;
// * </pre>
// */
// public PgsqlConnection()
// {
// this(url, "漢字組建", "ChineseCharacter");
// }
//
// /**
// * 連線到資料庫。
// *
// * @param urls
// * 資料庫位置
// * @param account
// * 資料庫帳號
// * @param passwd
// * 資料庫密碼
// */
// public PgsqlConnection(String urls, String account, String passwd)
// {
// try
// {
// Class.forName("org.postgresql.Driver");
// }
// catch (java.lang.ClassNotFoundException e)
// {
// System.err.print("ClassNotFoundException: ");
// System.err.println(e.getMessage());
// }
// try
// {
// connection = DriverManager.getConnection(urls, account, passwd);
// }
// catch (SQLException ex)
// {
// System.err.print("SQLException: ");
// System.err.println(ex.getMessage());
// }
// return;
// }
//
// /** 關閉連線。 */
// public void close()
// {
// try
// {
// connection.close();
// }
// catch (SQLException ex)
// {
// System.err.print("SQLException: ");
// System.err.println(ex.getMessage());
// }
// return;
// }
//
// /**
// * 查詢資料。
// *
// * @param query
// * 向資料庫提出的要求
// * @return 查詢結果
// * @throws SQLException
// * 資料庫錯誤
// */
// public ResultSet executeQuery(String query) throws SQLException
// {
// statement = connection.createStatement();
// ResultSet rs = statement.executeQuery(query);
// // stmt.close();
// return rs;
// }
//
// /**
// * 更改資料庫。
// *
// * @param query
// * 向資料庫提出的更改
// * @throws SQLException
// * 資料庫錯誤
// */
// public void executeUpdate(String query) throws SQLException
// {
// statement = connection.createStatement();
// statement.executeUpdate(query);
// statement.close();
// return;
// }
// }
| import java.sql.ResultSet;
import java.sql.SQLException;
import cc.tool.database.PgsqlConnection;
import cc.tool.database.DBCommandString; | package cc.char_indexingtool;
/**
* 連線到資料庫查展開式。
*
* @author Ihc
*/
public class CommonFontNoSearchbyDB implements CommonFontNoSearch
{
/** 佮資料庫的連線 */ | // Path: src/main/java/cc/tool/database/PgsqlConnection.java
// public class PgsqlConnection
// {
// /** 預設資料庫位置 */
// static public final String url = "jdbc:postgresql://localhost/漢字組建?useUnicode=true&characterEncoding=utf-8";
// /** 連線物件 */
// private Connection connection;
// /** 連線狀態 */
// private Statement statement;
//
// /**
// * 自動連線到資料庫,資料庫設定唯讀,這个帳號就無修改的權限。
// *
// * <pre>
// * ALTER DATABASE "漢字組建" set default_transaction_read_only=on;
// * </pre>
// */
// public PgsqlConnection()
// {
// this(url, "漢字組建", "ChineseCharacter");
// }
//
// /**
// * 連線到資料庫。
// *
// * @param urls
// * 資料庫位置
// * @param account
// * 資料庫帳號
// * @param passwd
// * 資料庫密碼
// */
// public PgsqlConnection(String urls, String account, String passwd)
// {
// try
// {
// Class.forName("org.postgresql.Driver");
// }
// catch (java.lang.ClassNotFoundException e)
// {
// System.err.print("ClassNotFoundException: ");
// System.err.println(e.getMessage());
// }
// try
// {
// connection = DriverManager.getConnection(urls, account, passwd);
// }
// catch (SQLException ex)
// {
// System.err.print("SQLException: ");
// System.err.println(ex.getMessage());
// }
// return;
// }
//
// /** 關閉連線。 */
// public void close()
// {
// try
// {
// connection.close();
// }
// catch (SQLException ex)
// {
// System.err.print("SQLException: ");
// System.err.println(ex.getMessage());
// }
// return;
// }
//
// /**
// * 查詢資料。
// *
// * @param query
// * 向資料庫提出的要求
// * @return 查詢結果
// * @throws SQLException
// * 資料庫錯誤
// */
// public ResultSet executeQuery(String query) throws SQLException
// {
// statement = connection.createStatement();
// ResultSet rs = statement.executeQuery(query);
// // stmt.close();
// return rs;
// }
//
// /**
// * 更改資料庫。
// *
// * @param query
// * 向資料庫提出的更改
// * @throws SQLException
// * 資料庫錯誤
// */
// public void executeUpdate(String query) throws SQLException
// {
// statement = connection.createStatement();
// statement.executeUpdate(query);
// statement.close();
// return;
// }
// }
// Path: src/main/java/cc/char_indexingtool/CommonFontNoSearchbyDB.java
import java.sql.ResultSet;
import java.sql.SQLException;
import cc.tool.database.PgsqlConnection;
import cc.tool.database.DBCommandString;
package cc.char_indexingtool;
/**
* 連線到資料庫查展開式。
*
* @author Ihc
*/
public class CommonFontNoSearchbyDB implements CommonFontNoSearch
{
/** 佮資料庫的連線 */ | protected PgsqlConnection 連線; |
sih4sing5hong5/han3_ji7_tsoo1_kian3 | src/main/java/cc/movabletype/PieceMovableTypeWen.java | // Path: src/main/java/idsrend/charcomponent/NonFinalCharComponent.java
// public class NonFinalCharComponent extends CharComponent
// {
// /**
// * 部件的Unicode編碼
// */
// private final int codePoint;
//
// /**
// * 初使化一个新的文部件。
// *
// * @param 面頂彼个字部件
// * 樹狀結構面頂彼个字部件
// * @param 控制碼
// * 這个文部件字的統一碼控制碼
// */
// /**
// * 建立一個文部件
// *
// * @param parent
// * 上一層的部件結構。若上層為樹狀的樹根,傳入null
// * @param codePoint
// * 部件的Unicode編碼
// */
// public NonFinalCharComponent(int codePoint)
// {
// this.codePoint = codePoint;
// }
//
// public NonFinalCharComponent(String 組字式)
// {
// this(組字式.codePointAt(0));
// }
//
// @Override
// public boolean 是文部件()
// {
// return true;
// }
//
// @Override
// public boolean 是字部件()
// {
// return false;
// }
//
// @Override
// public String 樹狀結構組字式()
// {
// return 部件組字式();
// }
//
// /**
// * 取得部件Unicode編碼
// *
// * @return 部件Unicode編碼
// */
// public int Unicode編號()
// {
// return codePoint;
// }
//
// @Override
// public ChineseCharCompositeMoveabletype typeset(
// ChineseCharacterTypeSetter chineseCharacterTypeSetter,
// ChineseCharacterMovableTypeTzu parent)
// {
// return chineseCharacterTypeSetter.setWen(parent, this);
// }
// }
| import idsrend.charcomponent.NonFinalCharComponent; | package cc.movabletype;
/**
* 物件活字樹狀結構的葉子。把活字的資訊全部集中在同一個物件上(<code>Piece</code>,
* <code>RectangularArea</code>型態 ),方便函式傳遞與使用,而且物件上也有相對應操縱的函式。
*
* @author Ihc
* @see ChineseCharacterMovableTypeWen
*/
public class PieceMovableTypeWen extends ChineseCharacterMovableTypeWen
implements PieceMovableType
{
/**
* 物件活字
*/
private final SeprateMovabletype rectangularArea;
/**
* 建立字活字結構
*
* @param parent
* 上一層的活字結構。若上層為樹狀的樹根,傳入null
* @param chineseCharacterWen
* 文部件結構
* @param rectangularArea
* 物件活字
*/
public PieceMovableTypeWen(ChineseCharacterMovableTypeTzu parent, | // Path: src/main/java/idsrend/charcomponent/NonFinalCharComponent.java
// public class NonFinalCharComponent extends CharComponent
// {
// /**
// * 部件的Unicode編碼
// */
// private final int codePoint;
//
// /**
// * 初使化一个新的文部件。
// *
// * @param 面頂彼个字部件
// * 樹狀結構面頂彼个字部件
// * @param 控制碼
// * 這个文部件字的統一碼控制碼
// */
// /**
// * 建立一個文部件
// *
// * @param parent
// * 上一層的部件結構。若上層為樹狀的樹根,傳入null
// * @param codePoint
// * 部件的Unicode編碼
// */
// public NonFinalCharComponent(int codePoint)
// {
// this.codePoint = codePoint;
// }
//
// public NonFinalCharComponent(String 組字式)
// {
// this(組字式.codePointAt(0));
// }
//
// @Override
// public boolean 是文部件()
// {
// return true;
// }
//
// @Override
// public boolean 是字部件()
// {
// return false;
// }
//
// @Override
// public String 樹狀結構組字式()
// {
// return 部件組字式();
// }
//
// /**
// * 取得部件Unicode編碼
// *
// * @return 部件Unicode編碼
// */
// public int Unicode編號()
// {
// return codePoint;
// }
//
// @Override
// public ChineseCharCompositeMoveabletype typeset(
// ChineseCharacterTypeSetter chineseCharacterTypeSetter,
// ChineseCharacterMovableTypeTzu parent)
// {
// return chineseCharacterTypeSetter.setWen(parent, this);
// }
// }
// Path: src/main/java/cc/movabletype/PieceMovableTypeWen.java
import idsrend.charcomponent.NonFinalCharComponent;
package cc.movabletype;
/**
* 物件活字樹狀結構的葉子。把活字的資訊全部集中在同一個物件上(<code>Piece</code>,
* <code>RectangularArea</code>型態 ),方便函式傳遞與使用,而且物件上也有相對應操縱的函式。
*
* @author Ihc
* @see ChineseCharacterMovableTypeWen
*/
public class PieceMovableTypeWen extends ChineseCharacterMovableTypeWen
implements PieceMovableType
{
/**
* 物件活字
*/
private final SeprateMovabletype rectangularArea;
/**
* 建立字活字結構
*
* @param parent
* 上一層的活字結構。若上層為樹狀的樹根,傳入null
* @param chineseCharacterWen
* 文部件結構
* @param rectangularArea
* 物件活字
*/
public PieceMovableTypeWen(ChineseCharacterMovableTypeTzu parent, | NonFinalCharComponent chineseCharacterWen, |
sih4sing5hong5/han3_ji7_tsoo1_kian3 | src/main/java/cc/layouttools/LRBSurronder.java | // Path: src/main/java/cc/movabletype/PieceMovableTypeTzu.java
// public class PieceMovableTypeTzu extends ChineseCharacterMovableTypeTzu
// implements PieceMovableType
// {
// /**
// * 物件活字
// */
// private final SeprateMovabletype rectangularArea;
//
// /**
// * 建立字活字結構
// *
// * @param parent
// * 上一層的活字結構。若上層為樹狀的樹根,傳入null
// * @param chineseCharacterTzu
// * 字部件結構
// * @param rectangularArea
// * 物件活字
// */
// public PieceMovableTypeTzu(ChineseCharacterMovableTypeTzu parent,
// FinalCharComponent chineseCharacterTzu,
// SeprateMovabletype rectangularArea)
// {
// super(parent, chineseCharacterTzu);
// this.rectangularArea = rectangularArea;
// }
//
// @Override
// public SeprateMovabletype getPiece()
// {
// return rectangularArea;
// }
//
// /**
// * 取得合體活字下各個元件的活字物件
// *
// * @return 各個元件的活字物件
// */
// public SeprateMovabletype[] 取得活字物件()
// {
// SeprateMovabletype[] 活字物件 = new SeprateMovabletype[getChildren().length];
// for (int i = 0; i < getChildren().length; ++i)
// 活字物件[i] = new SeprateMovabletype((SeprateMovabletype)
// ((PieceMovableType) getChildren()[i]).getPiece());
// return 活字物件;
// }
// }
//
// Path: src/main/java/cc/movabletype/SeprateMovabletype.java
// public class SeprateMovabletype
// {
// /** 目前字體大細,所在 */
// private Vector<PlaneGeometry> 字;
// /** 為著保留字體闊,若維護矩陣顛倒愛去顧平移 */
// private Vector<PlaneGeometry> 原本字體;
// /** 加粗莫合併的外殼 */
// private Vector<PlaneGeometry> 字外殼;
// /** 這馬的範圍,是為著閃避「一字問題」 */
// private Rectangle2D.Double 這馬;
// /** 目標範圍,上尾印的時陣愛看印偌大 */
// private Rectangle2D.Double 目標;
//
// public SeprateMovabletype()
// {
// 字 = new Vector<PlaneGeometry>();
// 原本字體 = new Vector<PlaneGeometry>();
// 字外殼 = null;
// 這馬 = new Rectangle.Double();
// 目標 = new Rectangle.Double();
// }
//
// public SeprateMovabletype(PlaneGeometry 幾何)
// {
// this();
// 字.add(幾何);
// 原本字體.add(幾何);
// 這馬字範圍();
// }
| import cc.movabletype.PieceMovableTypeTzu;
import cc.movabletype.SeprateMovabletype; | package cc.layouttools;
/**
* 用於左右下的包圍部件。從左右下三邊包住,像是「凵」等等。
*
* @author Ihc
*/
public class LRBSurronder extends ObjMoveableTypeSurronder
{
/**
* 建立左右下三邊包圍工具
*
* @param 調整工具
* 使用此包圍工具的調整工具,並使用其自身合併相關函式
*/
public LRBSurronder(MergePieceAdjuster 調整工具)
{
super(調整工具);
支援包圍部件.add("凵");
// TODO /*凶幽豳…*/
}
@Override | // Path: src/main/java/cc/movabletype/PieceMovableTypeTzu.java
// public class PieceMovableTypeTzu extends ChineseCharacterMovableTypeTzu
// implements PieceMovableType
// {
// /**
// * 物件活字
// */
// private final SeprateMovabletype rectangularArea;
//
// /**
// * 建立字活字結構
// *
// * @param parent
// * 上一層的活字結構。若上層為樹狀的樹根,傳入null
// * @param chineseCharacterTzu
// * 字部件結構
// * @param rectangularArea
// * 物件活字
// */
// public PieceMovableTypeTzu(ChineseCharacterMovableTypeTzu parent,
// FinalCharComponent chineseCharacterTzu,
// SeprateMovabletype rectangularArea)
// {
// super(parent, chineseCharacterTzu);
// this.rectangularArea = rectangularArea;
// }
//
// @Override
// public SeprateMovabletype getPiece()
// {
// return rectangularArea;
// }
//
// /**
// * 取得合體活字下各個元件的活字物件
// *
// * @return 各個元件的活字物件
// */
// public SeprateMovabletype[] 取得活字物件()
// {
// SeprateMovabletype[] 活字物件 = new SeprateMovabletype[getChildren().length];
// for (int i = 0; i < getChildren().length; ++i)
// 活字物件[i] = new SeprateMovabletype((SeprateMovabletype)
// ((PieceMovableType) getChildren()[i]).getPiece());
// return 活字物件;
// }
// }
//
// Path: src/main/java/cc/movabletype/SeprateMovabletype.java
// public class SeprateMovabletype
// {
// /** 目前字體大細,所在 */
// private Vector<PlaneGeometry> 字;
// /** 為著保留字體闊,若維護矩陣顛倒愛去顧平移 */
// private Vector<PlaneGeometry> 原本字體;
// /** 加粗莫合併的外殼 */
// private Vector<PlaneGeometry> 字外殼;
// /** 這馬的範圍,是為著閃避「一字問題」 */
// private Rectangle2D.Double 這馬;
// /** 目標範圍,上尾印的時陣愛看印偌大 */
// private Rectangle2D.Double 目標;
//
// public SeprateMovabletype()
// {
// 字 = new Vector<PlaneGeometry>();
// 原本字體 = new Vector<PlaneGeometry>();
// 字外殼 = null;
// 這馬 = new Rectangle.Double();
// 目標 = new Rectangle.Double();
// }
//
// public SeprateMovabletype(PlaneGeometry 幾何)
// {
// this();
// 字.add(幾何);
// 原本字體.add(幾何);
// 這馬字範圍();
// }
// Path: src/main/java/cc/layouttools/LRBSurronder.java
import cc.movabletype.PieceMovableTypeTzu;
import cc.movabletype.SeprateMovabletype;
package cc.layouttools;
/**
* 用於左右下的包圍部件。從左右下三邊包住,像是「凵」等等。
*
* @author Ihc
*/
public class LRBSurronder extends ObjMoveableTypeSurronder
{
/**
* 建立左右下三邊包圍工具
*
* @param 調整工具
* 使用此包圍工具的調整工具,並使用其自身合併相關函式
*/
public LRBSurronder(MergePieceAdjuster 調整工具)
{
super(調整工具);
支援包圍部件.add("凵");
// TODO /*凶幽豳…*/
}
@Override | public void 組合(PieceMovableTypeTzu 物件活字) |
sih4sing5hong5/han3_ji7_tsoo1_kian3 | src/main/java/cc/layouttools/LRBSurronder.java | // Path: src/main/java/cc/movabletype/PieceMovableTypeTzu.java
// public class PieceMovableTypeTzu extends ChineseCharacterMovableTypeTzu
// implements PieceMovableType
// {
// /**
// * 物件活字
// */
// private final SeprateMovabletype rectangularArea;
//
// /**
// * 建立字活字結構
// *
// * @param parent
// * 上一層的活字結構。若上層為樹狀的樹根,傳入null
// * @param chineseCharacterTzu
// * 字部件結構
// * @param rectangularArea
// * 物件活字
// */
// public PieceMovableTypeTzu(ChineseCharacterMovableTypeTzu parent,
// FinalCharComponent chineseCharacterTzu,
// SeprateMovabletype rectangularArea)
// {
// super(parent, chineseCharacterTzu);
// this.rectangularArea = rectangularArea;
// }
//
// @Override
// public SeprateMovabletype getPiece()
// {
// return rectangularArea;
// }
//
// /**
// * 取得合體活字下各個元件的活字物件
// *
// * @return 各個元件的活字物件
// */
// public SeprateMovabletype[] 取得活字物件()
// {
// SeprateMovabletype[] 活字物件 = new SeprateMovabletype[getChildren().length];
// for (int i = 0; i < getChildren().length; ++i)
// 活字物件[i] = new SeprateMovabletype((SeprateMovabletype)
// ((PieceMovableType) getChildren()[i]).getPiece());
// return 活字物件;
// }
// }
//
// Path: src/main/java/cc/movabletype/SeprateMovabletype.java
// public class SeprateMovabletype
// {
// /** 目前字體大細,所在 */
// private Vector<PlaneGeometry> 字;
// /** 為著保留字體闊,若維護矩陣顛倒愛去顧平移 */
// private Vector<PlaneGeometry> 原本字體;
// /** 加粗莫合併的外殼 */
// private Vector<PlaneGeometry> 字外殼;
// /** 這馬的範圍,是為著閃避「一字問題」 */
// private Rectangle2D.Double 這馬;
// /** 目標範圍,上尾印的時陣愛看印偌大 */
// private Rectangle2D.Double 目標;
//
// public SeprateMovabletype()
// {
// 字 = new Vector<PlaneGeometry>();
// 原本字體 = new Vector<PlaneGeometry>();
// 字外殼 = null;
// 這馬 = new Rectangle.Double();
// 目標 = new Rectangle.Double();
// }
//
// public SeprateMovabletype(PlaneGeometry 幾何)
// {
// this();
// 字.add(幾何);
// 原本字體.add(幾何);
// 這馬字範圍();
// }
| import cc.movabletype.PieceMovableTypeTzu;
import cc.movabletype.SeprateMovabletype; | package cc.layouttools;
/**
* 用於左右下的包圍部件。從左右下三邊包住,像是「凵」等等。
*
* @author Ihc
*/
public class LRBSurronder extends ObjMoveableTypeSurronder
{
/**
* 建立左右下三邊包圍工具
*
* @param 調整工具
* 使用此包圍工具的調整工具,並使用其自身合併相關函式
*/
public LRBSurronder(MergePieceAdjuster 調整工具)
{
super(調整工具);
支援包圍部件.add("凵");
// TODO /*凶幽豳…*/
}
@Override
public void 組合(PieceMovableTypeTzu 物件活字)
{
/** 平推前先用的調整模組 */
LRBOutsideAsmmod 模組 = new LRBOutsideAsmmod(調整工具);
/** 平推後用的調整模組 */
LRBInsideAsmmod 後模組 = new LRBInsideAsmmod(調整工具);
/** 要使用的平推工具 */
FlatSurronder FlatSurronder = new FlatSurronder(調整工具, 模組, 後模組);
| // Path: src/main/java/cc/movabletype/PieceMovableTypeTzu.java
// public class PieceMovableTypeTzu extends ChineseCharacterMovableTypeTzu
// implements PieceMovableType
// {
// /**
// * 物件活字
// */
// private final SeprateMovabletype rectangularArea;
//
// /**
// * 建立字活字結構
// *
// * @param parent
// * 上一層的活字結構。若上層為樹狀的樹根,傳入null
// * @param chineseCharacterTzu
// * 字部件結構
// * @param rectangularArea
// * 物件活字
// */
// public PieceMovableTypeTzu(ChineseCharacterMovableTypeTzu parent,
// FinalCharComponent chineseCharacterTzu,
// SeprateMovabletype rectangularArea)
// {
// super(parent, chineseCharacterTzu);
// this.rectangularArea = rectangularArea;
// }
//
// @Override
// public SeprateMovabletype getPiece()
// {
// return rectangularArea;
// }
//
// /**
// * 取得合體活字下各個元件的活字物件
// *
// * @return 各個元件的活字物件
// */
// public SeprateMovabletype[] 取得活字物件()
// {
// SeprateMovabletype[] 活字物件 = new SeprateMovabletype[getChildren().length];
// for (int i = 0; i < getChildren().length; ++i)
// 活字物件[i] = new SeprateMovabletype((SeprateMovabletype)
// ((PieceMovableType) getChildren()[i]).getPiece());
// return 活字物件;
// }
// }
//
// Path: src/main/java/cc/movabletype/SeprateMovabletype.java
// public class SeprateMovabletype
// {
// /** 目前字體大細,所在 */
// private Vector<PlaneGeometry> 字;
// /** 為著保留字體闊,若維護矩陣顛倒愛去顧平移 */
// private Vector<PlaneGeometry> 原本字體;
// /** 加粗莫合併的外殼 */
// private Vector<PlaneGeometry> 字外殼;
// /** 這馬的範圍,是為著閃避「一字問題」 */
// private Rectangle2D.Double 這馬;
// /** 目標範圍,上尾印的時陣愛看印偌大 */
// private Rectangle2D.Double 目標;
//
// public SeprateMovabletype()
// {
// 字 = new Vector<PlaneGeometry>();
// 原本字體 = new Vector<PlaneGeometry>();
// 字外殼 = null;
// 這馬 = new Rectangle.Double();
// 目標 = new Rectangle.Double();
// }
//
// public SeprateMovabletype(PlaneGeometry 幾何)
// {
// this();
// 字.add(幾何);
// 原本字體.add(幾何);
// 這馬字範圍();
// }
// Path: src/main/java/cc/layouttools/LRBSurronder.java
import cc.movabletype.PieceMovableTypeTzu;
import cc.movabletype.SeprateMovabletype;
package cc.layouttools;
/**
* 用於左右下的包圍部件。從左右下三邊包住,像是「凵」等等。
*
* @author Ihc
*/
public class LRBSurronder extends ObjMoveableTypeSurronder
{
/**
* 建立左右下三邊包圍工具
*
* @param 調整工具
* 使用此包圍工具的調整工具,並使用其自身合併相關函式
*/
public LRBSurronder(MergePieceAdjuster 調整工具)
{
super(調整工具);
支援包圍部件.add("凵");
// TODO /*凶幽豳…*/
}
@Override
public void 組合(PieceMovableTypeTzu 物件活字)
{
/** 平推前先用的調整模組 */
LRBOutsideAsmmod 模組 = new LRBOutsideAsmmod(調整工具);
/** 平推後用的調整模組 */
LRBInsideAsmmod 後模組 = new LRBInsideAsmmod(調整工具);
/** 要使用的平推工具 */
FlatSurronder FlatSurronder = new FlatSurronder(調整工具, 模組, 後模組);
| SeprateMovabletype[] 調整結果 = FlatSurronder.產生調整後活字(物件活字.取得活字物件()); |
sih4sing5hong5/han3_ji7_tsoo1_kian3 | src/main/java/cc/layouttools/SimplePieceAdjuster.java | // Path: src/main/java/cc/movabletype/SeprateMovabletype.java
// public class SeprateMovabletype
// {
// /** 目前字體大細,所在 */
// private Vector<PlaneGeometry> 字;
// /** 為著保留字體闊,若維護矩陣顛倒愛去顧平移 */
// private Vector<PlaneGeometry> 原本字體;
// /** 加粗莫合併的外殼 */
// private Vector<PlaneGeometry> 字外殼;
// /** 這馬的範圍,是為著閃避「一字問題」 */
// private Rectangle2D.Double 這馬;
// /** 目標範圍,上尾印的時陣愛看印偌大 */
// private Rectangle2D.Double 目標;
//
// public SeprateMovabletype()
// {
// 字 = new Vector<PlaneGeometry>();
// 原本字體 = new Vector<PlaneGeometry>();
// 字外殼 = null;
// 這馬 = new Rectangle.Double();
// 目標 = new Rectangle.Double();
// }
//
// public SeprateMovabletype(PlaneGeometry 幾何)
// {
// this();
// 字.add(幾何);
// 原本字體.add(幾何);
// 這馬字範圍();
// }
| import java.awt.geom.AffineTransform;
import java.awt.geom.Rectangle2D;
import org.slf4j.Logger;
import cc.log.IDSGenLogToolpack;
import cc.movabletype.SeprateMovabletype; | package cc.layouttools;
/**
* 區塊活字調整工具。調整<code>PieceMovableType</code>,因為把活字的資訊全部集中在同一個物件上(
* <code>Piece</code>, <code>RectangularArea</code>型態
* ),方便函式傳遞與使用,而且物件上也有相對應操縱的函式。
* <p>
* <code>SimplePiece</code>是在設定時兩兩配對後定框,調整時更改部件大小,但無法物件難實作距離貼近或拉開。
*
* @author Ihc
*/
abstract public class SimplePieceAdjuster implements
ChineseCharacterTypeAdjuster
{
/** 記錄程式狀況 */
protected Logger 記錄工具;
/**
* 建立物件活字調整工具
*
* @param chineseCharacterTypeBolder
* 物件活字加寬工具
* @param precision
* 合併、調整的精細度
*/
public SimplePieceAdjuster()
{
記錄工具 = new IDSGenLogToolpack().記錄工具(getClass());
}
// @Override
// public void adjustWen(
// ChineseCharacterMovableTypeWen chineseCharacterMovableTypeWen)
// {
// PieceMovableTypeWen pieceMovableTypeWen = (PieceMovableTypeWen)
// chineseCharacterMovableTypeWen;
// SeprateMovabletype rectangularArea = pieceMovableTypeWen.getPiece();
// AffineTransform affineTransform = getAffineTransform(rectangularArea);
// shrinkPieceByFixingStroke(rectangularArea, affineTransform);
// return;
// }
//
// @Override
// public void adjustTzu(ChineseCharacterMovableTypeTzu tzu)
// {
// PieceMovableTypeTzu pieceMovableTypeTzu = (PieceMovableTypeTzu) tzu;
// SeprateMovabletype rectangularArea = pieceMovableTypeTzu.getPiece();
// AffineTransform affineTransform = getAffineTransform(rectangularArea);
// rectangularArea.縮放(affineTransform);
// for (int i = 0; i < pieceMovableTypeTzu.getChildren().length; ++i)
// {
// PieceMovableType child = (PieceMovableType) pieceMovableTypeTzu
// .getChildren()[i];
// Rectangle2D childTerritory = child.getPiece().目標範圍();
// childTerritory.setRect(
// childTerritory.getX() * affineTransform.getScaleX(),
// childTerritory.getY() * affineTransform.getScaleY(),
// childTerritory.getWidth() * affineTransform.getScaleX(),
// childTerritory.getHeight() * affineTransform.getScaleY());
// pieceMovableTypeTzu.getChildren()[i].adjust(this);
// }
// }
/**
* 比較<code>RectangularArea</code>目前大小(<code>getBounds2D()</code>)和預期大小(
* <code>getTerritory()</code>),算出縮放矩陣
*
* @param rectangularArea
* 計算縮放的目標
* @return 相對應的縮放矩陣
*/ | // Path: src/main/java/cc/movabletype/SeprateMovabletype.java
// public class SeprateMovabletype
// {
// /** 目前字體大細,所在 */
// private Vector<PlaneGeometry> 字;
// /** 為著保留字體闊,若維護矩陣顛倒愛去顧平移 */
// private Vector<PlaneGeometry> 原本字體;
// /** 加粗莫合併的外殼 */
// private Vector<PlaneGeometry> 字外殼;
// /** 這馬的範圍,是為著閃避「一字問題」 */
// private Rectangle2D.Double 這馬;
// /** 目標範圍,上尾印的時陣愛看印偌大 */
// private Rectangle2D.Double 目標;
//
// public SeprateMovabletype()
// {
// 字 = new Vector<PlaneGeometry>();
// 原本字體 = new Vector<PlaneGeometry>();
// 字外殼 = null;
// 這馬 = new Rectangle.Double();
// 目標 = new Rectangle.Double();
// }
//
// public SeprateMovabletype(PlaneGeometry 幾何)
// {
// this();
// 字.add(幾何);
// 原本字體.add(幾何);
// 這馬字範圍();
// }
// Path: src/main/java/cc/layouttools/SimplePieceAdjuster.java
import java.awt.geom.AffineTransform;
import java.awt.geom.Rectangle2D;
import org.slf4j.Logger;
import cc.log.IDSGenLogToolpack;
import cc.movabletype.SeprateMovabletype;
package cc.layouttools;
/**
* 區塊活字調整工具。調整<code>PieceMovableType</code>,因為把活字的資訊全部集中在同一個物件上(
* <code>Piece</code>, <code>RectangularArea</code>型態
* ),方便函式傳遞與使用,而且物件上也有相對應操縱的函式。
* <p>
* <code>SimplePiece</code>是在設定時兩兩配對後定框,調整時更改部件大小,但無法物件難實作距離貼近或拉開。
*
* @author Ihc
*/
abstract public class SimplePieceAdjuster implements
ChineseCharacterTypeAdjuster
{
/** 記錄程式狀況 */
protected Logger 記錄工具;
/**
* 建立物件活字調整工具
*
* @param chineseCharacterTypeBolder
* 物件活字加寬工具
* @param precision
* 合併、調整的精細度
*/
public SimplePieceAdjuster()
{
記錄工具 = new IDSGenLogToolpack().記錄工具(getClass());
}
// @Override
// public void adjustWen(
// ChineseCharacterMovableTypeWen chineseCharacterMovableTypeWen)
// {
// PieceMovableTypeWen pieceMovableTypeWen = (PieceMovableTypeWen)
// chineseCharacterMovableTypeWen;
// SeprateMovabletype rectangularArea = pieceMovableTypeWen.getPiece();
// AffineTransform affineTransform = getAffineTransform(rectangularArea);
// shrinkPieceByFixingStroke(rectangularArea, affineTransform);
// return;
// }
//
// @Override
// public void adjustTzu(ChineseCharacterMovableTypeTzu tzu)
// {
// PieceMovableTypeTzu pieceMovableTypeTzu = (PieceMovableTypeTzu) tzu;
// SeprateMovabletype rectangularArea = pieceMovableTypeTzu.getPiece();
// AffineTransform affineTransform = getAffineTransform(rectangularArea);
// rectangularArea.縮放(affineTransform);
// for (int i = 0; i < pieceMovableTypeTzu.getChildren().length; ++i)
// {
// PieceMovableType child = (PieceMovableType) pieceMovableTypeTzu
// .getChildren()[i];
// Rectangle2D childTerritory = child.getPiece().目標範圍();
// childTerritory.setRect(
// childTerritory.getX() * affineTransform.getScaleX(),
// childTerritory.getY() * affineTransform.getScaleY(),
// childTerritory.getWidth() * affineTransform.getScaleX(),
// childTerritory.getHeight() * affineTransform.getScaleY());
// pieceMovableTypeTzu.getChildren()[i].adjust(this);
// }
// }
/**
* 比較<code>RectangularArea</code>目前大小(<code>getBounds2D()</code>)和預期大小(
* <code>getTerritory()</code>),算出縮放矩陣
*
* @param rectangularArea
* 計算縮放的目標
* @return 相對應的縮放矩陣
*/ | protected AffineTransform getAffineTransform(SeprateMovabletype rectangularArea) |
sih4sing5hong5/han3_ji7_tsoo1_kian3 | src/main/java/cc/example/awt/AwtStrokeWidthTest.java | // Path: src/main/java/cc/stroke/NullStroke.java
// public class NullStroke implements Stroke
// {
// @Override
// public Shape createStrokedShape(Shape p)
// {
// return new Area(p);
// }
//
// }
//
// Path: src/main/java/cc/stroke/SimplifyStroke.java
// public class SimplifyStroke implements Stroke
// {
// @Override
// public Shape createStrokedShape(Shape shape)
// {
// return createStrokedShape(new GeneralPath(shape));// Area保證他的順逆時針
// }
//
// /**
// * 去掉該路徑的冗點。
// *
// * @param generalPath
// * 路徑物件
// * @return 去掉冗點的結果
// */
// public Shape createStrokedShape(GeneralPath generalPath)
// {
// SimplifyAction simplifyAction = new SimplifyAction(
// generalPath.getWindingRule());
// PathTravel pathTravel = new PathTravel(simplifyAction);
// pathTravel.travelOn(generalPath);
// new ShapeAnalyst(simplifyAction.getCurrnetPath());
// return simplifyAction.getCurrnetPath();
// }
//
// }
| import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.Stroke;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.font.GlyphVector;
import java.awt.geom.Area;
import javax.swing.JFrame;
import javax.swing.JPanel;
import cc.example.reference.ControlPointsStroke;
import cc.stroke.FunctinoalBasicBolder;
import cc.stroke.NullStroke;
import cc.stroke.SimplifyStroke; | package cc.example.awt;
/**
* 加寬工具加寬趨勢分析, 將不同加寬度的字擺放在一起。
*
* @author Ihc
*/
public class AwtStrokeWidthTest extends JPanel
{
/** 序列化編號 */
private static final long serialVersionUID = 1L;
/** 視窗寬度 */
static final int WIDTH = 1620;
/** 視窗高度 */
static final int HEIGHT = 1050;
@Override
public void paint(Graphics g1)
{
System.out.println("D");
// if(true)
// return;
Graphics2D graphics2D = (Graphics2D) g1;
Font f = new Font("全字庫正宋體", Font.BOLD, 700);
GlyphVector gv = f.createGlyphVector(graphics2D.getFontRenderContext(),
"變");
System.out.println(gv.getNumGlyphs());
Area area = new Area(gv.getOutline());
// area = new Area(new Rectangle2D.Double(100, 200, 100, 200));
// area = new Area(new QuadCurve2D.Double(0.0, 0.0, 100.0, 0.0, 100,
// 100));
// AffineTransform affineTransform = new AffineTransform();
// affineTransform.setToTranslation(4, 4);
// // area.transform(affineTransform);
// area = new Area(new CubicCurve2D.Double(0.0, 0.0, 100.0, 0.0, 100,
// 100,
// 0, 100));
graphics2D.setColor(Color.RED);
graphics2D.setStroke(new ControlPointsStroke(5));
graphics2D.translate(10, 610);
// Stroke stroke = new SimplifyStroke();
System.out.println("--");
// ShapeAnalyst shapeAnalyst = new ShapeAnalyst(area);
System.out.println("--");
// area = new Area(stroke.createStrokedShape(area));
// shapeAnalyst = new ShapeAnalyst(area);
System.out.println("--");
graphics2D.draw(area);
graphics2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
graphics2D.translate(750, 000);
FunctinoalBasicBolder functinoalBasicBolder = new FunctinoalBasicBolder( | // Path: src/main/java/cc/stroke/NullStroke.java
// public class NullStroke implements Stroke
// {
// @Override
// public Shape createStrokedShape(Shape p)
// {
// return new Area(p);
// }
//
// }
//
// Path: src/main/java/cc/stroke/SimplifyStroke.java
// public class SimplifyStroke implements Stroke
// {
// @Override
// public Shape createStrokedShape(Shape shape)
// {
// return createStrokedShape(new GeneralPath(shape));// Area保證他的順逆時針
// }
//
// /**
// * 去掉該路徑的冗點。
// *
// * @param generalPath
// * 路徑物件
// * @return 去掉冗點的結果
// */
// public Shape createStrokedShape(GeneralPath generalPath)
// {
// SimplifyAction simplifyAction = new SimplifyAction(
// generalPath.getWindingRule());
// PathTravel pathTravel = new PathTravel(simplifyAction);
// pathTravel.travelOn(generalPath);
// new ShapeAnalyst(simplifyAction.getCurrnetPath());
// return simplifyAction.getCurrnetPath();
// }
//
// }
// Path: src/main/java/cc/example/awt/AwtStrokeWidthTest.java
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.Stroke;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.font.GlyphVector;
import java.awt.geom.Area;
import javax.swing.JFrame;
import javax.swing.JPanel;
import cc.example.reference.ControlPointsStroke;
import cc.stroke.FunctinoalBasicBolder;
import cc.stroke.NullStroke;
import cc.stroke.SimplifyStroke;
package cc.example.awt;
/**
* 加寬工具加寬趨勢分析, 將不同加寬度的字擺放在一起。
*
* @author Ihc
*/
public class AwtStrokeWidthTest extends JPanel
{
/** 序列化編號 */
private static final long serialVersionUID = 1L;
/** 視窗寬度 */
static final int WIDTH = 1620;
/** 視窗高度 */
static final int HEIGHT = 1050;
@Override
public void paint(Graphics g1)
{
System.out.println("D");
// if(true)
// return;
Graphics2D graphics2D = (Graphics2D) g1;
Font f = new Font("全字庫正宋體", Font.BOLD, 700);
GlyphVector gv = f.createGlyphVector(graphics2D.getFontRenderContext(),
"變");
System.out.println(gv.getNumGlyphs());
Area area = new Area(gv.getOutline());
// area = new Area(new Rectangle2D.Double(100, 200, 100, 200));
// area = new Area(new QuadCurve2D.Double(0.0, 0.0, 100.0, 0.0, 100,
// 100));
// AffineTransform affineTransform = new AffineTransform();
// affineTransform.setToTranslation(4, 4);
// // area.transform(affineTransform);
// area = new Area(new CubicCurve2D.Double(0.0, 0.0, 100.0, 0.0, 100,
// 100,
// 0, 100));
graphics2D.setColor(Color.RED);
graphics2D.setStroke(new ControlPointsStroke(5));
graphics2D.translate(10, 610);
// Stroke stroke = new SimplifyStroke();
System.out.println("--");
// ShapeAnalyst shapeAnalyst = new ShapeAnalyst(area);
System.out.println("--");
// area = new Area(stroke.createStrokedShape(area));
// shapeAnalyst = new ShapeAnalyst(area);
System.out.println("--");
graphics2D.draw(area);
graphics2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
graphics2D.translate(750, 000);
FunctinoalBasicBolder functinoalBasicBolder = new FunctinoalBasicBolder( | new Stroke[] { new SimplifyStroke()/*,new UnsharpenStroke(1.0) */}, 1); |
sih4sing5hong5/han3_ji7_tsoo1_kian3 | src/main/java/cc/example/awt/AwtStrokeWidthTest.java | // Path: src/main/java/cc/stroke/NullStroke.java
// public class NullStroke implements Stroke
// {
// @Override
// public Shape createStrokedShape(Shape p)
// {
// return new Area(p);
// }
//
// }
//
// Path: src/main/java/cc/stroke/SimplifyStroke.java
// public class SimplifyStroke implements Stroke
// {
// @Override
// public Shape createStrokedShape(Shape shape)
// {
// return createStrokedShape(new GeneralPath(shape));// Area保證他的順逆時針
// }
//
// /**
// * 去掉該路徑的冗點。
// *
// * @param generalPath
// * 路徑物件
// * @return 去掉冗點的結果
// */
// public Shape createStrokedShape(GeneralPath generalPath)
// {
// SimplifyAction simplifyAction = new SimplifyAction(
// generalPath.getWindingRule());
// PathTravel pathTravel = new PathTravel(simplifyAction);
// pathTravel.travelOn(generalPath);
// new ShapeAnalyst(simplifyAction.getCurrnetPath());
// return simplifyAction.getCurrnetPath();
// }
//
// }
| import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.Stroke;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.font.GlyphVector;
import java.awt.geom.Area;
import javax.swing.JFrame;
import javax.swing.JPanel;
import cc.example.reference.ControlPointsStroke;
import cc.stroke.FunctinoalBasicBolder;
import cc.stroke.NullStroke;
import cc.stroke.SimplifyStroke; | package cc.example.awt;
/**
* 加寬工具加寬趨勢分析, 將不同加寬度的字擺放在一起。
*
* @author Ihc
*/
public class AwtStrokeWidthTest extends JPanel
{
/** 序列化編號 */
private static final long serialVersionUID = 1L;
/** 視窗寬度 */
static final int WIDTH = 1620;
/** 視窗高度 */
static final int HEIGHT = 1050;
@Override
public void paint(Graphics g1)
{
System.out.println("D");
// if(true)
// return;
Graphics2D graphics2D = (Graphics2D) g1;
Font f = new Font("全字庫正宋體", Font.BOLD, 700);
GlyphVector gv = f.createGlyphVector(graphics2D.getFontRenderContext(),
"變");
System.out.println(gv.getNumGlyphs());
Area area = new Area(gv.getOutline());
// area = new Area(new Rectangle2D.Double(100, 200, 100, 200));
// area = new Area(new QuadCurve2D.Double(0.0, 0.0, 100.0, 0.0, 100,
// 100));
// AffineTransform affineTransform = new AffineTransform();
// affineTransform.setToTranslation(4, 4);
// // area.transform(affineTransform);
// area = new Area(new CubicCurve2D.Double(0.0, 0.0, 100.0, 0.0, 100,
// 100,
// 0, 100));
graphics2D.setColor(Color.RED);
graphics2D.setStroke(new ControlPointsStroke(5));
graphics2D.translate(10, 610);
// Stroke stroke = new SimplifyStroke();
System.out.println("--");
// ShapeAnalyst shapeAnalyst = new ShapeAnalyst(area);
System.out.println("--");
// area = new Area(stroke.createStrokedShape(area));
// shapeAnalyst = new ShapeAnalyst(area);
System.out.println("--");
graphics2D.draw(area);
graphics2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
graphics2D.translate(750, 000);
FunctinoalBasicBolder functinoalBasicBolder = new FunctinoalBasicBolder(
new Stroke[] { new SimplifyStroke()/*,new UnsharpenStroke(1.0) */}, 1);
Area a = area;
for (int i = 10; i >= 0; i -= 2)
{
Color color = new Color((10 - i) * 0x001010 + 0xff0000);
graphics2D.setColor(color);
graphics2D.setStroke(functinoalBasicBolder.getStroke(i * 5));
// graphics2D.setStroke(new BasicStroke(i * 5));
// stroke = new RadialStroke(i * 5);
// area = new Area();
graphics2D.draw(area);
// graphics2D.draw(stroke.createStrokedShape(area)); | // Path: src/main/java/cc/stroke/NullStroke.java
// public class NullStroke implements Stroke
// {
// @Override
// public Shape createStrokedShape(Shape p)
// {
// return new Area(p);
// }
//
// }
//
// Path: src/main/java/cc/stroke/SimplifyStroke.java
// public class SimplifyStroke implements Stroke
// {
// @Override
// public Shape createStrokedShape(Shape shape)
// {
// return createStrokedShape(new GeneralPath(shape));// Area保證他的順逆時針
// }
//
// /**
// * 去掉該路徑的冗點。
// *
// * @param generalPath
// * 路徑物件
// * @return 去掉冗點的結果
// */
// public Shape createStrokedShape(GeneralPath generalPath)
// {
// SimplifyAction simplifyAction = new SimplifyAction(
// generalPath.getWindingRule());
// PathTravel pathTravel = new PathTravel(simplifyAction);
// pathTravel.travelOn(generalPath);
// new ShapeAnalyst(simplifyAction.getCurrnetPath());
// return simplifyAction.getCurrnetPath();
// }
//
// }
// Path: src/main/java/cc/example/awt/AwtStrokeWidthTest.java
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.Stroke;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.font.GlyphVector;
import java.awt.geom.Area;
import javax.swing.JFrame;
import javax.swing.JPanel;
import cc.example.reference.ControlPointsStroke;
import cc.stroke.FunctinoalBasicBolder;
import cc.stroke.NullStroke;
import cc.stroke.SimplifyStroke;
package cc.example.awt;
/**
* 加寬工具加寬趨勢分析, 將不同加寬度的字擺放在一起。
*
* @author Ihc
*/
public class AwtStrokeWidthTest extends JPanel
{
/** 序列化編號 */
private static final long serialVersionUID = 1L;
/** 視窗寬度 */
static final int WIDTH = 1620;
/** 視窗高度 */
static final int HEIGHT = 1050;
@Override
public void paint(Graphics g1)
{
System.out.println("D");
// if(true)
// return;
Graphics2D graphics2D = (Graphics2D) g1;
Font f = new Font("全字庫正宋體", Font.BOLD, 700);
GlyphVector gv = f.createGlyphVector(graphics2D.getFontRenderContext(),
"變");
System.out.println(gv.getNumGlyphs());
Area area = new Area(gv.getOutline());
// area = new Area(new Rectangle2D.Double(100, 200, 100, 200));
// area = new Area(new QuadCurve2D.Double(0.0, 0.0, 100.0, 0.0, 100,
// 100));
// AffineTransform affineTransform = new AffineTransform();
// affineTransform.setToTranslation(4, 4);
// // area.transform(affineTransform);
// area = new Area(new CubicCurve2D.Double(0.0, 0.0, 100.0, 0.0, 100,
// 100,
// 0, 100));
graphics2D.setColor(Color.RED);
graphics2D.setStroke(new ControlPointsStroke(5));
graphics2D.translate(10, 610);
// Stroke stroke = new SimplifyStroke();
System.out.println("--");
// ShapeAnalyst shapeAnalyst = new ShapeAnalyst(area);
System.out.println("--");
// area = new Area(stroke.createStrokedShape(area));
// shapeAnalyst = new ShapeAnalyst(area);
System.out.println("--");
graphics2D.draw(area);
graphics2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
graphics2D.translate(750, 000);
FunctinoalBasicBolder functinoalBasicBolder = new FunctinoalBasicBolder(
new Stroke[] { new SimplifyStroke()/*,new UnsharpenStroke(1.0) */}, 1);
Area a = area;
for (int i = 10; i >= 0; i -= 2)
{
Color color = new Color((10 - i) * 0x001010 + 0xff0000);
graphics2D.setColor(color);
graphics2D.setStroke(functinoalBasicBolder.getStroke(i * 5));
// graphics2D.setStroke(new BasicStroke(i * 5));
// stroke = new RadialStroke(i * 5);
// area = new Area();
graphics2D.draw(area);
// graphics2D.draw(stroke.createStrokedShape(area)); | graphics2D.setStroke(new NullStroke()); |
sih4sing5hong5/han3_ji7_tsoo1_kian3 | src/main/java/cc/layouttools/VerticalAssembler.java | // Path: src/main/java/cc/movabletype/PieceMovableTypeTzu.java
// public class PieceMovableTypeTzu extends ChineseCharacterMovableTypeTzu
// implements PieceMovableType
// {
// /**
// * 物件活字
// */
// private final SeprateMovabletype rectangularArea;
//
// /**
// * 建立字活字結構
// *
// * @param parent
// * 上一層的活字結構。若上層為樹狀的樹根,傳入null
// * @param chineseCharacterTzu
// * 字部件結構
// * @param rectangularArea
// * 物件活字
// */
// public PieceMovableTypeTzu(ChineseCharacterMovableTypeTzu parent,
// FinalCharComponent chineseCharacterTzu,
// SeprateMovabletype rectangularArea)
// {
// super(parent, chineseCharacterTzu);
// this.rectangularArea = rectangularArea;
// }
//
// @Override
// public SeprateMovabletype getPiece()
// {
// return rectangularArea;
// }
//
// /**
// * 取得合體活字下各個元件的活字物件
// *
// * @return 各個元件的活字物件
// */
// public SeprateMovabletype[] 取得活字物件()
// {
// SeprateMovabletype[] 活字物件 = new SeprateMovabletype[getChildren().length];
// for (int i = 0; i < getChildren().length; ++i)
// 活字物件[i] = new SeprateMovabletype((SeprateMovabletype)
// ((PieceMovableType) getChildren()[i]).getPiece());
// return 活字物件;
// }
// }
//
// Path: src/main/java/cc/movabletype/SeprateMovabletype.java
// public class SeprateMovabletype
// {
// /** 目前字體大細,所在 */
// private Vector<PlaneGeometry> 字;
// /** 為著保留字體闊,若維護矩陣顛倒愛去顧平移 */
// private Vector<PlaneGeometry> 原本字體;
// /** 加粗莫合併的外殼 */
// private Vector<PlaneGeometry> 字外殼;
// /** 這馬的範圍,是為著閃避「一字問題」 */
// private Rectangle2D.Double 這馬;
// /** 目標範圍,上尾印的時陣愛看印偌大 */
// private Rectangle2D.Double 目標;
//
// public SeprateMovabletype()
// {
// 字 = new Vector<PlaneGeometry>();
// 原本字體 = new Vector<PlaneGeometry>();
// 字外殼 = null;
// 這馬 = new Rectangle.Double();
// 目標 = new Rectangle.Double();
// }
//
// public SeprateMovabletype(PlaneGeometry 幾何)
// {
// this();
// 字.add(幾何);
// 原本字體.add(幾何);
// 這馬字範圍();
// }
| import cc.movabletype.PieceMovableTypeTzu;
import cc.movabletype.SeprateMovabletype; | package cc.layouttools;
/**
* 用於上蓋的包圍部件。蓋住上方,左右二邊只包含上方一小部份,像是「冖」、「宀」和「『學』上半部」等等。
*
* @author Ihc
*/
public class VerticalAssembler extends ObjMoveableTypeSurronder
{
/**
* 建立垂直拼合工具
*
* @param 調整工具
* 使用此包圍工具的調整工具,並使用其自身合併相關函式
*/
public VerticalAssembler(MergePieceAdjuster 調整工具)
{
super(調整工具);
}
@Override | // Path: src/main/java/cc/movabletype/PieceMovableTypeTzu.java
// public class PieceMovableTypeTzu extends ChineseCharacterMovableTypeTzu
// implements PieceMovableType
// {
// /**
// * 物件活字
// */
// private final SeprateMovabletype rectangularArea;
//
// /**
// * 建立字活字結構
// *
// * @param parent
// * 上一層的活字結構。若上層為樹狀的樹根,傳入null
// * @param chineseCharacterTzu
// * 字部件結構
// * @param rectangularArea
// * 物件活字
// */
// public PieceMovableTypeTzu(ChineseCharacterMovableTypeTzu parent,
// FinalCharComponent chineseCharacterTzu,
// SeprateMovabletype rectangularArea)
// {
// super(parent, chineseCharacterTzu);
// this.rectangularArea = rectangularArea;
// }
//
// @Override
// public SeprateMovabletype getPiece()
// {
// return rectangularArea;
// }
//
// /**
// * 取得合體活字下各個元件的活字物件
// *
// * @return 各個元件的活字物件
// */
// public SeprateMovabletype[] 取得活字物件()
// {
// SeprateMovabletype[] 活字物件 = new SeprateMovabletype[getChildren().length];
// for (int i = 0; i < getChildren().length; ++i)
// 活字物件[i] = new SeprateMovabletype((SeprateMovabletype)
// ((PieceMovableType) getChildren()[i]).getPiece());
// return 活字物件;
// }
// }
//
// Path: src/main/java/cc/movabletype/SeprateMovabletype.java
// public class SeprateMovabletype
// {
// /** 目前字體大細,所在 */
// private Vector<PlaneGeometry> 字;
// /** 為著保留字體闊,若維護矩陣顛倒愛去顧平移 */
// private Vector<PlaneGeometry> 原本字體;
// /** 加粗莫合併的外殼 */
// private Vector<PlaneGeometry> 字外殼;
// /** 這馬的範圍,是為著閃避「一字問題」 */
// private Rectangle2D.Double 這馬;
// /** 目標範圍,上尾印的時陣愛看印偌大 */
// private Rectangle2D.Double 目標;
//
// public SeprateMovabletype()
// {
// 字 = new Vector<PlaneGeometry>();
// 原本字體 = new Vector<PlaneGeometry>();
// 字外殼 = null;
// 這馬 = new Rectangle.Double();
// 目標 = new Rectangle.Double();
// }
//
// public SeprateMovabletype(PlaneGeometry 幾何)
// {
// this();
// 字.add(幾何);
// 原本字體.add(幾何);
// 這馬字範圍();
// }
// Path: src/main/java/cc/layouttools/VerticalAssembler.java
import cc.movabletype.PieceMovableTypeTzu;
import cc.movabletype.SeprateMovabletype;
package cc.layouttools;
/**
* 用於上蓋的包圍部件。蓋住上方,左右二邊只包含上方一小部份,像是「冖」、「宀」和「『學』上半部」等等。
*
* @author Ihc
*/
public class VerticalAssembler extends ObjMoveableTypeSurronder
{
/**
* 建立垂直拼合工具
*
* @param 調整工具
* 使用此包圍工具的調整工具,並使用其自身合併相關函式
*/
public VerticalAssembler(MergePieceAdjuster 調整工具)
{
super(調整工具);
}
@Override | public void 組合(PieceMovableTypeTzu 物件活字) |
sih4sing5hong5/han3_ji7_tsoo1_kian3 | src/main/java/cc/layouttools/VerticalAssembler.java | // Path: src/main/java/cc/movabletype/PieceMovableTypeTzu.java
// public class PieceMovableTypeTzu extends ChineseCharacterMovableTypeTzu
// implements PieceMovableType
// {
// /**
// * 物件活字
// */
// private final SeprateMovabletype rectangularArea;
//
// /**
// * 建立字活字結構
// *
// * @param parent
// * 上一層的活字結構。若上層為樹狀的樹根,傳入null
// * @param chineseCharacterTzu
// * 字部件結構
// * @param rectangularArea
// * 物件活字
// */
// public PieceMovableTypeTzu(ChineseCharacterMovableTypeTzu parent,
// FinalCharComponent chineseCharacterTzu,
// SeprateMovabletype rectangularArea)
// {
// super(parent, chineseCharacterTzu);
// this.rectangularArea = rectangularArea;
// }
//
// @Override
// public SeprateMovabletype getPiece()
// {
// return rectangularArea;
// }
//
// /**
// * 取得合體活字下各個元件的活字物件
// *
// * @return 各個元件的活字物件
// */
// public SeprateMovabletype[] 取得活字物件()
// {
// SeprateMovabletype[] 活字物件 = new SeprateMovabletype[getChildren().length];
// for (int i = 0; i < getChildren().length; ++i)
// 活字物件[i] = new SeprateMovabletype((SeprateMovabletype)
// ((PieceMovableType) getChildren()[i]).getPiece());
// return 活字物件;
// }
// }
//
// Path: src/main/java/cc/movabletype/SeprateMovabletype.java
// public class SeprateMovabletype
// {
// /** 目前字體大細,所在 */
// private Vector<PlaneGeometry> 字;
// /** 為著保留字體闊,若維護矩陣顛倒愛去顧平移 */
// private Vector<PlaneGeometry> 原本字體;
// /** 加粗莫合併的外殼 */
// private Vector<PlaneGeometry> 字外殼;
// /** 這馬的範圍,是為著閃避「一字問題」 */
// private Rectangle2D.Double 這馬;
// /** 目標範圍,上尾印的時陣愛看印偌大 */
// private Rectangle2D.Double 目標;
//
// public SeprateMovabletype()
// {
// 字 = new Vector<PlaneGeometry>();
// 原本字體 = new Vector<PlaneGeometry>();
// 字外殼 = null;
// 這馬 = new Rectangle.Double();
// 目標 = new Rectangle.Double();
// }
//
// public SeprateMovabletype(PlaneGeometry 幾何)
// {
// this();
// 字.add(幾何);
// 原本字體.add(幾何);
// 這馬字範圍();
// }
| import cc.movabletype.PieceMovableTypeTzu;
import cc.movabletype.SeprateMovabletype; | package cc.layouttools;
/**
* 用於上蓋的包圍部件。蓋住上方,左右二邊只包含上方一小部份,像是「冖」、「宀」和「『學』上半部」等等。
*
* @author Ihc
*/
public class VerticalAssembler extends ObjMoveableTypeSurronder
{
/**
* 建立垂直拼合工具
*
* @param 調整工具
* 使用此包圍工具的調整工具,並使用其自身合併相關函式
*/
public VerticalAssembler(MergePieceAdjuster 調整工具)
{
super(調整工具);
}
@Override
public void 組合(PieceMovableTypeTzu 物件活字)
{
/** 面頂佮下跤佮做伙時的調整模組 */
VerticalAsmmod 模組 = new VerticalAsmmod(調整工具);
/** 將上下兩部件拼合的工具 */
BisearchPasteAssembler 貼合工具 = new BisearchPasteAssembler();
貼合工具.執行(模組, 物件活字.取得活字物件());
| // Path: src/main/java/cc/movabletype/PieceMovableTypeTzu.java
// public class PieceMovableTypeTzu extends ChineseCharacterMovableTypeTzu
// implements PieceMovableType
// {
// /**
// * 物件活字
// */
// private final SeprateMovabletype rectangularArea;
//
// /**
// * 建立字活字結構
// *
// * @param parent
// * 上一層的活字結構。若上層為樹狀的樹根,傳入null
// * @param chineseCharacterTzu
// * 字部件結構
// * @param rectangularArea
// * 物件活字
// */
// public PieceMovableTypeTzu(ChineseCharacterMovableTypeTzu parent,
// FinalCharComponent chineseCharacterTzu,
// SeprateMovabletype rectangularArea)
// {
// super(parent, chineseCharacterTzu);
// this.rectangularArea = rectangularArea;
// }
//
// @Override
// public SeprateMovabletype getPiece()
// {
// return rectangularArea;
// }
//
// /**
// * 取得合體活字下各個元件的活字物件
// *
// * @return 各個元件的活字物件
// */
// public SeprateMovabletype[] 取得活字物件()
// {
// SeprateMovabletype[] 活字物件 = new SeprateMovabletype[getChildren().length];
// for (int i = 0; i < getChildren().length; ++i)
// 活字物件[i] = new SeprateMovabletype((SeprateMovabletype)
// ((PieceMovableType) getChildren()[i]).getPiece());
// return 活字物件;
// }
// }
//
// Path: src/main/java/cc/movabletype/SeprateMovabletype.java
// public class SeprateMovabletype
// {
// /** 目前字體大細,所在 */
// private Vector<PlaneGeometry> 字;
// /** 為著保留字體闊,若維護矩陣顛倒愛去顧平移 */
// private Vector<PlaneGeometry> 原本字體;
// /** 加粗莫合併的外殼 */
// private Vector<PlaneGeometry> 字外殼;
// /** 這馬的範圍,是為著閃避「一字問題」 */
// private Rectangle2D.Double 這馬;
// /** 目標範圍,上尾印的時陣愛看印偌大 */
// private Rectangle2D.Double 目標;
//
// public SeprateMovabletype()
// {
// 字 = new Vector<PlaneGeometry>();
// 原本字體 = new Vector<PlaneGeometry>();
// 字外殼 = null;
// 這馬 = new Rectangle.Double();
// 目標 = new Rectangle.Double();
// }
//
// public SeprateMovabletype(PlaneGeometry 幾何)
// {
// this();
// 字.add(幾何);
// 原本字體.add(幾何);
// 這馬字範圍();
// }
// Path: src/main/java/cc/layouttools/VerticalAssembler.java
import cc.movabletype.PieceMovableTypeTzu;
import cc.movabletype.SeprateMovabletype;
package cc.layouttools;
/**
* 用於上蓋的包圍部件。蓋住上方,左右二邊只包含上方一小部份,像是「冖」、「宀」和「『學』上半部」等等。
*
* @author Ihc
*/
public class VerticalAssembler extends ObjMoveableTypeSurronder
{
/**
* 建立垂直拼合工具
*
* @param 調整工具
* 使用此包圍工具的調整工具,並使用其自身合併相關函式
*/
public VerticalAssembler(MergePieceAdjuster 調整工具)
{
super(調整工具);
}
@Override
public void 組合(PieceMovableTypeTzu 物件活字)
{
/** 面頂佮下跤佮做伙時的調整模組 */
VerticalAsmmod 模組 = new VerticalAsmmod(調整工具);
/** 將上下兩部件拼合的工具 */
BisearchPasteAssembler 貼合工具 = new BisearchPasteAssembler();
貼合工具.執行(模組, 物件活字.取得活字物件());
| SeprateMovabletype[] 調整結果 = 模組.取得調整後活字物件(); |
sih4sing5hong5/han3_ji7_tsoo1_kian3 | src/main/java/cc/layouttools/PasteFlatpushSticking.java | // Path: src/main/java/cc/movabletype/SeprateMovabletype.java
// public class SeprateMovabletype
// {
// /** 目前字體大細,所在 */
// private Vector<PlaneGeometry> 字;
// /** 為著保留字體闊,若維護矩陣顛倒愛去顧平移 */
// private Vector<PlaneGeometry> 原本字體;
// /** 加粗莫合併的外殼 */
// private Vector<PlaneGeometry> 字外殼;
// /** 這馬的範圍,是為著閃避「一字問題」 */
// private Rectangle2D.Double 這馬;
// /** 目標範圍,上尾印的時陣愛看印偌大 */
// private Rectangle2D.Double 目標;
//
// public SeprateMovabletype()
// {
// 字 = new Vector<PlaneGeometry>();
// 原本字體 = new Vector<PlaneGeometry>();
// 字外殼 = null;
// 這馬 = new Rectangle.Double();
// 目標 = new Rectangle.Double();
// }
//
// public SeprateMovabletype(PlaneGeometry 幾何)
// {
// this();
// 字.add(幾何);
// 原本字體.add(幾何);
// 這馬字範圍();
// }
| import cc.movabletype.SeprateMovabletype; | package cc.layouttools;
/**
* 適用於靠平推合併的模組,若是內部活字是靠拉長一個方向的長度來當參數調整,就可適用此型態。
*
* @author Ihc
*/
public abstract class PasteFlatpushSticking extends ZoomAsmmod
{
/**
* 建立平推黏合模組
*
* @param 調整工具 使用此模組的調整工具
* ,並使用其自身合併相關函式
*/
public PasteFlatpushSticking(MergePieceAdjuster 調整工具)
{
super(調整工具);
}
@Override | // Path: src/main/java/cc/movabletype/SeprateMovabletype.java
// public class SeprateMovabletype
// {
// /** 目前字體大細,所在 */
// private Vector<PlaneGeometry> 字;
// /** 為著保留字體闊,若維護矩陣顛倒愛去顧平移 */
// private Vector<PlaneGeometry> 原本字體;
// /** 加粗莫合併的外殼 */
// private Vector<PlaneGeometry> 字外殼;
// /** 這馬的範圍,是為著閃避「一字問題」 */
// private Rectangle2D.Double 這馬;
// /** 目標範圍,上尾印的時陣愛看印偌大 */
// private Rectangle2D.Double 目標;
//
// public SeprateMovabletype()
// {
// 字 = new Vector<PlaneGeometry>();
// 原本字體 = new Vector<PlaneGeometry>();
// 字外殼 = null;
// 這馬 = new Rectangle.Double();
// 目標 = new Rectangle.Double();
// }
//
// public SeprateMovabletype(PlaneGeometry 幾何)
// {
// this();
// 字.add(幾何);
// 原本字體.add(幾何);
// 這馬字範圍();
// }
// Path: src/main/java/cc/layouttools/PasteFlatpushSticking.java
import cc.movabletype.SeprateMovabletype;
package cc.layouttools;
/**
* 適用於靠平推合併的模組,若是內部活字是靠拉長一個方向的長度來當參數調整,就可適用此型態。
*
* @author Ihc
*/
public abstract class PasteFlatpushSticking extends ZoomAsmmod
{
/**
* 建立平推黏合模組
*
* @param 調整工具 使用此模組的調整工具
* ,並使用其自身合併相關函式
*/
public PasteFlatpushSticking(MergePieceAdjuster 調整工具)
{
super(調整工具);
}
@Override | public void 初始化(SeprateMovabletype[] rectangularAreas) |
sih4sing5hong5/han3_ji7_tsoo1_kian3 | src/main/java/cc/layouttools/BisearchPasteAsmMod.java | // Path: src/main/java/cc/movabletype/SeprateMovabletype.java
// public class SeprateMovabletype
// {
// /** 目前字體大細,所在 */
// private Vector<PlaneGeometry> 字;
// /** 為著保留字體闊,若維護矩陣顛倒愛去顧平移 */
// private Vector<PlaneGeometry> 原本字體;
// /** 加粗莫合併的外殼 */
// private Vector<PlaneGeometry> 字外殼;
// /** 這馬的範圍,是為著閃避「一字問題」 */
// private Rectangle2D.Double 這馬;
// /** 目標範圍,上尾印的時陣愛看印偌大 */
// private Rectangle2D.Double 目標;
//
// public SeprateMovabletype()
// {
// 字 = new Vector<PlaneGeometry>();
// 原本字體 = new Vector<PlaneGeometry>();
// 字外殼 = null;
// 這馬 = new Rectangle.Double();
// 目標 = new Rectangle.Double();
// }
//
// public SeprateMovabletype(PlaneGeometry 幾何)
// {
// this();
// 字.add(幾何);
// 原本字體.add(幾何);
// 這馬字範圍();
// }
| import cc.movabletype.SeprateMovabletype; | package cc.layouttools;
/**
* 用利用二元搜尋來組合兩個活字的模組,定義相關的動作,二元搜尋的上下限,變形方式等等細節。
*
* @author Ihc
*/
public abstract class BisearchPasteAsmMod
{
/** 使用此模組的調整工具,並使用其自身合併相關函式 */
protected MergePieceAdjuster 調整工具;
/**
* 建立二元搜尋貼合模組。
*
* @param 調整工具
* 使用此模組的調整工具,並使用其自身合併相關函式
*/
public BisearchPasteAsmMod(MergePieceAdjuster 調整工具)
{
this.調整工具 = 調整工具;
}
/**
* 初始化此模組。
*
* @param rectangularAreas
* 要調整的物件活字
*/ | // Path: src/main/java/cc/movabletype/SeprateMovabletype.java
// public class SeprateMovabletype
// {
// /** 目前字體大細,所在 */
// private Vector<PlaneGeometry> 字;
// /** 為著保留字體闊,若維護矩陣顛倒愛去顧平移 */
// private Vector<PlaneGeometry> 原本字體;
// /** 加粗莫合併的外殼 */
// private Vector<PlaneGeometry> 字外殼;
// /** 這馬的範圍,是為著閃避「一字問題」 */
// private Rectangle2D.Double 這馬;
// /** 目標範圍,上尾印的時陣愛看印偌大 */
// private Rectangle2D.Double 目標;
//
// public SeprateMovabletype()
// {
// 字 = new Vector<PlaneGeometry>();
// 原本字體 = new Vector<PlaneGeometry>();
// 字外殼 = null;
// 這馬 = new Rectangle.Double();
// 目標 = new Rectangle.Double();
// }
//
// public SeprateMovabletype(PlaneGeometry 幾何)
// {
// this();
// 字.add(幾何);
// 原本字體.add(幾何);
// 這馬字範圍();
// }
// Path: src/main/java/cc/layouttools/BisearchPasteAsmMod.java
import cc.movabletype.SeprateMovabletype;
package cc.layouttools;
/**
* 用利用二元搜尋來組合兩個活字的模組,定義相關的動作,二元搜尋的上下限,變形方式等等細節。
*
* @author Ihc
*/
public abstract class BisearchPasteAsmMod
{
/** 使用此模組的調整工具,並使用其自身合併相關函式 */
protected MergePieceAdjuster 調整工具;
/**
* 建立二元搜尋貼合模組。
*
* @param 調整工具
* 使用此模組的調整工具,並使用其自身合併相關函式
*/
public BisearchPasteAsmMod(MergePieceAdjuster 調整工具)
{
this.調整工具 = 調整工具;
}
/**
* 初始化此模組。
*
* @param rectangularAreas
* 要調整的物件活字
*/ | public abstract void 初始化(SeprateMovabletype[] rectangularAreas); |
sih4sing5hong5/han3_ji7_tsoo1_kian3 | src/main/java/idsrend/charcomponent/NonFinalCharComponent.java | // Path: src/main/java/cc/movabletype/ChineseCharacterMovableTypeTzu.java
// public class ChineseCharacterMovableTypeTzu extends ChineseCharacterMovableType
// {
//
// /**
// * 底下的各個活字
// */
// protected ChineseCharCompositeMoveabletype[] children;
//
// /**
// * 以<code>ChineseCharacter</code>部件結構建立字活字結構
// *
// * @param parent
// * 上一層的活字結構。若上層為樹狀的樹根,傳入null
// * @param chineseCharacterTzu
// * 字部件結構
// */
// public ChineseCharacterMovableTypeTzu(
// ChineseCharacterMovableTypeTzu parent,
// FinalCharComponent chineseCharacterTzu)
// {
// super(parent, chineseCharacterTzu);
// int childrenSize = chineseCharacterTzu.CompositionMethods().getNumberOfChildren();
// this.children = new ChineseCharacterMovableType[childrenSize];
// }
//
// @Override
// public void adjust(ChineseCharacterTypeAdjuster adjuster)
// {
// adjuster.adjustTzu(this);
// return;
// }
//
// @Override
// public void print(ChineseCharacterTypePrinter printer)
// {
// printer.printTzu(this);
// return;
// }
//
// /**
// * 取得底下的各個部件
// *
// * @return 底下的各個部件
// */
// public ChineseCharCompositeMoveabletype[] getChildren()
// {
// return children;
// }
// }
//
// Path: src/main/java/cc/char_indexingtool/ChineseCharacterTypeSetter.java
// public interface ChineseCharacterTypeSetter
// {
// /**
// * 產生並初使化獨體活字
// *
// * @param parent
// * 此活字結構的上層活字
// * @param chineseCharacterWen
// * 要轉化的文(獨體)CharComponent
// * @return 獨體活字
// */
// public ChineseCharCompositeMoveabletype setWen(ChineseCharacterMovableTypeTzu parent,
// NonFinalCharComponent chineseCharacterWen);
//
// /**
// * 產生並初使化合體活字
// *
// * @param parent
// * 此活字結構的上層活字
// * @param chineseCharacterTzu
// * 要轉化的字(合體)CharComponent
// * @return 合體活字
// */
// public ChineseCharCompositeMoveabletype setTzu(ChineseCharacterMovableTypeTzu parent,
// FinalCharComponent chineseCharacterTzu);
// }
| import cc.movabletype.ChineseCharacterMovableTypeTzu;
import cc.char_indexingtool.ChineseCharacterTypeSetter;
import cc.movabletype.ChineseCharCompositeMoveabletype; | @Override
public boolean 是文部件()
{
return true;
}
@Override
public boolean 是字部件()
{
return false;
}
@Override
public String 樹狀結構組字式()
{
return 部件組字式();
}
/**
* 取得部件Unicode編碼
*
* @return 部件Unicode編碼
*/
public int Unicode編號()
{
return codePoint;
}
@Override
public ChineseCharCompositeMoveabletype typeset( | // Path: src/main/java/cc/movabletype/ChineseCharacterMovableTypeTzu.java
// public class ChineseCharacterMovableTypeTzu extends ChineseCharacterMovableType
// {
//
// /**
// * 底下的各個活字
// */
// protected ChineseCharCompositeMoveabletype[] children;
//
// /**
// * 以<code>ChineseCharacter</code>部件結構建立字活字結構
// *
// * @param parent
// * 上一層的活字結構。若上層為樹狀的樹根,傳入null
// * @param chineseCharacterTzu
// * 字部件結構
// */
// public ChineseCharacterMovableTypeTzu(
// ChineseCharacterMovableTypeTzu parent,
// FinalCharComponent chineseCharacterTzu)
// {
// super(parent, chineseCharacterTzu);
// int childrenSize = chineseCharacterTzu.CompositionMethods().getNumberOfChildren();
// this.children = new ChineseCharacterMovableType[childrenSize];
// }
//
// @Override
// public void adjust(ChineseCharacterTypeAdjuster adjuster)
// {
// adjuster.adjustTzu(this);
// return;
// }
//
// @Override
// public void print(ChineseCharacterTypePrinter printer)
// {
// printer.printTzu(this);
// return;
// }
//
// /**
// * 取得底下的各個部件
// *
// * @return 底下的各個部件
// */
// public ChineseCharCompositeMoveabletype[] getChildren()
// {
// return children;
// }
// }
//
// Path: src/main/java/cc/char_indexingtool/ChineseCharacterTypeSetter.java
// public interface ChineseCharacterTypeSetter
// {
// /**
// * 產生並初使化獨體活字
// *
// * @param parent
// * 此活字結構的上層活字
// * @param chineseCharacterWen
// * 要轉化的文(獨體)CharComponent
// * @return 獨體活字
// */
// public ChineseCharCompositeMoveabletype setWen(ChineseCharacterMovableTypeTzu parent,
// NonFinalCharComponent chineseCharacterWen);
//
// /**
// * 產生並初使化合體活字
// *
// * @param parent
// * 此活字結構的上層活字
// * @param chineseCharacterTzu
// * 要轉化的字(合體)CharComponent
// * @return 合體活字
// */
// public ChineseCharCompositeMoveabletype setTzu(ChineseCharacterMovableTypeTzu parent,
// FinalCharComponent chineseCharacterTzu);
// }
// Path: src/main/java/idsrend/charcomponent/NonFinalCharComponent.java
import cc.movabletype.ChineseCharacterMovableTypeTzu;
import cc.char_indexingtool.ChineseCharacterTypeSetter;
import cc.movabletype.ChineseCharCompositeMoveabletype;
@Override
public boolean 是文部件()
{
return true;
}
@Override
public boolean 是字部件()
{
return false;
}
@Override
public String 樹狀結構組字式()
{
return 部件組字式();
}
/**
* 取得部件Unicode編碼
*
* @return 部件Unicode編碼
*/
public int Unicode編號()
{
return codePoint;
}
@Override
public ChineseCharCompositeMoveabletype typeset( | ChineseCharacterTypeSetter chineseCharacterTypeSetter, |
sih4sing5hong5/han3_ji7_tsoo1_kian3 | src/main/java/idsrend/charcomponent/NonFinalCharComponent.java | // Path: src/main/java/cc/movabletype/ChineseCharacterMovableTypeTzu.java
// public class ChineseCharacterMovableTypeTzu extends ChineseCharacterMovableType
// {
//
// /**
// * 底下的各個活字
// */
// protected ChineseCharCompositeMoveabletype[] children;
//
// /**
// * 以<code>ChineseCharacter</code>部件結構建立字活字結構
// *
// * @param parent
// * 上一層的活字結構。若上層為樹狀的樹根,傳入null
// * @param chineseCharacterTzu
// * 字部件結構
// */
// public ChineseCharacterMovableTypeTzu(
// ChineseCharacterMovableTypeTzu parent,
// FinalCharComponent chineseCharacterTzu)
// {
// super(parent, chineseCharacterTzu);
// int childrenSize = chineseCharacterTzu.CompositionMethods().getNumberOfChildren();
// this.children = new ChineseCharacterMovableType[childrenSize];
// }
//
// @Override
// public void adjust(ChineseCharacterTypeAdjuster adjuster)
// {
// adjuster.adjustTzu(this);
// return;
// }
//
// @Override
// public void print(ChineseCharacterTypePrinter printer)
// {
// printer.printTzu(this);
// return;
// }
//
// /**
// * 取得底下的各個部件
// *
// * @return 底下的各個部件
// */
// public ChineseCharCompositeMoveabletype[] getChildren()
// {
// return children;
// }
// }
//
// Path: src/main/java/cc/char_indexingtool/ChineseCharacterTypeSetter.java
// public interface ChineseCharacterTypeSetter
// {
// /**
// * 產生並初使化獨體活字
// *
// * @param parent
// * 此活字結構的上層活字
// * @param chineseCharacterWen
// * 要轉化的文(獨體)CharComponent
// * @return 獨體活字
// */
// public ChineseCharCompositeMoveabletype setWen(ChineseCharacterMovableTypeTzu parent,
// NonFinalCharComponent chineseCharacterWen);
//
// /**
// * 產生並初使化合體活字
// *
// * @param parent
// * 此活字結構的上層活字
// * @param chineseCharacterTzu
// * 要轉化的字(合體)CharComponent
// * @return 合體活字
// */
// public ChineseCharCompositeMoveabletype setTzu(ChineseCharacterMovableTypeTzu parent,
// FinalCharComponent chineseCharacterTzu);
// }
| import cc.movabletype.ChineseCharacterMovableTypeTzu;
import cc.char_indexingtool.ChineseCharacterTypeSetter;
import cc.movabletype.ChineseCharCompositeMoveabletype; | public boolean 是文部件()
{
return true;
}
@Override
public boolean 是字部件()
{
return false;
}
@Override
public String 樹狀結構組字式()
{
return 部件組字式();
}
/**
* 取得部件Unicode編碼
*
* @return 部件Unicode編碼
*/
public int Unicode編號()
{
return codePoint;
}
@Override
public ChineseCharCompositeMoveabletype typeset(
ChineseCharacterTypeSetter chineseCharacterTypeSetter, | // Path: src/main/java/cc/movabletype/ChineseCharacterMovableTypeTzu.java
// public class ChineseCharacterMovableTypeTzu extends ChineseCharacterMovableType
// {
//
// /**
// * 底下的各個活字
// */
// protected ChineseCharCompositeMoveabletype[] children;
//
// /**
// * 以<code>ChineseCharacter</code>部件結構建立字活字結構
// *
// * @param parent
// * 上一層的活字結構。若上層為樹狀的樹根,傳入null
// * @param chineseCharacterTzu
// * 字部件結構
// */
// public ChineseCharacterMovableTypeTzu(
// ChineseCharacterMovableTypeTzu parent,
// FinalCharComponent chineseCharacterTzu)
// {
// super(parent, chineseCharacterTzu);
// int childrenSize = chineseCharacterTzu.CompositionMethods().getNumberOfChildren();
// this.children = new ChineseCharacterMovableType[childrenSize];
// }
//
// @Override
// public void adjust(ChineseCharacterTypeAdjuster adjuster)
// {
// adjuster.adjustTzu(this);
// return;
// }
//
// @Override
// public void print(ChineseCharacterTypePrinter printer)
// {
// printer.printTzu(this);
// return;
// }
//
// /**
// * 取得底下的各個部件
// *
// * @return 底下的各個部件
// */
// public ChineseCharCompositeMoveabletype[] getChildren()
// {
// return children;
// }
// }
//
// Path: src/main/java/cc/char_indexingtool/ChineseCharacterTypeSetter.java
// public interface ChineseCharacterTypeSetter
// {
// /**
// * 產生並初使化獨體活字
// *
// * @param parent
// * 此活字結構的上層活字
// * @param chineseCharacterWen
// * 要轉化的文(獨體)CharComponent
// * @return 獨體活字
// */
// public ChineseCharCompositeMoveabletype setWen(ChineseCharacterMovableTypeTzu parent,
// NonFinalCharComponent chineseCharacterWen);
//
// /**
// * 產生並初使化合體活字
// *
// * @param parent
// * 此活字結構的上層活字
// * @param chineseCharacterTzu
// * 要轉化的字(合體)CharComponent
// * @return 合體活字
// */
// public ChineseCharCompositeMoveabletype setTzu(ChineseCharacterMovableTypeTzu parent,
// FinalCharComponent chineseCharacterTzu);
// }
// Path: src/main/java/idsrend/charcomponent/NonFinalCharComponent.java
import cc.movabletype.ChineseCharacterMovableTypeTzu;
import cc.char_indexingtool.ChineseCharacterTypeSetter;
import cc.movabletype.ChineseCharCompositeMoveabletype;
public boolean 是文部件()
{
return true;
}
@Override
public boolean 是字部件()
{
return false;
}
@Override
public String 樹狀結構組字式()
{
return 部件組字式();
}
/**
* 取得部件Unicode編碼
*
* @return 部件Unicode編碼
*/
public int Unicode編號()
{
return codePoint;
}
@Override
public ChineseCharCompositeMoveabletype typeset(
ChineseCharacterTypeSetter chineseCharacterTypeSetter, | ChineseCharacterMovableTypeTzu parent) |
sih4sing5hong5/han3_ji7_tsoo1_kian3 | src/main/java/cc/ccomponent_adjuster/ExpSequenceLookup.java | // Path: src/main/java/cc/tool/database/String2ControlCode.java
// public class String2ControlCode
// {
// /**
// * 將字串型態轉換成整數控制碼
// *
// * @param 字串
// * 欲轉換的文字
// * @return 轉換結果
// */
// static public int[] 轉換成控制碼(String 字串)
// {
// int 控制碼長度 = 字串.codePointCount(0, 字串.length());
// int[] 控制碼 = new int[控制碼長度];
//
// int 註標 = 0, 字串註標 = 0;
// for (字串註標 = 0, 註標 = 0; 字串註標 < 字串.length(); 字串註標 += Character.charCount(字串.codePointAt(字串註標)), 註標++)
// {
// 控制碼[註標] = 字串.codePointAt(字串註標);
// }
// return 控制碼;
// }
| import cc.tool.database.String2ControlCode; | package cc.ccomponent_adjuster;
/**
* 單字查詢展開式介面。
*
* @author Ihc
*/
public abstract class ExpSequenceLookup
{
/**
* 查詢其展開式,若無,回傳null。
*
* @param 統一碼控制碼
* 欲查的控制碼
* @return 這字的展開式
*/
public abstract String 查詢展開式(int 統一碼控制碼);
/**
* 查詢字串第一个字的展開式,若無,回傳null。
*
* @param 待查文字
* 欲查的字
* @return 第一个字的展開式
*/
public String 查詢展開式(String 待查文字)
{ | // Path: src/main/java/cc/tool/database/String2ControlCode.java
// public class String2ControlCode
// {
// /**
// * 將字串型態轉換成整數控制碼
// *
// * @param 字串
// * 欲轉換的文字
// * @return 轉換結果
// */
// static public int[] 轉換成控制碼(String 字串)
// {
// int 控制碼長度 = 字串.codePointCount(0, 字串.length());
// int[] 控制碼 = new int[控制碼長度];
//
// int 註標 = 0, 字串註標 = 0;
// for (字串註標 = 0, 註標 = 0; 字串註標 < 字串.length(); 字串註標 += Character.charCount(字串.codePointAt(字串註標)), 註標++)
// {
// 控制碼[註標] = 字串.codePointAt(字串註標);
// }
// return 控制碼;
// }
// Path: src/main/java/cc/ccomponent_adjuster/ExpSequenceLookup.java
import cc.tool.database.String2ControlCode;
package cc.ccomponent_adjuster;
/**
* 單字查詢展開式介面。
*
* @author Ihc
*/
public abstract class ExpSequenceLookup
{
/**
* 查詢其展開式,若無,回傳null。
*
* @param 統一碼控制碼
* 欲查的控制碼
* @return 這字的展開式
*/
public abstract String 查詢展開式(int 統一碼控制碼);
/**
* 查詢字串第一个字的展開式,若無,回傳null。
*
* @param 待查文字
* 欲查的字
* @return 第一个字的展開式
*/
public String 查詢展開式(String 待查文字)
{ | int[] 待查控制碼 = String2ControlCode.轉換成控制碼(待查文字); |
lakeinchina/librestreaming | librestreaming/src/main/java/me/lake/librestreaming/rtmp/FLvMetaData.java | // Path: librestreaming/src/main/java/me/lake/librestreaming/model/RESCoreParameters.java
// public class RESCoreParameters {
// public static final int FILTER_MODE_HARD = 1;
// public static final int FILTER_MODE_SOFT = 2;
//
// public static final int RENDERING_MODE_NATIVE_WINDOW = 1;
// public static final int RENDERING_MODE_OPENGLES = 2;
// /**
// * same with jni
// */
// public static final int FLAG_DIRECTION_FLIP_HORIZONTAL = 0x01;
// public static final int FLAG_DIRECTION_FLIP_VERTICAL = 0x02;
// public static final int FLAG_DIRECTION_ROATATION_0 = 0x10;
// public static final int FLAG_DIRECTION_ROATATION_90 = 0x20;
// public static final int FLAG_DIRECTION_ROATATION_180 = 0x40;
// public static final int FLAG_DIRECTION_ROATATION_270 = 0x80;
//
// public boolean done;
// public boolean printDetailMsg;
// public int filterMode;
// public int renderingMode;
// public String rtmpAddr;
// public int frontCameraDirectionMode;
// public int backCameraDirectionMode;
// public boolean isPortrait;
// public int previewVideoWidth;
// public int previewVideoHeight;
// public int videoWidth;
// public int videoHeight;
// public int videoFPS;
// public int videoGOP;
// public float cropRatio;
// public int previewColorFormat;
// public int previewBufferSize;
// public int mediacodecAVCColorFormat;
// public int mediacdoecAVCBitRate;
// public int videoBufferQueueNum;
// public int audioBufferQueueNum;
// public int audioRecoderFormat;
// public int audioRecoderSampleRate;
// public int audioRecoderChannelConfig;
// public int audioRecoderSliceSize;
// public int audioRecoderSource;
// public int audioRecoderBufferSize;
// public int previewMaxFps;
// public int previewMinFps;
// public int mediacodecAVCFrameRate;
// public int mediacodecAVCIFrameInterval;
// public int mediacodecAVCProfile;
// public int mediacodecAVClevel;
//
// public int mediacodecAACProfile;
// public int mediacodecAACSampleRate;
// public int mediacodecAACChannelCount;
// public int mediacodecAACBitRate;
// public int mediacodecAACMaxInputSize;
//
// //sender
// public int senderQueueLength;
//
// public RESCoreParameters() {
// done = false;
// printDetailMsg = false;
// filterMode=-1;
// videoWidth = -1;
// videoHeight = -1;
// videoFPS=-1;
// videoGOP=1;
// previewColorFormat = -1;
// mediacodecAVCColorFormat = -1;
// mediacdoecAVCBitRate = -1;
// videoBufferQueueNum = -1;
// audioBufferQueueNum = -1;
// mediacodecAVCFrameRate = -1;
// mediacodecAVCIFrameInterval = -1;
// mediacodecAVCProfile = -1;
// mediacodecAVClevel = -1;
// mediacodecAACProfile = -1;
// mediacodecAACSampleRate = -1;
// mediacodecAACChannelCount = -1;
// mediacodecAACBitRate = -1;
// mediacodecAACMaxInputSize = -1;
// }
//
// public void dump() {
// LogTools.e(this.toString());
// }
//
// @Override
// public String toString() {
// StringBuilder sb = new StringBuilder();
// sb.append("ResParameter:");
// Field[] fields = this.getClass().getDeclaredFields();
// for (Field field : fields) {
// if (Modifier.isStatic(field.getModifiers())) {
// continue;
// }
// field.setAccessible(true);
// try {
// sb.append(field.getName());
// sb.append('=');
// sb.append(field.get(this));
// sb.append(';');
// } catch (IllegalAccessException e) {
// }
// }
// return sb.toString();
// }
// }
| import java.util.ArrayList;
import me.lake.librestreaming.model.RESCoreParameters; | package me.lake.librestreaming.rtmp;
/**
* Created by tianyu on 15-12-29.
* modified by lake on 16-4-8.
* This class is able to generate a FLVTAG in accordance with Adobe Flash Video File Format
* Specification v10.1 Annex E.5 with limited types available.
*/
public class FLvMetaData {
private static final String Name = "onMetaData";
private static final int ScriptData = 18;
private static final byte[] TS_SID = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
private static final byte[] ObjEndMarker = {0x00, 0x00, 0x09};
private static final int EmptySize = 21;
private ArrayList<byte[]> MetaData;
private int DataSize;
private int pointer;
private byte[] MetaDataFrame;
public FLvMetaData() {
MetaData = new ArrayList<>();
DataSize = 0;
}
| // Path: librestreaming/src/main/java/me/lake/librestreaming/model/RESCoreParameters.java
// public class RESCoreParameters {
// public static final int FILTER_MODE_HARD = 1;
// public static final int FILTER_MODE_SOFT = 2;
//
// public static final int RENDERING_MODE_NATIVE_WINDOW = 1;
// public static final int RENDERING_MODE_OPENGLES = 2;
// /**
// * same with jni
// */
// public static final int FLAG_DIRECTION_FLIP_HORIZONTAL = 0x01;
// public static final int FLAG_DIRECTION_FLIP_VERTICAL = 0x02;
// public static final int FLAG_DIRECTION_ROATATION_0 = 0x10;
// public static final int FLAG_DIRECTION_ROATATION_90 = 0x20;
// public static final int FLAG_DIRECTION_ROATATION_180 = 0x40;
// public static final int FLAG_DIRECTION_ROATATION_270 = 0x80;
//
// public boolean done;
// public boolean printDetailMsg;
// public int filterMode;
// public int renderingMode;
// public String rtmpAddr;
// public int frontCameraDirectionMode;
// public int backCameraDirectionMode;
// public boolean isPortrait;
// public int previewVideoWidth;
// public int previewVideoHeight;
// public int videoWidth;
// public int videoHeight;
// public int videoFPS;
// public int videoGOP;
// public float cropRatio;
// public int previewColorFormat;
// public int previewBufferSize;
// public int mediacodecAVCColorFormat;
// public int mediacdoecAVCBitRate;
// public int videoBufferQueueNum;
// public int audioBufferQueueNum;
// public int audioRecoderFormat;
// public int audioRecoderSampleRate;
// public int audioRecoderChannelConfig;
// public int audioRecoderSliceSize;
// public int audioRecoderSource;
// public int audioRecoderBufferSize;
// public int previewMaxFps;
// public int previewMinFps;
// public int mediacodecAVCFrameRate;
// public int mediacodecAVCIFrameInterval;
// public int mediacodecAVCProfile;
// public int mediacodecAVClevel;
//
// public int mediacodecAACProfile;
// public int mediacodecAACSampleRate;
// public int mediacodecAACChannelCount;
// public int mediacodecAACBitRate;
// public int mediacodecAACMaxInputSize;
//
// //sender
// public int senderQueueLength;
//
// public RESCoreParameters() {
// done = false;
// printDetailMsg = false;
// filterMode=-1;
// videoWidth = -1;
// videoHeight = -1;
// videoFPS=-1;
// videoGOP=1;
// previewColorFormat = -1;
// mediacodecAVCColorFormat = -1;
// mediacdoecAVCBitRate = -1;
// videoBufferQueueNum = -1;
// audioBufferQueueNum = -1;
// mediacodecAVCFrameRate = -1;
// mediacodecAVCIFrameInterval = -1;
// mediacodecAVCProfile = -1;
// mediacodecAVClevel = -1;
// mediacodecAACProfile = -1;
// mediacodecAACSampleRate = -1;
// mediacodecAACChannelCount = -1;
// mediacodecAACBitRate = -1;
// mediacodecAACMaxInputSize = -1;
// }
//
// public void dump() {
// LogTools.e(this.toString());
// }
//
// @Override
// public String toString() {
// StringBuilder sb = new StringBuilder();
// sb.append("ResParameter:");
// Field[] fields = this.getClass().getDeclaredFields();
// for (Field field : fields) {
// if (Modifier.isStatic(field.getModifiers())) {
// continue;
// }
// field.setAccessible(true);
// try {
// sb.append(field.getName());
// sb.append('=');
// sb.append(field.get(this));
// sb.append(';');
// } catch (IllegalAccessException e) {
// }
// }
// return sb.toString();
// }
// }
// Path: librestreaming/src/main/java/me/lake/librestreaming/rtmp/FLvMetaData.java
import java.util.ArrayList;
import me.lake.librestreaming.model.RESCoreParameters;
package me.lake.librestreaming.rtmp;
/**
* Created by tianyu on 15-12-29.
* modified by lake on 16-4-8.
* This class is able to generate a FLVTAG in accordance with Adobe Flash Video File Format
* Specification v10.1 Annex E.5 with limited types available.
*/
public class FLvMetaData {
private static final String Name = "onMetaData";
private static final int ScriptData = 18;
private static final byte[] TS_SID = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
private static final byte[] ObjEndMarker = {0x00, 0x00, 0x09};
private static final int EmptySize = 21;
private ArrayList<byte[]> MetaData;
private int DataSize;
private int pointer;
private byte[] MetaDataFrame;
public FLvMetaData() {
MetaData = new ArrayList<>();
DataSize = 0;
}
| public FLvMetaData(RESCoreParameters coreParameters) { |
lakeinchina/librestreaming | librestreaming/src/main/java/me/lake/librestreaming/model/RESCoreParameters.java | // Path: librestreaming/src/main/java/me/lake/librestreaming/tools/LogTools.java
// public class LogTools {
// protected static final String TAG = "RESLog";
// private static boolean enableLog = true;
//
// public static boolean isEnableLog() {
// return enableLog;
// }
//
// public static void setEnableLog(boolean enableLog) {
// LogTools.enableLog = enableLog;
// }
//
// public static void e(String content) {
// if (!enableLog) {
// return;
// }
// Log.e(TAG, content);
// }
//
// public static void d(String content) {
// if (!enableLog) {
// return;
// }
// Log.d(TAG, content);
// }
//
// public static void trace(String msg) {
// if (!enableLog) {
// return;
// }
// trace(msg, new Throwable());
// }
//
// public static void trace(Throwable e) {
// if (!enableLog) {
// return;
// }
// trace(null, e);
// }
//
// public static void trace(String msg, Throwable e) {
// if (!enableLog) {
// return;
// }
// if (null == e || e instanceof UnknownHostException) {
// return;
// }
//
// final Writer writer = new StringWriter();
// final PrintWriter pWriter = new PrintWriter(writer);
// e.printStackTrace(pWriter);
// String stackTrace = writer.toString();
// if (null == msg || msg.equals("")) {
// msg = "================error!==================";
// }
// Log.e(TAG, "==================================");
// Log.e(TAG, msg);
// Log.e(TAG, stackTrace);
// Log.e(TAG, "-----------------------------------");
// }
// }
| import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import me.lake.librestreaming.tools.LogTools; | public int mediacodecAACMaxInputSize;
//sender
public int senderQueueLength;
public RESCoreParameters() {
done = false;
printDetailMsg = false;
filterMode=-1;
videoWidth = -1;
videoHeight = -1;
videoFPS=-1;
videoGOP=1;
previewColorFormat = -1;
mediacodecAVCColorFormat = -1;
mediacdoecAVCBitRate = -1;
videoBufferQueueNum = -1;
audioBufferQueueNum = -1;
mediacodecAVCFrameRate = -1;
mediacodecAVCIFrameInterval = -1;
mediacodecAVCProfile = -1;
mediacodecAVClevel = -1;
mediacodecAACProfile = -1;
mediacodecAACSampleRate = -1;
mediacodecAACChannelCount = -1;
mediacodecAACBitRate = -1;
mediacodecAACMaxInputSize = -1;
}
public void dump() { | // Path: librestreaming/src/main/java/me/lake/librestreaming/tools/LogTools.java
// public class LogTools {
// protected static final String TAG = "RESLog";
// private static boolean enableLog = true;
//
// public static boolean isEnableLog() {
// return enableLog;
// }
//
// public static void setEnableLog(boolean enableLog) {
// LogTools.enableLog = enableLog;
// }
//
// public static void e(String content) {
// if (!enableLog) {
// return;
// }
// Log.e(TAG, content);
// }
//
// public static void d(String content) {
// if (!enableLog) {
// return;
// }
// Log.d(TAG, content);
// }
//
// public static void trace(String msg) {
// if (!enableLog) {
// return;
// }
// trace(msg, new Throwable());
// }
//
// public static void trace(Throwable e) {
// if (!enableLog) {
// return;
// }
// trace(null, e);
// }
//
// public static void trace(String msg, Throwable e) {
// if (!enableLog) {
// return;
// }
// if (null == e || e instanceof UnknownHostException) {
// return;
// }
//
// final Writer writer = new StringWriter();
// final PrintWriter pWriter = new PrintWriter(writer);
// e.printStackTrace(pWriter);
// String stackTrace = writer.toString();
// if (null == msg || msg.equals("")) {
// msg = "================error!==================";
// }
// Log.e(TAG, "==================================");
// Log.e(TAG, msg);
// Log.e(TAG, stackTrace);
// Log.e(TAG, "-----------------------------------");
// }
// }
// Path: librestreaming/src/main/java/me/lake/librestreaming/model/RESCoreParameters.java
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import me.lake.librestreaming.tools.LogTools;
public int mediacodecAACMaxInputSize;
//sender
public int senderQueueLength;
public RESCoreParameters() {
done = false;
printDetailMsg = false;
filterMode=-1;
videoWidth = -1;
videoHeight = -1;
videoFPS=-1;
videoGOP=1;
previewColorFormat = -1;
mediacodecAVCColorFormat = -1;
mediacdoecAVCBitRate = -1;
videoBufferQueueNum = -1;
audioBufferQueueNum = -1;
mediacodecAVCFrameRate = -1;
mediacodecAVCIFrameInterval = -1;
mediacodecAVCProfile = -1;
mediacodecAVClevel = -1;
mediacodecAACProfile = -1;
mediacodecAACSampleRate = -1;
mediacodecAACChannelCount = -1;
mediacodecAACBitRate = -1;
mediacodecAACMaxInputSize = -1;
}
public void dump() { | LogTools.e(this.toString()); |
lakeinchina/librestreaming | librestreaming/src/main/java/me/lake/librestreaming/core/Packager.java | // Path: librestreaming/src/main/java/me/lake/librestreaming/tools/ByteArrayTools.java
// public class ByteArrayTools {
// public static void intToByteArrayFull(byte[] dst, int pos, int interger) {
// dst[pos] = (byte) ((interger >> 24) & 0xFF);
// dst[pos + 1] = (byte) ((interger >> 16) & 0xFF);
// dst[pos + 2] = (byte) ((interger >> 8) & 0xFF);
// dst[pos + 3] = (byte) ((interger) & 0xFF);
// }
//
// public static void intToByteArrayTwoByte(byte[] dst, int pos, int interger) {
// dst[pos] = (byte) ((interger >> 8) & 0xFF);
// dst[pos + 1] = (byte) ((interger) & 0xFF);
// }
// }
| import android.media.MediaFormat;
import java.nio.ByteBuffer;
import me.lake.librestreaming.tools.ByteArrayTools; | package me.lake.librestreaming.core;
/**
* Created by lake on 16-3-30.
*/
public class Packager {
public static class H264Packager {
public static byte[] generateAVCDecoderConfigurationRecord(MediaFormat mediaFormat) {
ByteBuffer SPSByteBuff = mediaFormat.getByteBuffer("csd-0");
SPSByteBuff.position(4);
ByteBuffer PPSByteBuff = mediaFormat.getByteBuffer("csd-1");
PPSByteBuff.position(4);
int spslength = SPSByteBuff.remaining();
int ppslength = PPSByteBuff.remaining();
int length = 11 + spslength + ppslength;
byte[] result = new byte[length];
SPSByteBuff.get(result, 8, spslength);
PPSByteBuff.get(result, 8 + spslength + 3, ppslength);
/**
* UB[8]configurationVersion
* UB[8]AVCProfileIndication
* UB[8]profile_compatibility
* UB[8]AVCLevelIndication
* UB[8]lengthSizeMinusOne
*/
result[0] = 0x01;
result[1] = result[9];
result[2] = result[10];
result[3] = result[11];
result[4] = (byte) 0xFF;
/**
* UB[8]numOfSequenceParameterSets
* UB[16]sequenceParameterSetLength
*/
result[5] = (byte) 0xE1; | // Path: librestreaming/src/main/java/me/lake/librestreaming/tools/ByteArrayTools.java
// public class ByteArrayTools {
// public static void intToByteArrayFull(byte[] dst, int pos, int interger) {
// dst[pos] = (byte) ((interger >> 24) & 0xFF);
// dst[pos + 1] = (byte) ((interger >> 16) & 0xFF);
// dst[pos + 2] = (byte) ((interger >> 8) & 0xFF);
// dst[pos + 3] = (byte) ((interger) & 0xFF);
// }
//
// public static void intToByteArrayTwoByte(byte[] dst, int pos, int interger) {
// dst[pos] = (byte) ((interger >> 8) & 0xFF);
// dst[pos + 1] = (byte) ((interger) & 0xFF);
// }
// }
// Path: librestreaming/src/main/java/me/lake/librestreaming/core/Packager.java
import android.media.MediaFormat;
import java.nio.ByteBuffer;
import me.lake.librestreaming.tools.ByteArrayTools;
package me.lake.librestreaming.core;
/**
* Created by lake on 16-3-30.
*/
public class Packager {
public static class H264Packager {
public static byte[] generateAVCDecoderConfigurationRecord(MediaFormat mediaFormat) {
ByteBuffer SPSByteBuff = mediaFormat.getByteBuffer("csd-0");
SPSByteBuff.position(4);
ByteBuffer PPSByteBuff = mediaFormat.getByteBuffer("csd-1");
PPSByteBuff.position(4);
int spslength = SPSByteBuff.remaining();
int ppslength = PPSByteBuff.remaining();
int length = 11 + spslength + ppslength;
byte[] result = new byte[length];
SPSByteBuff.get(result, 8, spslength);
PPSByteBuff.get(result, 8 + spslength + 3, ppslength);
/**
* UB[8]configurationVersion
* UB[8]AVCProfileIndication
* UB[8]profile_compatibility
* UB[8]AVCLevelIndication
* UB[8]lengthSizeMinusOne
*/
result[0] = 0x01;
result[1] = result[9];
result[2] = result[10];
result[3] = result[11];
result[4] = (byte) 0xFF;
/**
* UB[8]numOfSequenceParameterSets
* UB[16]sequenceParameterSetLength
*/
result[5] = (byte) 0xE1; | ByteArrayTools.intToByteArrayTwoByte(result, 6, spslength); |
lakeinchina/librestreaming | librestreaming/src/main/java/me/lake/librestreaming/render/NativeRender.java | // Path: librestreaming/src/main/java/me/lake/librestreaming/tools/LogTools.java
// public class LogTools {
// protected static final String TAG = "RESLog";
// private static boolean enableLog = true;
//
// public static boolean isEnableLog() {
// return enableLog;
// }
//
// public static void setEnableLog(boolean enableLog) {
// LogTools.enableLog = enableLog;
// }
//
// public static void e(String content) {
// if (!enableLog) {
// return;
// }
// Log.e(TAG, content);
// }
//
// public static void d(String content) {
// if (!enableLog) {
// return;
// }
// Log.d(TAG, content);
// }
//
// public static void trace(String msg) {
// if (!enableLog) {
// return;
// }
// trace(msg, new Throwable());
// }
//
// public static void trace(Throwable e) {
// if (!enableLog) {
// return;
// }
// trace(null, e);
// }
//
// public static void trace(String msg, Throwable e) {
// if (!enableLog) {
// return;
// }
// if (null == e || e instanceof UnknownHostException) {
// return;
// }
//
// final Writer writer = new StringWriter();
// final PrintWriter pWriter = new PrintWriter(writer);
// e.printStackTrace(pWriter);
// String stackTrace = writer.toString();
// if (null == msg || msg.equals("")) {
// msg = "================error!==================";
// }
// Log.e(TAG, "==================================");
// Log.e(TAG, msg);
// Log.e(TAG, stackTrace);
// Log.e(TAG, "-----------------------------------");
// }
// }
| import android.graphics.ImageFormat;
import android.graphics.SurfaceTexture;
import android.view.Surface;
import me.lake.librestreaming.tools.LogTools; | package me.lake.librestreaming.render;
/**
* Created by lake on 16-5-3.
*/
public class NativeRender implements IRender {
Surface mVisualSurface;
int mPixelWidth;
int mPixelHeight;
int mPixelSize;
@Override
public void create(SurfaceTexture visualSurfaceTexture, int pixelFormat, int pixelWidth, int pixelHeight, int visualWidth, int visualHeight) {
if (pixelFormat != ImageFormat.NV21) {
throw new IllegalArgumentException("NativeRender,pixelFormat only support NV21");
}
mVisualSurface = new Surface(visualSurfaceTexture);
mPixelWidth = pixelWidth;
mPixelHeight = pixelHeight;
mPixelSize = (3 * pixelWidth * pixelHeight) / 2;
}
@Override
public void update(int visualWidth, int visualHeight) {
}
@Override
public void rendering(byte[] pixel) {
if (mVisualSurface != null && mVisualSurface.isValid()) {
renderingSurface(mVisualSurface, pixel, mPixelWidth, mPixelHeight, mPixelSize);
} else { | // Path: librestreaming/src/main/java/me/lake/librestreaming/tools/LogTools.java
// public class LogTools {
// protected static final String TAG = "RESLog";
// private static boolean enableLog = true;
//
// public static boolean isEnableLog() {
// return enableLog;
// }
//
// public static void setEnableLog(boolean enableLog) {
// LogTools.enableLog = enableLog;
// }
//
// public static void e(String content) {
// if (!enableLog) {
// return;
// }
// Log.e(TAG, content);
// }
//
// public static void d(String content) {
// if (!enableLog) {
// return;
// }
// Log.d(TAG, content);
// }
//
// public static void trace(String msg) {
// if (!enableLog) {
// return;
// }
// trace(msg, new Throwable());
// }
//
// public static void trace(Throwable e) {
// if (!enableLog) {
// return;
// }
// trace(null, e);
// }
//
// public static void trace(String msg, Throwable e) {
// if (!enableLog) {
// return;
// }
// if (null == e || e instanceof UnknownHostException) {
// return;
// }
//
// final Writer writer = new StringWriter();
// final PrintWriter pWriter = new PrintWriter(writer);
// e.printStackTrace(pWriter);
// String stackTrace = writer.toString();
// if (null == msg || msg.equals("")) {
// msg = "================error!==================";
// }
// Log.e(TAG, "==================================");
// Log.e(TAG, msg);
// Log.e(TAG, stackTrace);
// Log.e(TAG, "-----------------------------------");
// }
// }
// Path: librestreaming/src/main/java/me/lake/librestreaming/render/NativeRender.java
import android.graphics.ImageFormat;
import android.graphics.SurfaceTexture;
import android.view.Surface;
import me.lake.librestreaming.tools.LogTools;
package me.lake.librestreaming.render;
/**
* Created by lake on 16-5-3.
*/
public class NativeRender implements IRender {
Surface mVisualSurface;
int mPixelWidth;
int mPixelHeight;
int mPixelSize;
@Override
public void create(SurfaceTexture visualSurfaceTexture, int pixelFormat, int pixelWidth, int pixelHeight, int visualWidth, int visualHeight) {
if (pixelFormat != ImageFormat.NV21) {
throw new IllegalArgumentException("NativeRender,pixelFormat only support NV21");
}
mVisualSurface = new Surface(visualSurfaceTexture);
mPixelWidth = pixelWidth;
mPixelHeight = pixelHeight;
mPixelSize = (3 * pixelWidth * pixelHeight) / 2;
}
@Override
public void update(int visualWidth, int visualHeight) {
}
@Override
public void rendering(byte[] pixel) {
if (mVisualSurface != null && mVisualSurface.isValid()) {
renderingSurface(mVisualSurface, pixel, mPixelWidth, mPixelHeight, mPixelSize);
} else { | LogTools.d("NativeRender,rendering()invalid Surface"); |
bmatthias/config-builder | src/main/java/com/tngtech/configbuilder/util/FieldSetter.java | // Path: src/main/java/com/tngtech/configbuilder/configuration/BuilderConfiguration.java
// public class BuilderConfiguration {
//
// private Properties properties;
// private CommandLine commandLine;
// private Object importedConfiguration;
// private Class<? extends Annotation>[] annotationOrder = new Class[]{CommandLineValue.class, PropertyValue.class, EnvironmentVariableValue.class, SystemPropertyValue.class, ImportedValue.class, DefaultValue.class};
//
// public BuilderConfiguration() {
// properties = new Properties();
// commandLine = null;
// importedConfiguration = null;
// }
//
// public CommandLine getCommandLine() {
// return commandLine;
// }
//
// public Properties getProperties() {
// return properties;
// }
//
// public Object getImportedConfiguration() {
// return importedConfiguration;
// }
//
// public void setProperties(Properties properties) {
// this.properties = properties;
// }
//
// public void setCommandLine(CommandLine commandLine) {
// this.commandLine = commandLine;
// }
//
// public void setImportedConfiguration(Object importedConfiguration) {
// this.importedConfiguration = importedConfiguration;
// }
//
// public void setAnnotationOrder(Class<? extends Annotation>[] annotationOrder) {
// this.annotationOrder = annotationOrder;
// }
//
// public Class<? extends Annotation>[] getAnnotationOrder() {
// return annotationOrder;
// }
// }
//
// Path: src/main/java/com/tngtech/configbuilder/configuration/ErrorMessageSetup.java
// public class ErrorMessageSetup {
//
// private Properties errorMessages;
//
// /**
// * loads the default error messages for the system locale, then merges them with additional error messages loaded with the PropertyLoader
// *
// * @param baseName the filename for additional error messages
// * @param propertyLoader the PropertyLoader used to load additional error messages
// */
// public void initialize(String baseName, PropertyLoader propertyLoader) {
// ResourceBundle resourceBundle = ResourceBundle.getBundle("errors");
// errorMessages = convertResourceBundleToProperties(resourceBundle);
// if (baseName != null) {
// errorMessages.putAll(propertyLoader.load(baseName));
// }
// }
//
// private Properties convertResourceBundleToProperties(ResourceBundle resource) {
// Properties properties = new Properties();
//
// Enumeration<String> keys = resource.getKeys();
// while (keys.hasMoreElements()) {
// String key = keys.nextElement();
// properties.put(key, resource.getString(key));
// }
// return properties;
// }
//
// public String getErrorMessage(Throwable e, String... variables) {
// String message = errorMessages.getProperty(e.getClass().getName());
// return message == null ? String.format(errorMessages.getProperty("standardMessage"), e.getClass().getName()) : String.format(message, variables);
// }
//
// public String getErrorMessage(Class exceptionClass, String... variables) {
// String message = errorMessages.getProperty(exceptionClass.getName());
// return message == null ? String.format(errorMessages.getProperty("standardMessage"), exceptionClass.getName()) : String.format(message, variables);
// }
// }
//
// Path: src/main/java/com/tngtech/configbuilder/exception/ConfigBuilderException.java
// public class ConfigBuilderException extends RuntimeException {
//
// public ConfigBuilderException(String message, Throwable e) {
// super(message, e);
// }
// }
| import com.tngtech.configbuilder.annotation.valueextractor.ValueExtractorAnnotation;
import com.tngtech.configbuilder.configuration.BuilderConfiguration;
import com.tngtech.configbuilder.configuration.ErrorMessageSetup;
import com.tngtech.configbuilder.exception.ConfigBuilderException;
import org.apache.log4j.Logger;
import java.lang.reflect.Field; | package com.tngtech.configbuilder.util;
public class FieldSetter<T> {
private final static Logger log = Logger.getLogger(FieldSetter.class);
private final FieldValueTransformer fieldValueTransformer;
private final FieldValueExtractor fieldValueExtractor; | // Path: src/main/java/com/tngtech/configbuilder/configuration/BuilderConfiguration.java
// public class BuilderConfiguration {
//
// private Properties properties;
// private CommandLine commandLine;
// private Object importedConfiguration;
// private Class<? extends Annotation>[] annotationOrder = new Class[]{CommandLineValue.class, PropertyValue.class, EnvironmentVariableValue.class, SystemPropertyValue.class, ImportedValue.class, DefaultValue.class};
//
// public BuilderConfiguration() {
// properties = new Properties();
// commandLine = null;
// importedConfiguration = null;
// }
//
// public CommandLine getCommandLine() {
// return commandLine;
// }
//
// public Properties getProperties() {
// return properties;
// }
//
// public Object getImportedConfiguration() {
// return importedConfiguration;
// }
//
// public void setProperties(Properties properties) {
// this.properties = properties;
// }
//
// public void setCommandLine(CommandLine commandLine) {
// this.commandLine = commandLine;
// }
//
// public void setImportedConfiguration(Object importedConfiguration) {
// this.importedConfiguration = importedConfiguration;
// }
//
// public void setAnnotationOrder(Class<? extends Annotation>[] annotationOrder) {
// this.annotationOrder = annotationOrder;
// }
//
// public Class<? extends Annotation>[] getAnnotationOrder() {
// return annotationOrder;
// }
// }
//
// Path: src/main/java/com/tngtech/configbuilder/configuration/ErrorMessageSetup.java
// public class ErrorMessageSetup {
//
// private Properties errorMessages;
//
// /**
// * loads the default error messages for the system locale, then merges them with additional error messages loaded with the PropertyLoader
// *
// * @param baseName the filename for additional error messages
// * @param propertyLoader the PropertyLoader used to load additional error messages
// */
// public void initialize(String baseName, PropertyLoader propertyLoader) {
// ResourceBundle resourceBundle = ResourceBundle.getBundle("errors");
// errorMessages = convertResourceBundleToProperties(resourceBundle);
// if (baseName != null) {
// errorMessages.putAll(propertyLoader.load(baseName));
// }
// }
//
// private Properties convertResourceBundleToProperties(ResourceBundle resource) {
// Properties properties = new Properties();
//
// Enumeration<String> keys = resource.getKeys();
// while (keys.hasMoreElements()) {
// String key = keys.nextElement();
// properties.put(key, resource.getString(key));
// }
// return properties;
// }
//
// public String getErrorMessage(Throwable e, String... variables) {
// String message = errorMessages.getProperty(e.getClass().getName());
// return message == null ? String.format(errorMessages.getProperty("standardMessage"), e.getClass().getName()) : String.format(message, variables);
// }
//
// public String getErrorMessage(Class exceptionClass, String... variables) {
// String message = errorMessages.getProperty(exceptionClass.getName());
// return message == null ? String.format(errorMessages.getProperty("standardMessage"), exceptionClass.getName()) : String.format(message, variables);
// }
// }
//
// Path: src/main/java/com/tngtech/configbuilder/exception/ConfigBuilderException.java
// public class ConfigBuilderException extends RuntimeException {
//
// public ConfigBuilderException(String message, Throwable e) {
// super(message, e);
// }
// }
// Path: src/main/java/com/tngtech/configbuilder/util/FieldSetter.java
import com.tngtech.configbuilder.annotation.valueextractor.ValueExtractorAnnotation;
import com.tngtech.configbuilder.configuration.BuilderConfiguration;
import com.tngtech.configbuilder.configuration.ErrorMessageSetup;
import com.tngtech.configbuilder.exception.ConfigBuilderException;
import org.apache.log4j.Logger;
import java.lang.reflect.Field;
package com.tngtech.configbuilder.util;
public class FieldSetter<T> {
private final static Logger log = Logger.getLogger(FieldSetter.class);
private final FieldValueTransformer fieldValueTransformer;
private final FieldValueExtractor fieldValueExtractor; | private final ErrorMessageSetup errorMessageSetup; |
bmatthias/config-builder | src/main/java/com/tngtech/configbuilder/util/FieldSetter.java | // Path: src/main/java/com/tngtech/configbuilder/configuration/BuilderConfiguration.java
// public class BuilderConfiguration {
//
// private Properties properties;
// private CommandLine commandLine;
// private Object importedConfiguration;
// private Class<? extends Annotation>[] annotationOrder = new Class[]{CommandLineValue.class, PropertyValue.class, EnvironmentVariableValue.class, SystemPropertyValue.class, ImportedValue.class, DefaultValue.class};
//
// public BuilderConfiguration() {
// properties = new Properties();
// commandLine = null;
// importedConfiguration = null;
// }
//
// public CommandLine getCommandLine() {
// return commandLine;
// }
//
// public Properties getProperties() {
// return properties;
// }
//
// public Object getImportedConfiguration() {
// return importedConfiguration;
// }
//
// public void setProperties(Properties properties) {
// this.properties = properties;
// }
//
// public void setCommandLine(CommandLine commandLine) {
// this.commandLine = commandLine;
// }
//
// public void setImportedConfiguration(Object importedConfiguration) {
// this.importedConfiguration = importedConfiguration;
// }
//
// public void setAnnotationOrder(Class<? extends Annotation>[] annotationOrder) {
// this.annotationOrder = annotationOrder;
// }
//
// public Class<? extends Annotation>[] getAnnotationOrder() {
// return annotationOrder;
// }
// }
//
// Path: src/main/java/com/tngtech/configbuilder/configuration/ErrorMessageSetup.java
// public class ErrorMessageSetup {
//
// private Properties errorMessages;
//
// /**
// * loads the default error messages for the system locale, then merges them with additional error messages loaded with the PropertyLoader
// *
// * @param baseName the filename for additional error messages
// * @param propertyLoader the PropertyLoader used to load additional error messages
// */
// public void initialize(String baseName, PropertyLoader propertyLoader) {
// ResourceBundle resourceBundle = ResourceBundle.getBundle("errors");
// errorMessages = convertResourceBundleToProperties(resourceBundle);
// if (baseName != null) {
// errorMessages.putAll(propertyLoader.load(baseName));
// }
// }
//
// private Properties convertResourceBundleToProperties(ResourceBundle resource) {
// Properties properties = new Properties();
//
// Enumeration<String> keys = resource.getKeys();
// while (keys.hasMoreElements()) {
// String key = keys.nextElement();
// properties.put(key, resource.getString(key));
// }
// return properties;
// }
//
// public String getErrorMessage(Throwable e, String... variables) {
// String message = errorMessages.getProperty(e.getClass().getName());
// return message == null ? String.format(errorMessages.getProperty("standardMessage"), e.getClass().getName()) : String.format(message, variables);
// }
//
// public String getErrorMessage(Class exceptionClass, String... variables) {
// String message = errorMessages.getProperty(exceptionClass.getName());
// return message == null ? String.format(errorMessages.getProperty("standardMessage"), exceptionClass.getName()) : String.format(message, variables);
// }
// }
//
// Path: src/main/java/com/tngtech/configbuilder/exception/ConfigBuilderException.java
// public class ConfigBuilderException extends RuntimeException {
//
// public ConfigBuilderException(String message, Throwable e) {
// super(message, e);
// }
// }
| import com.tngtech.configbuilder.annotation.valueextractor.ValueExtractorAnnotation;
import com.tngtech.configbuilder.configuration.BuilderConfiguration;
import com.tngtech.configbuilder.configuration.ErrorMessageSetup;
import com.tngtech.configbuilder.exception.ConfigBuilderException;
import org.apache.log4j.Logger;
import java.lang.reflect.Field; | package com.tngtech.configbuilder.util;
public class FieldSetter<T> {
private final static Logger log = Logger.getLogger(FieldSetter.class);
private final FieldValueTransformer fieldValueTransformer;
private final FieldValueExtractor fieldValueExtractor;
private final ErrorMessageSetup errorMessageSetup;
private final AnnotationHelper annotationHelper;
public FieldSetter(ConfigBuilderFactory configBuilderFactory) {
this.annotationHelper = configBuilderFactory.getInstance(AnnotationHelper.class);
this.errorMessageSetup = configBuilderFactory.getInstance(ErrorMessageSetup.class);
this.fieldValueTransformer = configBuilderFactory.getInstance(FieldValueTransformer.class);
this.fieldValueExtractor = configBuilderFactory.getInstance(FieldValueExtractor.class);
}
| // Path: src/main/java/com/tngtech/configbuilder/configuration/BuilderConfiguration.java
// public class BuilderConfiguration {
//
// private Properties properties;
// private CommandLine commandLine;
// private Object importedConfiguration;
// private Class<? extends Annotation>[] annotationOrder = new Class[]{CommandLineValue.class, PropertyValue.class, EnvironmentVariableValue.class, SystemPropertyValue.class, ImportedValue.class, DefaultValue.class};
//
// public BuilderConfiguration() {
// properties = new Properties();
// commandLine = null;
// importedConfiguration = null;
// }
//
// public CommandLine getCommandLine() {
// return commandLine;
// }
//
// public Properties getProperties() {
// return properties;
// }
//
// public Object getImportedConfiguration() {
// return importedConfiguration;
// }
//
// public void setProperties(Properties properties) {
// this.properties = properties;
// }
//
// public void setCommandLine(CommandLine commandLine) {
// this.commandLine = commandLine;
// }
//
// public void setImportedConfiguration(Object importedConfiguration) {
// this.importedConfiguration = importedConfiguration;
// }
//
// public void setAnnotationOrder(Class<? extends Annotation>[] annotationOrder) {
// this.annotationOrder = annotationOrder;
// }
//
// public Class<? extends Annotation>[] getAnnotationOrder() {
// return annotationOrder;
// }
// }
//
// Path: src/main/java/com/tngtech/configbuilder/configuration/ErrorMessageSetup.java
// public class ErrorMessageSetup {
//
// private Properties errorMessages;
//
// /**
// * loads the default error messages for the system locale, then merges them with additional error messages loaded with the PropertyLoader
// *
// * @param baseName the filename for additional error messages
// * @param propertyLoader the PropertyLoader used to load additional error messages
// */
// public void initialize(String baseName, PropertyLoader propertyLoader) {
// ResourceBundle resourceBundle = ResourceBundle.getBundle("errors");
// errorMessages = convertResourceBundleToProperties(resourceBundle);
// if (baseName != null) {
// errorMessages.putAll(propertyLoader.load(baseName));
// }
// }
//
// private Properties convertResourceBundleToProperties(ResourceBundle resource) {
// Properties properties = new Properties();
//
// Enumeration<String> keys = resource.getKeys();
// while (keys.hasMoreElements()) {
// String key = keys.nextElement();
// properties.put(key, resource.getString(key));
// }
// return properties;
// }
//
// public String getErrorMessage(Throwable e, String... variables) {
// String message = errorMessages.getProperty(e.getClass().getName());
// return message == null ? String.format(errorMessages.getProperty("standardMessage"), e.getClass().getName()) : String.format(message, variables);
// }
//
// public String getErrorMessage(Class exceptionClass, String... variables) {
// String message = errorMessages.getProperty(exceptionClass.getName());
// return message == null ? String.format(errorMessages.getProperty("standardMessage"), exceptionClass.getName()) : String.format(message, variables);
// }
// }
//
// Path: src/main/java/com/tngtech/configbuilder/exception/ConfigBuilderException.java
// public class ConfigBuilderException extends RuntimeException {
//
// public ConfigBuilderException(String message, Throwable e) {
// super(message, e);
// }
// }
// Path: src/main/java/com/tngtech/configbuilder/util/FieldSetter.java
import com.tngtech.configbuilder.annotation.valueextractor.ValueExtractorAnnotation;
import com.tngtech.configbuilder.configuration.BuilderConfiguration;
import com.tngtech.configbuilder.configuration.ErrorMessageSetup;
import com.tngtech.configbuilder.exception.ConfigBuilderException;
import org.apache.log4j.Logger;
import java.lang.reflect.Field;
package com.tngtech.configbuilder.util;
public class FieldSetter<T> {
private final static Logger log = Logger.getLogger(FieldSetter.class);
private final FieldValueTransformer fieldValueTransformer;
private final FieldValueExtractor fieldValueExtractor;
private final ErrorMessageSetup errorMessageSetup;
private final AnnotationHelper annotationHelper;
public FieldSetter(ConfigBuilderFactory configBuilderFactory) {
this.annotationHelper = configBuilderFactory.getInstance(AnnotationHelper.class);
this.errorMessageSetup = configBuilderFactory.getInstance(ErrorMessageSetup.class);
this.fieldValueTransformer = configBuilderFactory.getInstance(FieldValueTransformer.class);
this.fieldValueExtractor = configBuilderFactory.getInstance(FieldValueExtractor.class);
}
| public void setFields(T instanceOfConfigClass, BuilderConfiguration builderConfiguration) { |
bmatthias/config-builder | src/main/java/com/tngtech/configbuilder/util/FieldSetter.java | // Path: src/main/java/com/tngtech/configbuilder/configuration/BuilderConfiguration.java
// public class BuilderConfiguration {
//
// private Properties properties;
// private CommandLine commandLine;
// private Object importedConfiguration;
// private Class<? extends Annotation>[] annotationOrder = new Class[]{CommandLineValue.class, PropertyValue.class, EnvironmentVariableValue.class, SystemPropertyValue.class, ImportedValue.class, DefaultValue.class};
//
// public BuilderConfiguration() {
// properties = new Properties();
// commandLine = null;
// importedConfiguration = null;
// }
//
// public CommandLine getCommandLine() {
// return commandLine;
// }
//
// public Properties getProperties() {
// return properties;
// }
//
// public Object getImportedConfiguration() {
// return importedConfiguration;
// }
//
// public void setProperties(Properties properties) {
// this.properties = properties;
// }
//
// public void setCommandLine(CommandLine commandLine) {
// this.commandLine = commandLine;
// }
//
// public void setImportedConfiguration(Object importedConfiguration) {
// this.importedConfiguration = importedConfiguration;
// }
//
// public void setAnnotationOrder(Class<? extends Annotation>[] annotationOrder) {
// this.annotationOrder = annotationOrder;
// }
//
// public Class<? extends Annotation>[] getAnnotationOrder() {
// return annotationOrder;
// }
// }
//
// Path: src/main/java/com/tngtech/configbuilder/configuration/ErrorMessageSetup.java
// public class ErrorMessageSetup {
//
// private Properties errorMessages;
//
// /**
// * loads the default error messages for the system locale, then merges them with additional error messages loaded with the PropertyLoader
// *
// * @param baseName the filename for additional error messages
// * @param propertyLoader the PropertyLoader used to load additional error messages
// */
// public void initialize(String baseName, PropertyLoader propertyLoader) {
// ResourceBundle resourceBundle = ResourceBundle.getBundle("errors");
// errorMessages = convertResourceBundleToProperties(resourceBundle);
// if (baseName != null) {
// errorMessages.putAll(propertyLoader.load(baseName));
// }
// }
//
// private Properties convertResourceBundleToProperties(ResourceBundle resource) {
// Properties properties = new Properties();
//
// Enumeration<String> keys = resource.getKeys();
// while (keys.hasMoreElements()) {
// String key = keys.nextElement();
// properties.put(key, resource.getString(key));
// }
// return properties;
// }
//
// public String getErrorMessage(Throwable e, String... variables) {
// String message = errorMessages.getProperty(e.getClass().getName());
// return message == null ? String.format(errorMessages.getProperty("standardMessage"), e.getClass().getName()) : String.format(message, variables);
// }
//
// public String getErrorMessage(Class exceptionClass, String... variables) {
// String message = errorMessages.getProperty(exceptionClass.getName());
// return message == null ? String.format(errorMessages.getProperty("standardMessage"), exceptionClass.getName()) : String.format(message, variables);
// }
// }
//
// Path: src/main/java/com/tngtech/configbuilder/exception/ConfigBuilderException.java
// public class ConfigBuilderException extends RuntimeException {
//
// public ConfigBuilderException(String message, Throwable e) {
// super(message, e);
// }
// }
| import com.tngtech.configbuilder.annotation.valueextractor.ValueExtractorAnnotation;
import com.tngtech.configbuilder.configuration.BuilderConfiguration;
import com.tngtech.configbuilder.configuration.ErrorMessageSetup;
import com.tngtech.configbuilder.exception.ConfigBuilderException;
import org.apache.log4j.Logger;
import java.lang.reflect.Field; | this.annotationHelper = configBuilderFactory.getInstance(AnnotationHelper.class);
this.errorMessageSetup = configBuilderFactory.getInstance(ErrorMessageSetup.class);
this.fieldValueTransformer = configBuilderFactory.getInstance(FieldValueTransformer.class);
this.fieldValueExtractor = configBuilderFactory.getInstance(FieldValueExtractor.class);
}
public void setFields(T instanceOfConfigClass, BuilderConfiguration builderConfiguration) {
for (Field field : instanceOfConfigClass.getClass().getDeclaredFields()) {
if (annotationHelper.fieldHasAnnotationAnnotatedWith(field, ValueExtractorAnnotation.class)) {
Object value = fieldValueExtractor.extractValue(field, builderConfiguration);
value = fieldValueTransformer.transformFieldValue(field, value);
setField(instanceOfConfigClass, field, value);
} else {
log.debug(String.format("field %s is not annotated with any ValueExtractorAnnotation: skipping field", field.getName()));
}
}
}
private void setField(T instanceOfConfigClass, Field field, Object value) {
try {
field.setAccessible(true);
if(value == null && field.getType().isPrimitive()) {
log.warn(String.format("no value found for field %s of primitive type %s: field will be initialized to default", field.getName(), field.getType().getName()));
}
else {
field.set(instanceOfConfigClass, value);
log.info(String.format("set field %s of type %s to a value of type %s", field.getName(), field.getType().getName(), value == null ? "null" : value.getClass().getName()));
}
} catch (Exception e) { | // Path: src/main/java/com/tngtech/configbuilder/configuration/BuilderConfiguration.java
// public class BuilderConfiguration {
//
// private Properties properties;
// private CommandLine commandLine;
// private Object importedConfiguration;
// private Class<? extends Annotation>[] annotationOrder = new Class[]{CommandLineValue.class, PropertyValue.class, EnvironmentVariableValue.class, SystemPropertyValue.class, ImportedValue.class, DefaultValue.class};
//
// public BuilderConfiguration() {
// properties = new Properties();
// commandLine = null;
// importedConfiguration = null;
// }
//
// public CommandLine getCommandLine() {
// return commandLine;
// }
//
// public Properties getProperties() {
// return properties;
// }
//
// public Object getImportedConfiguration() {
// return importedConfiguration;
// }
//
// public void setProperties(Properties properties) {
// this.properties = properties;
// }
//
// public void setCommandLine(CommandLine commandLine) {
// this.commandLine = commandLine;
// }
//
// public void setImportedConfiguration(Object importedConfiguration) {
// this.importedConfiguration = importedConfiguration;
// }
//
// public void setAnnotationOrder(Class<? extends Annotation>[] annotationOrder) {
// this.annotationOrder = annotationOrder;
// }
//
// public Class<? extends Annotation>[] getAnnotationOrder() {
// return annotationOrder;
// }
// }
//
// Path: src/main/java/com/tngtech/configbuilder/configuration/ErrorMessageSetup.java
// public class ErrorMessageSetup {
//
// private Properties errorMessages;
//
// /**
// * loads the default error messages for the system locale, then merges them with additional error messages loaded with the PropertyLoader
// *
// * @param baseName the filename for additional error messages
// * @param propertyLoader the PropertyLoader used to load additional error messages
// */
// public void initialize(String baseName, PropertyLoader propertyLoader) {
// ResourceBundle resourceBundle = ResourceBundle.getBundle("errors");
// errorMessages = convertResourceBundleToProperties(resourceBundle);
// if (baseName != null) {
// errorMessages.putAll(propertyLoader.load(baseName));
// }
// }
//
// private Properties convertResourceBundleToProperties(ResourceBundle resource) {
// Properties properties = new Properties();
//
// Enumeration<String> keys = resource.getKeys();
// while (keys.hasMoreElements()) {
// String key = keys.nextElement();
// properties.put(key, resource.getString(key));
// }
// return properties;
// }
//
// public String getErrorMessage(Throwable e, String... variables) {
// String message = errorMessages.getProperty(e.getClass().getName());
// return message == null ? String.format(errorMessages.getProperty("standardMessage"), e.getClass().getName()) : String.format(message, variables);
// }
//
// public String getErrorMessage(Class exceptionClass, String... variables) {
// String message = errorMessages.getProperty(exceptionClass.getName());
// return message == null ? String.format(errorMessages.getProperty("standardMessage"), exceptionClass.getName()) : String.format(message, variables);
// }
// }
//
// Path: src/main/java/com/tngtech/configbuilder/exception/ConfigBuilderException.java
// public class ConfigBuilderException extends RuntimeException {
//
// public ConfigBuilderException(String message, Throwable e) {
// super(message, e);
// }
// }
// Path: src/main/java/com/tngtech/configbuilder/util/FieldSetter.java
import com.tngtech.configbuilder.annotation.valueextractor.ValueExtractorAnnotation;
import com.tngtech.configbuilder.configuration.BuilderConfiguration;
import com.tngtech.configbuilder.configuration.ErrorMessageSetup;
import com.tngtech.configbuilder.exception.ConfigBuilderException;
import org.apache.log4j.Logger;
import java.lang.reflect.Field;
this.annotationHelper = configBuilderFactory.getInstance(AnnotationHelper.class);
this.errorMessageSetup = configBuilderFactory.getInstance(ErrorMessageSetup.class);
this.fieldValueTransformer = configBuilderFactory.getInstance(FieldValueTransformer.class);
this.fieldValueExtractor = configBuilderFactory.getInstance(FieldValueExtractor.class);
}
public void setFields(T instanceOfConfigClass, BuilderConfiguration builderConfiguration) {
for (Field field : instanceOfConfigClass.getClass().getDeclaredFields()) {
if (annotationHelper.fieldHasAnnotationAnnotatedWith(field, ValueExtractorAnnotation.class)) {
Object value = fieldValueExtractor.extractValue(field, builderConfiguration);
value = fieldValueTransformer.transformFieldValue(field, value);
setField(instanceOfConfigClass, field, value);
} else {
log.debug(String.format("field %s is not annotated with any ValueExtractorAnnotation: skipping field", field.getName()));
}
}
}
private void setField(T instanceOfConfigClass, Field field, Object value) {
try {
field.setAccessible(true);
if(value == null && field.getType().isPrimitive()) {
log.warn(String.format("no value found for field %s of primitive type %s: field will be initialized to default", field.getName(), field.getType().getName()));
}
else {
field.set(instanceOfConfigClass, value);
log.info(String.format("set field %s of type %s to a value of type %s", field.getName(), field.getType().getName(), value == null ? "null" : value.getClass().getName()));
}
} catch (Exception e) { | throw new ConfigBuilderException(errorMessageSetup.getErrorMessage(e, field.getName(), field.getType().getName(), value == null ? "null" : value.toString()), e); |
bmatthias/config-builder | src/test/java/com/tngtech/configbuilder/util/FieldValueTransformerComponentTest.java | // Path: src/main/java/com/tngtech/configbuilder/configuration/BuilderConfiguration.java
// public class BuilderConfiguration {
//
// private Properties properties;
// private CommandLine commandLine;
// private Object importedConfiguration;
// private Class<? extends Annotation>[] annotationOrder = new Class[]{CommandLineValue.class, PropertyValue.class, EnvironmentVariableValue.class, SystemPropertyValue.class, ImportedValue.class, DefaultValue.class};
//
// public BuilderConfiguration() {
// properties = new Properties();
// commandLine = null;
// importedConfiguration = null;
// }
//
// public CommandLine getCommandLine() {
// return commandLine;
// }
//
// public Properties getProperties() {
// return properties;
// }
//
// public Object getImportedConfiguration() {
// return importedConfiguration;
// }
//
// public void setProperties(Properties properties) {
// this.properties = properties;
// }
//
// public void setCommandLine(CommandLine commandLine) {
// this.commandLine = commandLine;
// }
//
// public void setImportedConfiguration(Object importedConfiguration) {
// this.importedConfiguration = importedConfiguration;
// }
//
// public void setAnnotationOrder(Class<? extends Annotation>[] annotationOrder) {
// this.annotationOrder = annotationOrder;
// }
//
// public Class<? extends Annotation>[] getAnnotationOrder() {
// return annotationOrder;
// }
// }
//
// Path: src/main/java/com/tngtech/configbuilder/configuration/ErrorMessageSetup.java
// public class ErrorMessageSetup {
//
// private Properties errorMessages;
//
// /**
// * loads the default error messages for the system locale, then merges them with additional error messages loaded with the PropertyLoader
// *
// * @param baseName the filename for additional error messages
// * @param propertyLoader the PropertyLoader used to load additional error messages
// */
// public void initialize(String baseName, PropertyLoader propertyLoader) {
// ResourceBundle resourceBundle = ResourceBundle.getBundle("errors");
// errorMessages = convertResourceBundleToProperties(resourceBundle);
// if (baseName != null) {
// errorMessages.putAll(propertyLoader.load(baseName));
// }
// }
//
// private Properties convertResourceBundleToProperties(ResourceBundle resource) {
// Properties properties = new Properties();
//
// Enumeration<String> keys = resource.getKeys();
// while (keys.hasMoreElements()) {
// String key = keys.nextElement();
// properties.put(key, resource.getString(key));
// }
// return properties;
// }
//
// public String getErrorMessage(Throwable e, String... variables) {
// String message = errorMessages.getProperty(e.getClass().getName());
// return message == null ? String.format(errorMessages.getProperty("standardMessage"), e.getClass().getName()) : String.format(message, variables);
// }
//
// public String getErrorMessage(Class exceptionClass, String... variables) {
// String message = errorMessages.getProperty(exceptionClass.getName());
// return message == null ? String.format(errorMessages.getProperty("standardMessage"), exceptionClass.getName()) : String.format(message, variables);
// }
// }
//
// Path: src/main/java/com/tngtech/configbuilder/exception/PrimitiveParsingException.java
// public class PrimitiveParsingException extends RuntimeException {
// public PrimitiveParsingException(String errorMessage) {
// super(errorMessage);
// }
// }
| import com.google.common.collect.Lists;
import com.tngtech.configbuilder.annotation.valuetransformer.*;
import com.tngtech.configbuilder.configuration.BuilderConfiguration;
import com.tngtech.configbuilder.configuration.ErrorMessageSetup;
import com.tngtech.configbuilder.exception.PrimitiveParsingException;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import java.lang.reflect.Field;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Collection;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when; |
@Override
public Integer transform(String argument) {
return 1472;
}
}
private class TestConfigClass {
@ValueTransformers({CharacterSeparatedStringToStringListTransformer.class})
private Collection<String> stringCollectionField;
private int intField;
private double doubleField;
private Boolean boolField;
@ValueTransformers({TestTransformer.class})
private int otherIntField;
@ValueTransformers({AnotherTestTransformer.class})
private Integer integerField;
private Collection<Path> pathCollectionField;
private Collection<Integer> integerCollectionField;
private Collection<Object> objectCollectionField;
}
@Mock
private ConfigBuilderFactory configBuilderFactory;
@Mock
private FieldValueExtractor fieldValueExtractor;
@Mock | // Path: src/main/java/com/tngtech/configbuilder/configuration/BuilderConfiguration.java
// public class BuilderConfiguration {
//
// private Properties properties;
// private CommandLine commandLine;
// private Object importedConfiguration;
// private Class<? extends Annotation>[] annotationOrder = new Class[]{CommandLineValue.class, PropertyValue.class, EnvironmentVariableValue.class, SystemPropertyValue.class, ImportedValue.class, DefaultValue.class};
//
// public BuilderConfiguration() {
// properties = new Properties();
// commandLine = null;
// importedConfiguration = null;
// }
//
// public CommandLine getCommandLine() {
// return commandLine;
// }
//
// public Properties getProperties() {
// return properties;
// }
//
// public Object getImportedConfiguration() {
// return importedConfiguration;
// }
//
// public void setProperties(Properties properties) {
// this.properties = properties;
// }
//
// public void setCommandLine(CommandLine commandLine) {
// this.commandLine = commandLine;
// }
//
// public void setImportedConfiguration(Object importedConfiguration) {
// this.importedConfiguration = importedConfiguration;
// }
//
// public void setAnnotationOrder(Class<? extends Annotation>[] annotationOrder) {
// this.annotationOrder = annotationOrder;
// }
//
// public Class<? extends Annotation>[] getAnnotationOrder() {
// return annotationOrder;
// }
// }
//
// Path: src/main/java/com/tngtech/configbuilder/configuration/ErrorMessageSetup.java
// public class ErrorMessageSetup {
//
// private Properties errorMessages;
//
// /**
// * loads the default error messages for the system locale, then merges them with additional error messages loaded with the PropertyLoader
// *
// * @param baseName the filename for additional error messages
// * @param propertyLoader the PropertyLoader used to load additional error messages
// */
// public void initialize(String baseName, PropertyLoader propertyLoader) {
// ResourceBundle resourceBundle = ResourceBundle.getBundle("errors");
// errorMessages = convertResourceBundleToProperties(resourceBundle);
// if (baseName != null) {
// errorMessages.putAll(propertyLoader.load(baseName));
// }
// }
//
// private Properties convertResourceBundleToProperties(ResourceBundle resource) {
// Properties properties = new Properties();
//
// Enumeration<String> keys = resource.getKeys();
// while (keys.hasMoreElements()) {
// String key = keys.nextElement();
// properties.put(key, resource.getString(key));
// }
// return properties;
// }
//
// public String getErrorMessage(Throwable e, String... variables) {
// String message = errorMessages.getProperty(e.getClass().getName());
// return message == null ? String.format(errorMessages.getProperty("standardMessage"), e.getClass().getName()) : String.format(message, variables);
// }
//
// public String getErrorMessage(Class exceptionClass, String... variables) {
// String message = errorMessages.getProperty(exceptionClass.getName());
// return message == null ? String.format(errorMessages.getProperty("standardMessage"), exceptionClass.getName()) : String.format(message, variables);
// }
// }
//
// Path: src/main/java/com/tngtech/configbuilder/exception/PrimitiveParsingException.java
// public class PrimitiveParsingException extends RuntimeException {
// public PrimitiveParsingException(String errorMessage) {
// super(errorMessage);
// }
// }
// Path: src/test/java/com/tngtech/configbuilder/util/FieldValueTransformerComponentTest.java
import com.google.common.collect.Lists;
import com.tngtech.configbuilder.annotation.valuetransformer.*;
import com.tngtech.configbuilder.configuration.BuilderConfiguration;
import com.tngtech.configbuilder.configuration.ErrorMessageSetup;
import com.tngtech.configbuilder.exception.PrimitiveParsingException;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import java.lang.reflect.Field;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Collection;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@Override
public Integer transform(String argument) {
return 1472;
}
}
private class TestConfigClass {
@ValueTransformers({CharacterSeparatedStringToStringListTransformer.class})
private Collection<String> stringCollectionField;
private int intField;
private double doubleField;
private Boolean boolField;
@ValueTransformers({TestTransformer.class})
private int otherIntField;
@ValueTransformers({AnotherTestTransformer.class})
private Integer integerField;
private Collection<Path> pathCollectionField;
private Collection<Integer> integerCollectionField;
private Collection<Object> objectCollectionField;
}
@Mock
private ConfigBuilderFactory configBuilderFactory;
@Mock
private FieldValueExtractor fieldValueExtractor;
@Mock | private ErrorMessageSetup errorMessageSetup; |
bmatthias/config-builder | src/test/java/com/tngtech/configbuilder/util/FieldValueTransformerComponentTest.java | // Path: src/main/java/com/tngtech/configbuilder/configuration/BuilderConfiguration.java
// public class BuilderConfiguration {
//
// private Properties properties;
// private CommandLine commandLine;
// private Object importedConfiguration;
// private Class<? extends Annotation>[] annotationOrder = new Class[]{CommandLineValue.class, PropertyValue.class, EnvironmentVariableValue.class, SystemPropertyValue.class, ImportedValue.class, DefaultValue.class};
//
// public BuilderConfiguration() {
// properties = new Properties();
// commandLine = null;
// importedConfiguration = null;
// }
//
// public CommandLine getCommandLine() {
// return commandLine;
// }
//
// public Properties getProperties() {
// return properties;
// }
//
// public Object getImportedConfiguration() {
// return importedConfiguration;
// }
//
// public void setProperties(Properties properties) {
// this.properties = properties;
// }
//
// public void setCommandLine(CommandLine commandLine) {
// this.commandLine = commandLine;
// }
//
// public void setImportedConfiguration(Object importedConfiguration) {
// this.importedConfiguration = importedConfiguration;
// }
//
// public void setAnnotationOrder(Class<? extends Annotation>[] annotationOrder) {
// this.annotationOrder = annotationOrder;
// }
//
// public Class<? extends Annotation>[] getAnnotationOrder() {
// return annotationOrder;
// }
// }
//
// Path: src/main/java/com/tngtech/configbuilder/configuration/ErrorMessageSetup.java
// public class ErrorMessageSetup {
//
// private Properties errorMessages;
//
// /**
// * loads the default error messages for the system locale, then merges them with additional error messages loaded with the PropertyLoader
// *
// * @param baseName the filename for additional error messages
// * @param propertyLoader the PropertyLoader used to load additional error messages
// */
// public void initialize(String baseName, PropertyLoader propertyLoader) {
// ResourceBundle resourceBundle = ResourceBundle.getBundle("errors");
// errorMessages = convertResourceBundleToProperties(resourceBundle);
// if (baseName != null) {
// errorMessages.putAll(propertyLoader.load(baseName));
// }
// }
//
// private Properties convertResourceBundleToProperties(ResourceBundle resource) {
// Properties properties = new Properties();
//
// Enumeration<String> keys = resource.getKeys();
// while (keys.hasMoreElements()) {
// String key = keys.nextElement();
// properties.put(key, resource.getString(key));
// }
// return properties;
// }
//
// public String getErrorMessage(Throwable e, String... variables) {
// String message = errorMessages.getProperty(e.getClass().getName());
// return message == null ? String.format(errorMessages.getProperty("standardMessage"), e.getClass().getName()) : String.format(message, variables);
// }
//
// public String getErrorMessage(Class exceptionClass, String... variables) {
// String message = errorMessages.getProperty(exceptionClass.getName());
// return message == null ? String.format(errorMessages.getProperty("standardMessage"), exceptionClass.getName()) : String.format(message, variables);
// }
// }
//
// Path: src/main/java/com/tngtech/configbuilder/exception/PrimitiveParsingException.java
// public class PrimitiveParsingException extends RuntimeException {
// public PrimitiveParsingException(String errorMessage) {
// super(errorMessage);
// }
// }
| import com.google.common.collect.Lists;
import com.tngtech.configbuilder.annotation.valuetransformer.*;
import com.tngtech.configbuilder.configuration.BuilderConfiguration;
import com.tngtech.configbuilder.configuration.ErrorMessageSetup;
import com.tngtech.configbuilder.exception.PrimitiveParsingException;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import java.lang.reflect.Field;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Collection;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when; | return 1472;
}
}
private class TestConfigClass {
@ValueTransformers({CharacterSeparatedStringToStringListTransformer.class})
private Collection<String> stringCollectionField;
private int intField;
private double doubleField;
private Boolean boolField;
@ValueTransformers({TestTransformer.class})
private int otherIntField;
@ValueTransformers({AnotherTestTransformer.class})
private Integer integerField;
private Collection<Path> pathCollectionField;
private Collection<Integer> integerCollectionField;
private Collection<Object> objectCollectionField;
}
@Mock
private ConfigBuilderFactory configBuilderFactory;
@Mock
private FieldValueExtractor fieldValueExtractor;
@Mock
private ErrorMessageSetup errorMessageSetup;
@Mock | // Path: src/main/java/com/tngtech/configbuilder/configuration/BuilderConfiguration.java
// public class BuilderConfiguration {
//
// private Properties properties;
// private CommandLine commandLine;
// private Object importedConfiguration;
// private Class<? extends Annotation>[] annotationOrder = new Class[]{CommandLineValue.class, PropertyValue.class, EnvironmentVariableValue.class, SystemPropertyValue.class, ImportedValue.class, DefaultValue.class};
//
// public BuilderConfiguration() {
// properties = new Properties();
// commandLine = null;
// importedConfiguration = null;
// }
//
// public CommandLine getCommandLine() {
// return commandLine;
// }
//
// public Properties getProperties() {
// return properties;
// }
//
// public Object getImportedConfiguration() {
// return importedConfiguration;
// }
//
// public void setProperties(Properties properties) {
// this.properties = properties;
// }
//
// public void setCommandLine(CommandLine commandLine) {
// this.commandLine = commandLine;
// }
//
// public void setImportedConfiguration(Object importedConfiguration) {
// this.importedConfiguration = importedConfiguration;
// }
//
// public void setAnnotationOrder(Class<? extends Annotation>[] annotationOrder) {
// this.annotationOrder = annotationOrder;
// }
//
// public Class<? extends Annotation>[] getAnnotationOrder() {
// return annotationOrder;
// }
// }
//
// Path: src/main/java/com/tngtech/configbuilder/configuration/ErrorMessageSetup.java
// public class ErrorMessageSetup {
//
// private Properties errorMessages;
//
// /**
// * loads the default error messages for the system locale, then merges them with additional error messages loaded with the PropertyLoader
// *
// * @param baseName the filename for additional error messages
// * @param propertyLoader the PropertyLoader used to load additional error messages
// */
// public void initialize(String baseName, PropertyLoader propertyLoader) {
// ResourceBundle resourceBundle = ResourceBundle.getBundle("errors");
// errorMessages = convertResourceBundleToProperties(resourceBundle);
// if (baseName != null) {
// errorMessages.putAll(propertyLoader.load(baseName));
// }
// }
//
// private Properties convertResourceBundleToProperties(ResourceBundle resource) {
// Properties properties = new Properties();
//
// Enumeration<String> keys = resource.getKeys();
// while (keys.hasMoreElements()) {
// String key = keys.nextElement();
// properties.put(key, resource.getString(key));
// }
// return properties;
// }
//
// public String getErrorMessage(Throwable e, String... variables) {
// String message = errorMessages.getProperty(e.getClass().getName());
// return message == null ? String.format(errorMessages.getProperty("standardMessage"), e.getClass().getName()) : String.format(message, variables);
// }
//
// public String getErrorMessage(Class exceptionClass, String... variables) {
// String message = errorMessages.getProperty(exceptionClass.getName());
// return message == null ? String.format(errorMessages.getProperty("standardMessage"), exceptionClass.getName()) : String.format(message, variables);
// }
// }
//
// Path: src/main/java/com/tngtech/configbuilder/exception/PrimitiveParsingException.java
// public class PrimitiveParsingException extends RuntimeException {
// public PrimitiveParsingException(String errorMessage) {
// super(errorMessage);
// }
// }
// Path: src/test/java/com/tngtech/configbuilder/util/FieldValueTransformerComponentTest.java
import com.google.common.collect.Lists;
import com.tngtech.configbuilder.annotation.valuetransformer.*;
import com.tngtech.configbuilder.configuration.BuilderConfiguration;
import com.tngtech.configbuilder.configuration.ErrorMessageSetup;
import com.tngtech.configbuilder.exception.PrimitiveParsingException;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import java.lang.reflect.Field;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Collection;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
return 1472;
}
}
private class TestConfigClass {
@ValueTransformers({CharacterSeparatedStringToStringListTransformer.class})
private Collection<String> stringCollectionField;
private int intField;
private double doubleField;
private Boolean boolField;
@ValueTransformers({TestTransformer.class})
private int otherIntField;
@ValueTransformers({AnotherTestTransformer.class})
private Integer integerField;
private Collection<Path> pathCollectionField;
private Collection<Integer> integerCollectionField;
private Collection<Object> objectCollectionField;
}
@Mock
private ConfigBuilderFactory configBuilderFactory;
@Mock
private FieldValueExtractor fieldValueExtractor;
@Mock
private ErrorMessageSetup errorMessageSetup;
@Mock | private BuilderConfiguration builderConfiguration; |
bmatthias/config-builder | src/test/java/com/tngtech/configbuilder/util/FieldValueTransformerComponentTest.java | // Path: src/main/java/com/tngtech/configbuilder/configuration/BuilderConfiguration.java
// public class BuilderConfiguration {
//
// private Properties properties;
// private CommandLine commandLine;
// private Object importedConfiguration;
// private Class<? extends Annotation>[] annotationOrder = new Class[]{CommandLineValue.class, PropertyValue.class, EnvironmentVariableValue.class, SystemPropertyValue.class, ImportedValue.class, DefaultValue.class};
//
// public BuilderConfiguration() {
// properties = new Properties();
// commandLine = null;
// importedConfiguration = null;
// }
//
// public CommandLine getCommandLine() {
// return commandLine;
// }
//
// public Properties getProperties() {
// return properties;
// }
//
// public Object getImportedConfiguration() {
// return importedConfiguration;
// }
//
// public void setProperties(Properties properties) {
// this.properties = properties;
// }
//
// public void setCommandLine(CommandLine commandLine) {
// this.commandLine = commandLine;
// }
//
// public void setImportedConfiguration(Object importedConfiguration) {
// this.importedConfiguration = importedConfiguration;
// }
//
// public void setAnnotationOrder(Class<? extends Annotation>[] annotationOrder) {
// this.annotationOrder = annotationOrder;
// }
//
// public Class<? extends Annotation>[] getAnnotationOrder() {
// return annotationOrder;
// }
// }
//
// Path: src/main/java/com/tngtech/configbuilder/configuration/ErrorMessageSetup.java
// public class ErrorMessageSetup {
//
// private Properties errorMessages;
//
// /**
// * loads the default error messages for the system locale, then merges them with additional error messages loaded with the PropertyLoader
// *
// * @param baseName the filename for additional error messages
// * @param propertyLoader the PropertyLoader used to load additional error messages
// */
// public void initialize(String baseName, PropertyLoader propertyLoader) {
// ResourceBundle resourceBundle = ResourceBundle.getBundle("errors");
// errorMessages = convertResourceBundleToProperties(resourceBundle);
// if (baseName != null) {
// errorMessages.putAll(propertyLoader.load(baseName));
// }
// }
//
// private Properties convertResourceBundleToProperties(ResourceBundle resource) {
// Properties properties = new Properties();
//
// Enumeration<String> keys = resource.getKeys();
// while (keys.hasMoreElements()) {
// String key = keys.nextElement();
// properties.put(key, resource.getString(key));
// }
// return properties;
// }
//
// public String getErrorMessage(Throwable e, String... variables) {
// String message = errorMessages.getProperty(e.getClass().getName());
// return message == null ? String.format(errorMessages.getProperty("standardMessage"), e.getClass().getName()) : String.format(message, variables);
// }
//
// public String getErrorMessage(Class exceptionClass, String... variables) {
// String message = errorMessages.getProperty(exceptionClass.getName());
// return message == null ? String.format(errorMessages.getProperty("standardMessage"), exceptionClass.getName()) : String.format(message, variables);
// }
// }
//
// Path: src/main/java/com/tngtech/configbuilder/exception/PrimitiveParsingException.java
// public class PrimitiveParsingException extends RuntimeException {
// public PrimitiveParsingException(String errorMessage) {
// super(errorMessage);
// }
// }
| import com.google.common.collect.Lists;
import com.tngtech.configbuilder.annotation.valuetransformer.*;
import com.tngtech.configbuilder.configuration.BuilderConfiguration;
import com.tngtech.configbuilder.configuration.ErrorMessageSetup;
import com.tngtech.configbuilder.exception.PrimitiveParsingException;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import java.lang.reflect.Field;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Collection;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when; | boolField = TestConfigClass.class.getDeclaredField("boolField");
otherIntField = TestConfigClass.class.getDeclaredField("otherIntField");
integerField = TestConfigClass.class.getDeclaredField("integerField");
pathCollectionField = TestConfigClass.class.getDeclaredField("pathCollectionField");
integerCollectionField = TestConfigClass.class.getDeclaredField("integerCollectionField");
doubleField = TestConfigClass.class.getDeclaredField("doubleField");
objectCollectionField = TestConfigClass.class.getDeclaredField("objectCollectionField");
this.fieldValueTransformer = new FieldValueTransformer(configBuilderFactory);
}
@Test
public void testTransformingStringToStringCollection() {
ArrayList<String> actualResult = (ArrayList<String>)fieldValueTransformer.transformFieldValue(stringCollectionField, "Alpha,Beta,Gamma");
assertEquals(Lists.newArrayList("Alpha","Beta","Gamma"), actualResult);
}
@Test
public void testTransformingStringToInt() {
Object actualResult = fieldValueTransformer.transformFieldValue(intField, "17");
assertEquals(17, actualResult);
}
@Test
public void testTransformingIntegerToDouble() {
Object actualResult = fieldValueTransformer.transformFieldValue(doubleField, 17);
assertEquals(17.0, actualResult);
}
| // Path: src/main/java/com/tngtech/configbuilder/configuration/BuilderConfiguration.java
// public class BuilderConfiguration {
//
// private Properties properties;
// private CommandLine commandLine;
// private Object importedConfiguration;
// private Class<? extends Annotation>[] annotationOrder = new Class[]{CommandLineValue.class, PropertyValue.class, EnvironmentVariableValue.class, SystemPropertyValue.class, ImportedValue.class, DefaultValue.class};
//
// public BuilderConfiguration() {
// properties = new Properties();
// commandLine = null;
// importedConfiguration = null;
// }
//
// public CommandLine getCommandLine() {
// return commandLine;
// }
//
// public Properties getProperties() {
// return properties;
// }
//
// public Object getImportedConfiguration() {
// return importedConfiguration;
// }
//
// public void setProperties(Properties properties) {
// this.properties = properties;
// }
//
// public void setCommandLine(CommandLine commandLine) {
// this.commandLine = commandLine;
// }
//
// public void setImportedConfiguration(Object importedConfiguration) {
// this.importedConfiguration = importedConfiguration;
// }
//
// public void setAnnotationOrder(Class<? extends Annotation>[] annotationOrder) {
// this.annotationOrder = annotationOrder;
// }
//
// public Class<? extends Annotation>[] getAnnotationOrder() {
// return annotationOrder;
// }
// }
//
// Path: src/main/java/com/tngtech/configbuilder/configuration/ErrorMessageSetup.java
// public class ErrorMessageSetup {
//
// private Properties errorMessages;
//
// /**
// * loads the default error messages for the system locale, then merges them with additional error messages loaded with the PropertyLoader
// *
// * @param baseName the filename for additional error messages
// * @param propertyLoader the PropertyLoader used to load additional error messages
// */
// public void initialize(String baseName, PropertyLoader propertyLoader) {
// ResourceBundle resourceBundle = ResourceBundle.getBundle("errors");
// errorMessages = convertResourceBundleToProperties(resourceBundle);
// if (baseName != null) {
// errorMessages.putAll(propertyLoader.load(baseName));
// }
// }
//
// private Properties convertResourceBundleToProperties(ResourceBundle resource) {
// Properties properties = new Properties();
//
// Enumeration<String> keys = resource.getKeys();
// while (keys.hasMoreElements()) {
// String key = keys.nextElement();
// properties.put(key, resource.getString(key));
// }
// return properties;
// }
//
// public String getErrorMessage(Throwable e, String... variables) {
// String message = errorMessages.getProperty(e.getClass().getName());
// return message == null ? String.format(errorMessages.getProperty("standardMessage"), e.getClass().getName()) : String.format(message, variables);
// }
//
// public String getErrorMessage(Class exceptionClass, String... variables) {
// String message = errorMessages.getProperty(exceptionClass.getName());
// return message == null ? String.format(errorMessages.getProperty("standardMessage"), exceptionClass.getName()) : String.format(message, variables);
// }
// }
//
// Path: src/main/java/com/tngtech/configbuilder/exception/PrimitiveParsingException.java
// public class PrimitiveParsingException extends RuntimeException {
// public PrimitiveParsingException(String errorMessage) {
// super(errorMessage);
// }
// }
// Path: src/test/java/com/tngtech/configbuilder/util/FieldValueTransformerComponentTest.java
import com.google.common.collect.Lists;
import com.tngtech.configbuilder.annotation.valuetransformer.*;
import com.tngtech.configbuilder.configuration.BuilderConfiguration;
import com.tngtech.configbuilder.configuration.ErrorMessageSetup;
import com.tngtech.configbuilder.exception.PrimitiveParsingException;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import java.lang.reflect.Field;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Collection;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
boolField = TestConfigClass.class.getDeclaredField("boolField");
otherIntField = TestConfigClass.class.getDeclaredField("otherIntField");
integerField = TestConfigClass.class.getDeclaredField("integerField");
pathCollectionField = TestConfigClass.class.getDeclaredField("pathCollectionField");
integerCollectionField = TestConfigClass.class.getDeclaredField("integerCollectionField");
doubleField = TestConfigClass.class.getDeclaredField("doubleField");
objectCollectionField = TestConfigClass.class.getDeclaredField("objectCollectionField");
this.fieldValueTransformer = new FieldValueTransformer(configBuilderFactory);
}
@Test
public void testTransformingStringToStringCollection() {
ArrayList<String> actualResult = (ArrayList<String>)fieldValueTransformer.transformFieldValue(stringCollectionField, "Alpha,Beta,Gamma");
assertEquals(Lists.newArrayList("Alpha","Beta","Gamma"), actualResult);
}
@Test
public void testTransformingStringToInt() {
Object actualResult = fieldValueTransformer.transformFieldValue(intField, "17");
assertEquals(17, actualResult);
}
@Test
public void testTransformingIntegerToDouble() {
Object actualResult = fieldValueTransformer.transformFieldValue(doubleField, 17);
assertEquals(17.0, actualResult);
}
| @Test(expected = PrimitiveParsingException.class) |
bmatthias/config-builder | src/test/java/com/tngtech/configbuilder/util/FieldValueTransformerTest.java | // Path: src/main/java/com/tngtech/configbuilder/configuration/ErrorMessageSetup.java
// public class ErrorMessageSetup {
//
// private Properties errorMessages;
//
// /**
// * loads the default error messages for the system locale, then merges them with additional error messages loaded with the PropertyLoader
// *
// * @param baseName the filename for additional error messages
// * @param propertyLoader the PropertyLoader used to load additional error messages
// */
// public void initialize(String baseName, PropertyLoader propertyLoader) {
// ResourceBundle resourceBundle = ResourceBundle.getBundle("errors");
// errorMessages = convertResourceBundleToProperties(resourceBundle);
// if (baseName != null) {
// errorMessages.putAll(propertyLoader.load(baseName));
// }
// }
//
// private Properties convertResourceBundleToProperties(ResourceBundle resource) {
// Properties properties = new Properties();
//
// Enumeration<String> keys = resource.getKeys();
// while (keys.hasMoreElements()) {
// String key = keys.nextElement();
// properties.put(key, resource.getString(key));
// }
// return properties;
// }
//
// public String getErrorMessage(Throwable e, String... variables) {
// String message = errorMessages.getProperty(e.getClass().getName());
// return message == null ? String.format(errorMessages.getProperty("standardMessage"), e.getClass().getName()) : String.format(message, variables);
// }
//
// public String getErrorMessage(Class exceptionClass, String... variables) {
// String message = errorMessages.getProperty(exceptionClass.getName());
// return message == null ? String.format(errorMessages.getProperty("standardMessage"), exceptionClass.getName()) : String.format(message, variables);
// }
// }
//
// Path: src/main/java/com/tngtech/configbuilder/exception/TypeTransformerException.java
// public class TypeTransformerException extends RuntimeException {
//
// public TypeTransformerException(String message) {
// super(message);
// }
// }
| import com.google.common.collect.Lists;
import com.tngtech.configbuilder.annotation.valuetransformer.*;
import com.tngtech.configbuilder.configuration.ErrorMessageSetup;
import com.tngtech.configbuilder.exception.TypeTransformerException;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InOrder;
import org.mockito.Matchers;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import java.lang.reflect.Field;
import java.lang.reflect.Type;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.*; | package com.tngtech.configbuilder.util;
@RunWith(MockitoJUnitRunner.class)
public class FieldValueTransformerTest {
private FieldValueTransformer fieldValueTransformer;
@ValueTransformers(FieldValueTransformerComponentTest.TestTransformer.class)
private ArrayList<Path> testField;
@Mock
private ConfigBuilderFactory configBuilderFactory;
@Mock | // Path: src/main/java/com/tngtech/configbuilder/configuration/ErrorMessageSetup.java
// public class ErrorMessageSetup {
//
// private Properties errorMessages;
//
// /**
// * loads the default error messages for the system locale, then merges them with additional error messages loaded with the PropertyLoader
// *
// * @param baseName the filename for additional error messages
// * @param propertyLoader the PropertyLoader used to load additional error messages
// */
// public void initialize(String baseName, PropertyLoader propertyLoader) {
// ResourceBundle resourceBundle = ResourceBundle.getBundle("errors");
// errorMessages = convertResourceBundleToProperties(resourceBundle);
// if (baseName != null) {
// errorMessages.putAll(propertyLoader.load(baseName));
// }
// }
//
// private Properties convertResourceBundleToProperties(ResourceBundle resource) {
// Properties properties = new Properties();
//
// Enumeration<String> keys = resource.getKeys();
// while (keys.hasMoreElements()) {
// String key = keys.nextElement();
// properties.put(key, resource.getString(key));
// }
// return properties;
// }
//
// public String getErrorMessage(Throwable e, String... variables) {
// String message = errorMessages.getProperty(e.getClass().getName());
// return message == null ? String.format(errorMessages.getProperty("standardMessage"), e.getClass().getName()) : String.format(message, variables);
// }
//
// public String getErrorMessage(Class exceptionClass, String... variables) {
// String message = errorMessages.getProperty(exceptionClass.getName());
// return message == null ? String.format(errorMessages.getProperty("standardMessage"), exceptionClass.getName()) : String.format(message, variables);
// }
// }
//
// Path: src/main/java/com/tngtech/configbuilder/exception/TypeTransformerException.java
// public class TypeTransformerException extends RuntimeException {
//
// public TypeTransformerException(String message) {
// super(message);
// }
// }
// Path: src/test/java/com/tngtech/configbuilder/util/FieldValueTransformerTest.java
import com.google.common.collect.Lists;
import com.tngtech.configbuilder.annotation.valuetransformer.*;
import com.tngtech.configbuilder.configuration.ErrorMessageSetup;
import com.tngtech.configbuilder.exception.TypeTransformerException;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InOrder;
import org.mockito.Matchers;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import java.lang.reflect.Field;
import java.lang.reflect.Type;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.*;
package com.tngtech.configbuilder.util;
@RunWith(MockitoJUnitRunner.class)
public class FieldValueTransformerTest {
private FieldValueTransformer fieldValueTransformer;
@ValueTransformers(FieldValueTransformerComponentTest.TestTransformer.class)
private ArrayList<Path> testField;
@Mock
private ConfigBuilderFactory configBuilderFactory;
@Mock | private ErrorMessageSetup errorMessageSetup; |
bmatthias/config-builder | src/test/java/com/tngtech/configbuilder/util/FieldValueExtractorTest.java | // Path: src/main/java/com/tngtech/configbuilder/configuration/BuilderConfiguration.java
// public class BuilderConfiguration {
//
// private Properties properties;
// private CommandLine commandLine;
// private Object importedConfiguration;
// private Class<? extends Annotation>[] annotationOrder = new Class[]{CommandLineValue.class, PropertyValue.class, EnvironmentVariableValue.class, SystemPropertyValue.class, ImportedValue.class, DefaultValue.class};
//
// public BuilderConfiguration() {
// properties = new Properties();
// commandLine = null;
// importedConfiguration = null;
// }
//
// public CommandLine getCommandLine() {
// return commandLine;
// }
//
// public Properties getProperties() {
// return properties;
// }
//
// public Object getImportedConfiguration() {
// return importedConfiguration;
// }
//
// public void setProperties(Properties properties) {
// this.properties = properties;
// }
//
// public void setCommandLine(CommandLine commandLine) {
// this.commandLine = commandLine;
// }
//
// public void setImportedConfiguration(Object importedConfiguration) {
// this.importedConfiguration = importedConfiguration;
// }
//
// public void setAnnotationOrder(Class<? extends Annotation>[] annotationOrder) {
// this.annotationOrder = annotationOrder;
// }
//
// public Class<? extends Annotation>[] getAnnotationOrder() {
// return annotationOrder;
// }
// }
| import com.google.common.collect.Lists;
import com.tngtech.configbuilder.annotation.configuration.Separator;
import com.tngtech.configbuilder.annotation.configuration.LoadingOrder;
import com.tngtech.configbuilder.annotation.valueextractor.*;
import com.tngtech.configbuilder.configuration.BuilderConfiguration;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.mockito.Matchers;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.util.Collection;
import java.util.List;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.*; | package com.tngtech.configbuilder.util;
@RunWith(MockitoJUnitRunner.class)
public class FieldValueExtractorTest {
private static class TestConfig {
@PropertyValue("testField")
@CommandLineValue(shortOpt = "t", longOpt = "testField")
private Collection<String> testField;
@LoadingOrder({CommandLineValue.class, PropertyValue.class})
@PropertyValue("testFieldWithLoadingOrder")
@CommandLineValue(shortOpt = "t", longOpt = "testFieldWithLoadingOrder")
private Collection<String> testFieldWithLoadingOrder;
@Separator
@DefaultValue("value1,value2")
private Collection<String> collectionField;
@DefaultValue("3")
private int primitiveField;
@DefaultValue("3")
private boolean booleanField;
}
@Rule
public ExpectedException expectedException = ExpectedException.none();
@Mock
private ConfigBuilderFactory configBuilderFactory;
@Mock | // Path: src/main/java/com/tngtech/configbuilder/configuration/BuilderConfiguration.java
// public class BuilderConfiguration {
//
// private Properties properties;
// private CommandLine commandLine;
// private Object importedConfiguration;
// private Class<? extends Annotation>[] annotationOrder = new Class[]{CommandLineValue.class, PropertyValue.class, EnvironmentVariableValue.class, SystemPropertyValue.class, ImportedValue.class, DefaultValue.class};
//
// public BuilderConfiguration() {
// properties = new Properties();
// commandLine = null;
// importedConfiguration = null;
// }
//
// public CommandLine getCommandLine() {
// return commandLine;
// }
//
// public Properties getProperties() {
// return properties;
// }
//
// public Object getImportedConfiguration() {
// return importedConfiguration;
// }
//
// public void setProperties(Properties properties) {
// this.properties = properties;
// }
//
// public void setCommandLine(CommandLine commandLine) {
// this.commandLine = commandLine;
// }
//
// public void setImportedConfiguration(Object importedConfiguration) {
// this.importedConfiguration = importedConfiguration;
// }
//
// public void setAnnotationOrder(Class<? extends Annotation>[] annotationOrder) {
// this.annotationOrder = annotationOrder;
// }
//
// public Class<? extends Annotation>[] getAnnotationOrder() {
// return annotationOrder;
// }
// }
// Path: src/test/java/com/tngtech/configbuilder/util/FieldValueExtractorTest.java
import com.google.common.collect.Lists;
import com.tngtech.configbuilder.annotation.configuration.Separator;
import com.tngtech.configbuilder.annotation.configuration.LoadingOrder;
import com.tngtech.configbuilder.annotation.valueextractor.*;
import com.tngtech.configbuilder.configuration.BuilderConfiguration;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.mockito.Matchers;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.util.Collection;
import java.util.List;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.*;
package com.tngtech.configbuilder.util;
@RunWith(MockitoJUnitRunner.class)
public class FieldValueExtractorTest {
private static class TestConfig {
@PropertyValue("testField")
@CommandLineValue(shortOpt = "t", longOpt = "testField")
private Collection<String> testField;
@LoadingOrder({CommandLineValue.class, PropertyValue.class})
@PropertyValue("testFieldWithLoadingOrder")
@CommandLineValue(shortOpt = "t", longOpt = "testFieldWithLoadingOrder")
private Collection<String> testFieldWithLoadingOrder;
@Separator
@DefaultValue("value1,value2")
private Collection<String> collectionField;
@DefaultValue("3")
private int primitiveField;
@DefaultValue("3")
private boolean booleanField;
}
@Rule
public ExpectedException expectedException = ExpectedException.none();
@Mock
private ConfigBuilderFactory configBuilderFactory;
@Mock | private BuilderConfiguration builderConfiguration; |
bmatthias/config-builder | src/test/java/com/tngtech/configbuilder/util/CommandLineHelperTest.java | // Path: src/main/java/com/tngtech/configbuilder/configuration/ErrorMessageSetup.java
// public class ErrorMessageSetup {
//
// private Properties errorMessages;
//
// /**
// * loads the default error messages for the system locale, then merges them with additional error messages loaded with the PropertyLoader
// *
// * @param baseName the filename for additional error messages
// * @param propertyLoader the PropertyLoader used to load additional error messages
// */
// public void initialize(String baseName, PropertyLoader propertyLoader) {
// ResourceBundle resourceBundle = ResourceBundle.getBundle("errors");
// errorMessages = convertResourceBundleToProperties(resourceBundle);
// if (baseName != null) {
// errorMessages.putAll(propertyLoader.load(baseName));
// }
// }
//
// private Properties convertResourceBundleToProperties(ResourceBundle resource) {
// Properties properties = new Properties();
//
// Enumeration<String> keys = resource.getKeys();
// while (keys.hasMoreElements()) {
// String key = keys.nextElement();
// properties.put(key, resource.getString(key));
// }
// return properties;
// }
//
// public String getErrorMessage(Throwable e, String... variables) {
// String message = errorMessages.getProperty(e.getClass().getName());
// return message == null ? String.format(errorMessages.getProperty("standardMessage"), e.getClass().getName()) : String.format(message, variables);
// }
//
// public String getErrorMessage(Class exceptionClass, String... variables) {
// String message = errorMessages.getProperty(exceptionClass.getName());
// return message == null ? String.format(errorMessages.getProperty("standardMessage"), exceptionClass.getName()) : String.format(message, variables);
// }
// }
//
// Path: src/main/java/com/tngtech/configbuilder/exception/ConfigBuilderException.java
// public class ConfigBuilderException extends RuntimeException {
//
// public ConfigBuilderException(String message, Throwable e) {
// super(message, e);
// }
// }
| import com.google.common.collect.Sets;
import com.tngtech.configbuilder.annotation.valueextractor.CommandLineValue;
import com.tngtech.configbuilder.configuration.ErrorMessageSetup;
import com.tngtech.configbuilder.exception.ConfigBuilderException;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.GnuParser;
import org.apache.commons.cli.Option;
import org.apache.commons.cli.Options;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import java.lang.reflect.Field;
import java.util.Set;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.*; | package com.tngtech.configbuilder.util;
@RunWith(MockitoJUnitRunner.class)
public class CommandLineHelperTest {
private static class TestConfig {
@CommandLineValue(shortOpt = "u", longOpt = "user", required = true)
public String aString;
@CommandLineValue(shortOpt = "v", longOpt = "vir", required = false)
public String anotherString;
}
private CommandLineHelper commandLineHelper;
private String[] args = null;
@Mock
private Options options;
@Mock
private GnuParser parser;
@Mock
private CommandLine commandLine;
@Mock
private ConfigBuilderFactory configBuilderFactory;
@Mock
private AnnotationHelper annotationHelper;
@Mock | // Path: src/main/java/com/tngtech/configbuilder/configuration/ErrorMessageSetup.java
// public class ErrorMessageSetup {
//
// private Properties errorMessages;
//
// /**
// * loads the default error messages for the system locale, then merges them with additional error messages loaded with the PropertyLoader
// *
// * @param baseName the filename for additional error messages
// * @param propertyLoader the PropertyLoader used to load additional error messages
// */
// public void initialize(String baseName, PropertyLoader propertyLoader) {
// ResourceBundle resourceBundle = ResourceBundle.getBundle("errors");
// errorMessages = convertResourceBundleToProperties(resourceBundle);
// if (baseName != null) {
// errorMessages.putAll(propertyLoader.load(baseName));
// }
// }
//
// private Properties convertResourceBundleToProperties(ResourceBundle resource) {
// Properties properties = new Properties();
//
// Enumeration<String> keys = resource.getKeys();
// while (keys.hasMoreElements()) {
// String key = keys.nextElement();
// properties.put(key, resource.getString(key));
// }
// return properties;
// }
//
// public String getErrorMessage(Throwable e, String... variables) {
// String message = errorMessages.getProperty(e.getClass().getName());
// return message == null ? String.format(errorMessages.getProperty("standardMessage"), e.getClass().getName()) : String.format(message, variables);
// }
//
// public String getErrorMessage(Class exceptionClass, String... variables) {
// String message = errorMessages.getProperty(exceptionClass.getName());
// return message == null ? String.format(errorMessages.getProperty("standardMessage"), exceptionClass.getName()) : String.format(message, variables);
// }
// }
//
// Path: src/main/java/com/tngtech/configbuilder/exception/ConfigBuilderException.java
// public class ConfigBuilderException extends RuntimeException {
//
// public ConfigBuilderException(String message, Throwable e) {
// super(message, e);
// }
// }
// Path: src/test/java/com/tngtech/configbuilder/util/CommandLineHelperTest.java
import com.google.common.collect.Sets;
import com.tngtech.configbuilder.annotation.valueextractor.CommandLineValue;
import com.tngtech.configbuilder.configuration.ErrorMessageSetup;
import com.tngtech.configbuilder.exception.ConfigBuilderException;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.GnuParser;
import org.apache.commons.cli.Option;
import org.apache.commons.cli.Options;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import java.lang.reflect.Field;
import java.util.Set;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.*;
package com.tngtech.configbuilder.util;
@RunWith(MockitoJUnitRunner.class)
public class CommandLineHelperTest {
private static class TestConfig {
@CommandLineValue(shortOpt = "u", longOpt = "user", required = true)
public String aString;
@CommandLineValue(shortOpt = "v", longOpt = "vir", required = false)
public String anotherString;
}
private CommandLineHelper commandLineHelper;
private String[] args = null;
@Mock
private Options options;
@Mock
private GnuParser parser;
@Mock
private CommandLine commandLine;
@Mock
private ConfigBuilderFactory configBuilderFactory;
@Mock
private AnnotationHelper annotationHelper;
@Mock | private ErrorMessageSetup errorMessageSetup; |
bmatthias/config-builder | src/test/java/com/tngtech/configbuilder/util/CommandLineHelperTest.java | // Path: src/main/java/com/tngtech/configbuilder/configuration/ErrorMessageSetup.java
// public class ErrorMessageSetup {
//
// private Properties errorMessages;
//
// /**
// * loads the default error messages for the system locale, then merges them with additional error messages loaded with the PropertyLoader
// *
// * @param baseName the filename for additional error messages
// * @param propertyLoader the PropertyLoader used to load additional error messages
// */
// public void initialize(String baseName, PropertyLoader propertyLoader) {
// ResourceBundle resourceBundle = ResourceBundle.getBundle("errors");
// errorMessages = convertResourceBundleToProperties(resourceBundle);
// if (baseName != null) {
// errorMessages.putAll(propertyLoader.load(baseName));
// }
// }
//
// private Properties convertResourceBundleToProperties(ResourceBundle resource) {
// Properties properties = new Properties();
//
// Enumeration<String> keys = resource.getKeys();
// while (keys.hasMoreElements()) {
// String key = keys.nextElement();
// properties.put(key, resource.getString(key));
// }
// return properties;
// }
//
// public String getErrorMessage(Throwable e, String... variables) {
// String message = errorMessages.getProperty(e.getClass().getName());
// return message == null ? String.format(errorMessages.getProperty("standardMessage"), e.getClass().getName()) : String.format(message, variables);
// }
//
// public String getErrorMessage(Class exceptionClass, String... variables) {
// String message = errorMessages.getProperty(exceptionClass.getName());
// return message == null ? String.format(errorMessages.getProperty("standardMessage"), exceptionClass.getName()) : String.format(message, variables);
// }
// }
//
// Path: src/main/java/com/tngtech/configbuilder/exception/ConfigBuilderException.java
// public class ConfigBuilderException extends RuntimeException {
//
// public ConfigBuilderException(String message, Throwable e) {
// super(message, e);
// }
// }
| import com.google.common.collect.Sets;
import com.tngtech.configbuilder.annotation.valueextractor.CommandLineValue;
import com.tngtech.configbuilder.configuration.ErrorMessageSetup;
import com.tngtech.configbuilder.exception.ConfigBuilderException;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.GnuParser;
import org.apache.commons.cli.Option;
import org.apache.commons.cli.Options;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import java.lang.reflect.Field;
import java.util.Set;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.*; | private ErrorMessageSetup errorMessageSetup;
@Before
public void setUp() throws Exception {
when(configBuilderFactory.getInstance(AnnotationHelper.class)).thenReturn(annotationHelper);
when(configBuilderFactory.getInstance(ErrorMessageSetup.class)).thenReturn(errorMessageSetup);
commandLineHelper = new CommandLineHelper(configBuilderFactory);
Set<Field> fields = Sets.newHashSet(TestConfig.class.getDeclaredFields());
when(annotationHelper.getFieldsAnnotatedWith(TestConfig.class, CommandLineValue.class)).thenReturn(fields);
when(parser.parse(options, args)).thenReturn(commandLine);
}
@Test
public void testGetCommandLine() throws Exception {
when(configBuilderFactory.createInstance(GnuParser.class)).thenReturn(parser);
when(configBuilderFactory.createInstance(Options.class)).thenReturn(options);
ArgumentCaptor<Option> captor = ArgumentCaptor.forClass(Option.class);
assertEquals(commandLine, commandLineHelper.getCommandLine(TestConfig.class, args));
verify(options, times(2)).addOption(captor.capture());
verify(parser).parse(options, args);
Option option = captor.getValue();
assertEquals("user", option.getLongOpt());
assertEquals("u", option.getOpt());
assertEquals(true, option.isRequired());
}
| // Path: src/main/java/com/tngtech/configbuilder/configuration/ErrorMessageSetup.java
// public class ErrorMessageSetup {
//
// private Properties errorMessages;
//
// /**
// * loads the default error messages for the system locale, then merges them with additional error messages loaded with the PropertyLoader
// *
// * @param baseName the filename for additional error messages
// * @param propertyLoader the PropertyLoader used to load additional error messages
// */
// public void initialize(String baseName, PropertyLoader propertyLoader) {
// ResourceBundle resourceBundle = ResourceBundle.getBundle("errors");
// errorMessages = convertResourceBundleToProperties(resourceBundle);
// if (baseName != null) {
// errorMessages.putAll(propertyLoader.load(baseName));
// }
// }
//
// private Properties convertResourceBundleToProperties(ResourceBundle resource) {
// Properties properties = new Properties();
//
// Enumeration<String> keys = resource.getKeys();
// while (keys.hasMoreElements()) {
// String key = keys.nextElement();
// properties.put(key, resource.getString(key));
// }
// return properties;
// }
//
// public String getErrorMessage(Throwable e, String... variables) {
// String message = errorMessages.getProperty(e.getClass().getName());
// return message == null ? String.format(errorMessages.getProperty("standardMessage"), e.getClass().getName()) : String.format(message, variables);
// }
//
// public String getErrorMessage(Class exceptionClass, String... variables) {
// String message = errorMessages.getProperty(exceptionClass.getName());
// return message == null ? String.format(errorMessages.getProperty("standardMessage"), exceptionClass.getName()) : String.format(message, variables);
// }
// }
//
// Path: src/main/java/com/tngtech/configbuilder/exception/ConfigBuilderException.java
// public class ConfigBuilderException extends RuntimeException {
//
// public ConfigBuilderException(String message, Throwable e) {
// super(message, e);
// }
// }
// Path: src/test/java/com/tngtech/configbuilder/util/CommandLineHelperTest.java
import com.google.common.collect.Sets;
import com.tngtech.configbuilder.annotation.valueextractor.CommandLineValue;
import com.tngtech.configbuilder.configuration.ErrorMessageSetup;
import com.tngtech.configbuilder.exception.ConfigBuilderException;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.GnuParser;
import org.apache.commons.cli.Option;
import org.apache.commons.cli.Options;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import java.lang.reflect.Field;
import java.util.Set;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.*;
private ErrorMessageSetup errorMessageSetup;
@Before
public void setUp() throws Exception {
when(configBuilderFactory.getInstance(AnnotationHelper.class)).thenReturn(annotationHelper);
when(configBuilderFactory.getInstance(ErrorMessageSetup.class)).thenReturn(errorMessageSetup);
commandLineHelper = new CommandLineHelper(configBuilderFactory);
Set<Field> fields = Sets.newHashSet(TestConfig.class.getDeclaredFields());
when(annotationHelper.getFieldsAnnotatedWith(TestConfig.class, CommandLineValue.class)).thenReturn(fields);
when(parser.parse(options, args)).thenReturn(commandLine);
}
@Test
public void testGetCommandLine() throws Exception {
when(configBuilderFactory.createInstance(GnuParser.class)).thenReturn(parser);
when(configBuilderFactory.createInstance(Options.class)).thenReturn(options);
ArgumentCaptor<Option> captor = ArgumentCaptor.forClass(Option.class);
assertEquals(commandLine, commandLineHelper.getCommandLine(TestConfig.class, args));
verify(options, times(2)).addOption(captor.capture());
verify(parser).parse(options, args);
Option option = captor.getValue();
assertEquals("user", option.getLongOpt());
assertEquals("u", option.getOpt());
assertEquals(true, option.isRequired());
}
| @Test(expected = ConfigBuilderException.class) |
bmatthias/config-builder | src/main/java/com/tngtech/configbuilder/annotation/valueextractor/PropertyValueProcessor.java | // Path: src/main/java/com/tngtech/configbuilder/configuration/BuilderConfiguration.java
// public class BuilderConfiguration {
//
// private Properties properties;
// private CommandLine commandLine;
// private Object importedConfiguration;
// private Class<? extends Annotation>[] annotationOrder = new Class[]{CommandLineValue.class, PropertyValue.class, EnvironmentVariableValue.class, SystemPropertyValue.class, ImportedValue.class, DefaultValue.class};
//
// public BuilderConfiguration() {
// properties = new Properties();
// commandLine = null;
// importedConfiguration = null;
// }
//
// public CommandLine getCommandLine() {
// return commandLine;
// }
//
// public Properties getProperties() {
// return properties;
// }
//
// public Object getImportedConfiguration() {
// return importedConfiguration;
// }
//
// public void setProperties(Properties properties) {
// this.properties = properties;
// }
//
// public void setCommandLine(CommandLine commandLine) {
// this.commandLine = commandLine;
// }
//
// public void setImportedConfiguration(Object importedConfiguration) {
// this.importedConfiguration = importedConfiguration;
// }
//
// public void setAnnotationOrder(Class<? extends Annotation>[] annotationOrder) {
// this.annotationOrder = annotationOrder;
// }
//
// public Class<? extends Annotation>[] getAnnotationOrder() {
// return annotationOrder;
// }
// }
//
// Path: src/main/java/com/tngtech/configbuilder/util/ConfigBuilderFactory.java
// public class ConfigBuilderFactory {
//
// private Map<Class,Object> singletonMap = Maps.newHashMap();
//
// public <T> void initialize() {
//
// //Order is IMPORTANT!
//
// //configuration
// singletonMap.put(ErrorMessageSetup.class, new ErrorMessageSetup());
// singletonMap.put(BuilderConfiguration.class, new BuilderConfiguration());
//
// //util
// singletonMap.put(AnnotationHelper.class, new AnnotationHelper());
// singletonMap.put(GenericsAndCastingHelper.class, new GenericsAndCastingHelper());
// singletonMap.put(FieldValueExtractor.class, new FieldValueExtractor(this));
// singletonMap.put(FieldValueTransformer.class, new FieldValueTransformer(this));
// singletonMap.put(PropertyLoaderConfigurator.class, new PropertyLoaderConfigurator(this));
// singletonMap.put(ConstructionHelper.class, new ConstructionHelper<T>(this));
// singletonMap.put(FieldSetter.class, new FieldSetter<T>(this));
// singletonMap.put(ConfigValidator.class, new ConfigValidator<T>(this));
// singletonMap.put(CommandLineHelper.class, new CommandLineHelper(this));
//
// //AnnotationProcessors
// singletonMap.put(SystemPropertyProcessor.class, new SystemPropertyProcessor());
// singletonMap.put(PropertyValueProcessor.class, new PropertyValueProcessor());
// singletonMap.put(EnvironmentVariableProcessor.class, new EnvironmentVariableProcessor());
// singletonMap.put(CommandLineValueProcessor.class, new CommandLineValueProcessor());
// singletonMap.put(PropertySuffixProcessor.class, new PropertySuffixProcessor());
// singletonMap.put(PropertyLocationsProcessor.class, new PropertyLocationsProcessor());
// singletonMap.put(PropertyExtensionProcessor.class, new PropertyExtensionProcessor());
// singletonMap.put(PropertiesFilesProcessor.class, new PropertiesFilesProcessor());
// singletonMap.put(DefaultValueProcessor.class, new DefaultValueProcessor());
//
// //ValueTransformers
// singletonMap.put(StringOrPrimitiveToPrimitiveTransformer.class, new StringOrPrimitiveToPrimitiveTransformer());
// singletonMap.put(CollectionToArrayListTransformer.class, new CollectionToArrayListTransformer());
// singletonMap.put(CollectionToHashSetTransformer.class, new CollectionToHashSetTransformer());
// singletonMap.put(CharacterSeparatedStringToStringListTransformer.class, new CharacterSeparatedStringToStringListTransformer());
// singletonMap.put(CharacterSeparatedStringToStringSetTransformer.class, new CharacterSeparatedStringToStringSetTransformer());
// singletonMap.put(StringCollectionToCommaSeparatedStringTransformer.class, new StringCollectionToCommaSeparatedStringTransformer());
// singletonMap.put(StringToPathTransformer.class, new StringToPathTransformer());
//
// //other
// singletonMap.put(ValidatorFactory.class, Validation.buildDefaultValidatorFactory());
// }
//
// public <K> K getInstance(Class<K> clazz) {
// if(singletonMap.get(clazz) != null) {
// return (K)singletonMap.get(clazz);
// }
// else {
// return createInstance(clazz);
// }
// }
//
// //TODO: exception message
// public <K> K createInstance(Class<K> clazz) {
// try {
// return clazz.newInstance();
// } catch (IllegalAccessException e) {
// ErrorMessageSetup errorMessageSetup = (ErrorMessageSetup)singletonMap.get(ErrorMessageSetup.class);
// throw new FactoryInstantiationException(errorMessageSetup.getErrorMessage(FactoryInstantiationException.class, clazz.toString()));
// } catch (InstantiationException e) {
// return createInstanceOfInnerClass(clazz);
// }
// }
//
// //TODO: exception message
// private <K> K createInstanceOfInnerClass(Class<K> clazz) {
// Class superClass = clazz.getDeclaringClass();
// try {
// Object superInstance = superClass.newInstance();
// Constructor<K> constructor = clazz.getConstructor(superClass);
// return constructor.newInstance(superInstance);
// } catch (Exception e) {
// ErrorMessageSetup errorMessageSetup = (ErrorMessageSetup)singletonMap.get(ErrorMessageSetup.class);
// throw new FactoryInstantiationException(errorMessageSetup.getErrorMessage(FactoryInstantiationException.class, clazz.toString()));
// }
// }
// }
| import com.tngtech.configbuilder.configuration.BuilderConfiguration;
import com.tngtech.configbuilder.util.ConfigBuilderFactory;
import java.lang.annotation.Annotation; | package com.tngtech.configbuilder.annotation.valueextractor;
/**
* Processes PropertyValue annotations, implements ValueExtractorProcessor
*/
public class PropertyValueProcessor implements ValueExtractorProcessor {
public String getValue(Annotation annotation, ConfigBuilderFactory configBuilderFactory) { | // Path: src/main/java/com/tngtech/configbuilder/configuration/BuilderConfiguration.java
// public class BuilderConfiguration {
//
// private Properties properties;
// private CommandLine commandLine;
// private Object importedConfiguration;
// private Class<? extends Annotation>[] annotationOrder = new Class[]{CommandLineValue.class, PropertyValue.class, EnvironmentVariableValue.class, SystemPropertyValue.class, ImportedValue.class, DefaultValue.class};
//
// public BuilderConfiguration() {
// properties = new Properties();
// commandLine = null;
// importedConfiguration = null;
// }
//
// public CommandLine getCommandLine() {
// return commandLine;
// }
//
// public Properties getProperties() {
// return properties;
// }
//
// public Object getImportedConfiguration() {
// return importedConfiguration;
// }
//
// public void setProperties(Properties properties) {
// this.properties = properties;
// }
//
// public void setCommandLine(CommandLine commandLine) {
// this.commandLine = commandLine;
// }
//
// public void setImportedConfiguration(Object importedConfiguration) {
// this.importedConfiguration = importedConfiguration;
// }
//
// public void setAnnotationOrder(Class<? extends Annotation>[] annotationOrder) {
// this.annotationOrder = annotationOrder;
// }
//
// public Class<? extends Annotation>[] getAnnotationOrder() {
// return annotationOrder;
// }
// }
//
// Path: src/main/java/com/tngtech/configbuilder/util/ConfigBuilderFactory.java
// public class ConfigBuilderFactory {
//
// private Map<Class,Object> singletonMap = Maps.newHashMap();
//
// public <T> void initialize() {
//
// //Order is IMPORTANT!
//
// //configuration
// singletonMap.put(ErrorMessageSetup.class, new ErrorMessageSetup());
// singletonMap.put(BuilderConfiguration.class, new BuilderConfiguration());
//
// //util
// singletonMap.put(AnnotationHelper.class, new AnnotationHelper());
// singletonMap.put(GenericsAndCastingHelper.class, new GenericsAndCastingHelper());
// singletonMap.put(FieldValueExtractor.class, new FieldValueExtractor(this));
// singletonMap.put(FieldValueTransformer.class, new FieldValueTransformer(this));
// singletonMap.put(PropertyLoaderConfigurator.class, new PropertyLoaderConfigurator(this));
// singletonMap.put(ConstructionHelper.class, new ConstructionHelper<T>(this));
// singletonMap.put(FieldSetter.class, new FieldSetter<T>(this));
// singletonMap.put(ConfigValidator.class, new ConfigValidator<T>(this));
// singletonMap.put(CommandLineHelper.class, new CommandLineHelper(this));
//
// //AnnotationProcessors
// singletonMap.put(SystemPropertyProcessor.class, new SystemPropertyProcessor());
// singletonMap.put(PropertyValueProcessor.class, new PropertyValueProcessor());
// singletonMap.put(EnvironmentVariableProcessor.class, new EnvironmentVariableProcessor());
// singletonMap.put(CommandLineValueProcessor.class, new CommandLineValueProcessor());
// singletonMap.put(PropertySuffixProcessor.class, new PropertySuffixProcessor());
// singletonMap.put(PropertyLocationsProcessor.class, new PropertyLocationsProcessor());
// singletonMap.put(PropertyExtensionProcessor.class, new PropertyExtensionProcessor());
// singletonMap.put(PropertiesFilesProcessor.class, new PropertiesFilesProcessor());
// singletonMap.put(DefaultValueProcessor.class, new DefaultValueProcessor());
//
// //ValueTransformers
// singletonMap.put(StringOrPrimitiveToPrimitiveTransformer.class, new StringOrPrimitiveToPrimitiveTransformer());
// singletonMap.put(CollectionToArrayListTransformer.class, new CollectionToArrayListTransformer());
// singletonMap.put(CollectionToHashSetTransformer.class, new CollectionToHashSetTransformer());
// singletonMap.put(CharacterSeparatedStringToStringListTransformer.class, new CharacterSeparatedStringToStringListTransformer());
// singletonMap.put(CharacterSeparatedStringToStringSetTransformer.class, new CharacterSeparatedStringToStringSetTransformer());
// singletonMap.put(StringCollectionToCommaSeparatedStringTransformer.class, new StringCollectionToCommaSeparatedStringTransformer());
// singletonMap.put(StringToPathTransformer.class, new StringToPathTransformer());
//
// //other
// singletonMap.put(ValidatorFactory.class, Validation.buildDefaultValidatorFactory());
// }
//
// public <K> K getInstance(Class<K> clazz) {
// if(singletonMap.get(clazz) != null) {
// return (K)singletonMap.get(clazz);
// }
// else {
// return createInstance(clazz);
// }
// }
//
// //TODO: exception message
// public <K> K createInstance(Class<K> clazz) {
// try {
// return clazz.newInstance();
// } catch (IllegalAccessException e) {
// ErrorMessageSetup errorMessageSetup = (ErrorMessageSetup)singletonMap.get(ErrorMessageSetup.class);
// throw new FactoryInstantiationException(errorMessageSetup.getErrorMessage(FactoryInstantiationException.class, clazz.toString()));
// } catch (InstantiationException e) {
// return createInstanceOfInnerClass(clazz);
// }
// }
//
// //TODO: exception message
// private <K> K createInstanceOfInnerClass(Class<K> clazz) {
// Class superClass = clazz.getDeclaringClass();
// try {
// Object superInstance = superClass.newInstance();
// Constructor<K> constructor = clazz.getConstructor(superClass);
// return constructor.newInstance(superInstance);
// } catch (Exception e) {
// ErrorMessageSetup errorMessageSetup = (ErrorMessageSetup)singletonMap.get(ErrorMessageSetup.class);
// throw new FactoryInstantiationException(errorMessageSetup.getErrorMessage(FactoryInstantiationException.class, clazz.toString()));
// }
// }
// }
// Path: src/main/java/com/tngtech/configbuilder/annotation/valueextractor/PropertyValueProcessor.java
import com.tngtech.configbuilder.configuration.BuilderConfiguration;
import com.tngtech.configbuilder.util.ConfigBuilderFactory;
import java.lang.annotation.Annotation;
package com.tngtech.configbuilder.annotation.valueextractor;
/**
* Processes PropertyValue annotations, implements ValueExtractorProcessor
*/
public class PropertyValueProcessor implements ValueExtractorProcessor {
public String getValue(Annotation annotation, ConfigBuilderFactory configBuilderFactory) { | BuilderConfiguration builderConfiguration = configBuilderFactory.getInstance(BuilderConfiguration.class); |
bmatthias/config-builder | src/main/java/com/tngtech/configbuilder/annotation/valuetransformer/StringOrPrimitiveToPrimitiveTransformer.java | // Path: src/main/java/com/tngtech/configbuilder/exception/PrimitiveParsingException.java
// public class PrimitiveParsingException extends RuntimeException {
// public PrimitiveParsingException(String errorMessage) {
// super(errorMessage);
// }
// }
| import com.tngtech.configbuilder.exception.PrimitiveParsingException;
import java.beans.PropertyEditor;
import java.beans.PropertyEditorManager;
import java.lang.reflect.Type; | package com.tngtech.configbuilder.annotation.valuetransformer;
public class StringOrPrimitiveToPrimitiveTransformer extends ValueTransformer<Object,Object> {
@Override
public Object transform(Object argument) {
PropertyEditor editor = PropertyEditorManager.findEditor(genericsAndCastingHelper.castTypeToClass(targetType));
try {
editor.setAsText(String.valueOf(argument));
return editor.getValue();
}
catch(IllegalArgumentException e) { | // Path: src/main/java/com/tngtech/configbuilder/exception/PrimitiveParsingException.java
// public class PrimitiveParsingException extends RuntimeException {
// public PrimitiveParsingException(String errorMessage) {
// super(errorMessage);
// }
// }
// Path: src/main/java/com/tngtech/configbuilder/annotation/valuetransformer/StringOrPrimitiveToPrimitiveTransformer.java
import com.tngtech.configbuilder.exception.PrimitiveParsingException;
import java.beans.PropertyEditor;
import java.beans.PropertyEditorManager;
import java.lang.reflect.Type;
package com.tngtech.configbuilder.annotation.valuetransformer;
public class StringOrPrimitiveToPrimitiveTransformer extends ValueTransformer<Object,Object> {
@Override
public Object transform(Object argument) {
PropertyEditor editor = PropertyEditorManager.findEditor(genericsAndCastingHelper.castTypeToClass(targetType));
try {
editor.setAsText(String.valueOf(argument));
return editor.getValue();
}
catch(IllegalArgumentException e) { | throw new PrimitiveParsingException(errorMessageSetup.getErrorMessage(PrimitiveParsingException.class, String.valueOf(argument), targetType.toString())); |
bmatthias/config-builder | src/test/java/com/tngtech/configbuilder/util/ConfigValidatorTest.java | // Path: src/main/java/com/tngtech/configbuilder/configuration/ErrorMessageSetup.java
// public class ErrorMessageSetup {
//
// private Properties errorMessages;
//
// /**
// * loads the default error messages for the system locale, then merges them with additional error messages loaded with the PropertyLoader
// *
// * @param baseName the filename for additional error messages
// * @param propertyLoader the PropertyLoader used to load additional error messages
// */
// public void initialize(String baseName, PropertyLoader propertyLoader) {
// ResourceBundle resourceBundle = ResourceBundle.getBundle("errors");
// errorMessages = convertResourceBundleToProperties(resourceBundle);
// if (baseName != null) {
// errorMessages.putAll(propertyLoader.load(baseName));
// }
// }
//
// private Properties convertResourceBundleToProperties(ResourceBundle resource) {
// Properties properties = new Properties();
//
// Enumeration<String> keys = resource.getKeys();
// while (keys.hasMoreElements()) {
// String key = keys.nextElement();
// properties.put(key, resource.getString(key));
// }
// return properties;
// }
//
// public String getErrorMessage(Throwable e, String... variables) {
// String message = errorMessages.getProperty(e.getClass().getName());
// return message == null ? String.format(errorMessages.getProperty("standardMessage"), e.getClass().getName()) : String.format(message, variables);
// }
//
// public String getErrorMessage(Class exceptionClass, String... variables) {
// String message = errorMessages.getProperty(exceptionClass.getName());
// return message == null ? String.format(errorMessages.getProperty("standardMessage"), exceptionClass.getName()) : String.format(message, variables);
// }
// }
//
// Path: src/main/java/com/tngtech/configbuilder/exception/ValidatorException.java
// public class ValidatorException extends RuntimeException {
//
// Set<ConstraintViolation> constraintViolations;
//
// public <T> ValidatorException(String message, Set<ConstraintViolation<T>> constraintViolations) {
// super(message);
// this.constraintViolations = Sets.newHashSet(Iterables.transform(constraintViolations, new Function<ConstraintViolation<T>, ConstraintViolation>() {
// @Override
// public ConstraintViolation apply(ConstraintViolation<T> constraintViolation) {
// return constraintViolation;
// }
// }));
// }
//
// public ValidatorException(String message, Throwable e) {
// super(message, e);
// }
// }
| import com.google.common.collect.Sets;
import com.tngtech.configbuilder.annotation.validation.Validation;
import com.tngtech.configbuilder.configuration.ErrorMessageSetup;
import com.tngtech.configbuilder.exception.ValidatorException;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.mockito.Matchers;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import javax.validation.ConstraintViolation;
import javax.validation.ValidatorFactory;
import java.util.Set;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when; | package com.tngtech.configbuilder.util;
@RunWith(MockitoJUnitRunner.class)
public class ConfigValidatorTest {
private static class TestConfig {
@Validation
private void validate() {
throw new RuntimeException();
}
}
private ConfigValidator<TestConfig> configValidator;
@Mock
private ConfigBuilderFactory configBuilderFactory;
@Mock
private ValidatorFactory validatorFactory;
@Mock
private javax.validation.Validator validator;
@Mock
private TestConfig testConfig;
@Mock
private ConstraintViolation<TestConfig> constraintViolation1, constraintViolation2;
@Mock | // Path: src/main/java/com/tngtech/configbuilder/configuration/ErrorMessageSetup.java
// public class ErrorMessageSetup {
//
// private Properties errorMessages;
//
// /**
// * loads the default error messages for the system locale, then merges them with additional error messages loaded with the PropertyLoader
// *
// * @param baseName the filename for additional error messages
// * @param propertyLoader the PropertyLoader used to load additional error messages
// */
// public void initialize(String baseName, PropertyLoader propertyLoader) {
// ResourceBundle resourceBundle = ResourceBundle.getBundle("errors");
// errorMessages = convertResourceBundleToProperties(resourceBundle);
// if (baseName != null) {
// errorMessages.putAll(propertyLoader.load(baseName));
// }
// }
//
// private Properties convertResourceBundleToProperties(ResourceBundle resource) {
// Properties properties = new Properties();
//
// Enumeration<String> keys = resource.getKeys();
// while (keys.hasMoreElements()) {
// String key = keys.nextElement();
// properties.put(key, resource.getString(key));
// }
// return properties;
// }
//
// public String getErrorMessage(Throwable e, String... variables) {
// String message = errorMessages.getProperty(e.getClass().getName());
// return message == null ? String.format(errorMessages.getProperty("standardMessage"), e.getClass().getName()) : String.format(message, variables);
// }
//
// public String getErrorMessage(Class exceptionClass, String... variables) {
// String message = errorMessages.getProperty(exceptionClass.getName());
// return message == null ? String.format(errorMessages.getProperty("standardMessage"), exceptionClass.getName()) : String.format(message, variables);
// }
// }
//
// Path: src/main/java/com/tngtech/configbuilder/exception/ValidatorException.java
// public class ValidatorException extends RuntimeException {
//
// Set<ConstraintViolation> constraintViolations;
//
// public <T> ValidatorException(String message, Set<ConstraintViolation<T>> constraintViolations) {
// super(message);
// this.constraintViolations = Sets.newHashSet(Iterables.transform(constraintViolations, new Function<ConstraintViolation<T>, ConstraintViolation>() {
// @Override
// public ConstraintViolation apply(ConstraintViolation<T> constraintViolation) {
// return constraintViolation;
// }
// }));
// }
//
// public ValidatorException(String message, Throwable e) {
// super(message, e);
// }
// }
// Path: src/test/java/com/tngtech/configbuilder/util/ConfigValidatorTest.java
import com.google.common.collect.Sets;
import com.tngtech.configbuilder.annotation.validation.Validation;
import com.tngtech.configbuilder.configuration.ErrorMessageSetup;
import com.tngtech.configbuilder.exception.ValidatorException;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.mockito.Matchers;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import javax.validation.ConstraintViolation;
import javax.validation.ValidatorFactory;
import java.util.Set;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
package com.tngtech.configbuilder.util;
@RunWith(MockitoJUnitRunner.class)
public class ConfigValidatorTest {
private static class TestConfig {
@Validation
private void validate() {
throw new RuntimeException();
}
}
private ConfigValidator<TestConfig> configValidator;
@Mock
private ConfigBuilderFactory configBuilderFactory;
@Mock
private ValidatorFactory validatorFactory;
@Mock
private javax.validation.Validator validator;
@Mock
private TestConfig testConfig;
@Mock
private ConstraintViolation<TestConfig> constraintViolation1, constraintViolation2;
@Mock | private ErrorMessageSetup errorMessageSetup; |
bmatthias/config-builder | src/test/java/com/tngtech/configbuilder/util/ConfigValidatorTest.java | // Path: src/main/java/com/tngtech/configbuilder/configuration/ErrorMessageSetup.java
// public class ErrorMessageSetup {
//
// private Properties errorMessages;
//
// /**
// * loads the default error messages for the system locale, then merges them with additional error messages loaded with the PropertyLoader
// *
// * @param baseName the filename for additional error messages
// * @param propertyLoader the PropertyLoader used to load additional error messages
// */
// public void initialize(String baseName, PropertyLoader propertyLoader) {
// ResourceBundle resourceBundle = ResourceBundle.getBundle("errors");
// errorMessages = convertResourceBundleToProperties(resourceBundle);
// if (baseName != null) {
// errorMessages.putAll(propertyLoader.load(baseName));
// }
// }
//
// private Properties convertResourceBundleToProperties(ResourceBundle resource) {
// Properties properties = new Properties();
//
// Enumeration<String> keys = resource.getKeys();
// while (keys.hasMoreElements()) {
// String key = keys.nextElement();
// properties.put(key, resource.getString(key));
// }
// return properties;
// }
//
// public String getErrorMessage(Throwable e, String... variables) {
// String message = errorMessages.getProperty(e.getClass().getName());
// return message == null ? String.format(errorMessages.getProperty("standardMessage"), e.getClass().getName()) : String.format(message, variables);
// }
//
// public String getErrorMessage(Class exceptionClass, String... variables) {
// String message = errorMessages.getProperty(exceptionClass.getName());
// return message == null ? String.format(errorMessages.getProperty("standardMessage"), exceptionClass.getName()) : String.format(message, variables);
// }
// }
//
// Path: src/main/java/com/tngtech/configbuilder/exception/ValidatorException.java
// public class ValidatorException extends RuntimeException {
//
// Set<ConstraintViolation> constraintViolations;
//
// public <T> ValidatorException(String message, Set<ConstraintViolation<T>> constraintViolations) {
// super(message);
// this.constraintViolations = Sets.newHashSet(Iterables.transform(constraintViolations, new Function<ConstraintViolation<T>, ConstraintViolation>() {
// @Override
// public ConstraintViolation apply(ConstraintViolation<T> constraintViolation) {
// return constraintViolation;
// }
// }));
// }
//
// public ValidatorException(String message, Throwable e) {
// super(message, e);
// }
// }
| import com.google.common.collect.Sets;
import com.tngtech.configbuilder.annotation.validation.Validation;
import com.tngtech.configbuilder.configuration.ErrorMessageSetup;
import com.tngtech.configbuilder.exception.ValidatorException;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.mockito.Matchers;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import javax.validation.ConstraintViolation;
import javax.validation.ValidatorFactory;
import java.util.Set;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when; | private TestConfig testConfig;
@Mock
private ConstraintViolation<TestConfig> constraintViolation1, constraintViolation2;
@Mock
private ErrorMessageSetup errorMessageSetup;
@Mock
private AnnotationHelper annotationHelper;
@Rule
public ExpectedException expectedException = ExpectedException.none();
@Before
public void setUp() throws Exception {
when(configBuilderFactory.getInstance(AnnotationHelper.class)).thenReturn(annotationHelper);
when(configBuilderFactory.getInstance(ErrorMessageSetup.class)).thenReturn(errorMessageSetup);
when(configBuilderFactory.getInstance(ValidatorFactory.class)).thenReturn(validatorFactory);
when(validatorFactory.getValidator()).thenReturn(validator);
configValidator = new ConfigValidator<>(configBuilderFactory);
}
@Test
public void testValidateWithConstraintViolations() throws Exception {
Set<ConstraintViolation<TestConfig>> constraintViolations = Sets.newHashSet(constraintViolation1, constraintViolation2);
when(validator.validate(testConfig)).thenReturn(constraintViolations);
when(errorMessageSetup.getErrorMessage(Matchers.any(Class.class))).thenReturn("Validation found the following constraint violations:");
| // Path: src/main/java/com/tngtech/configbuilder/configuration/ErrorMessageSetup.java
// public class ErrorMessageSetup {
//
// private Properties errorMessages;
//
// /**
// * loads the default error messages for the system locale, then merges them with additional error messages loaded with the PropertyLoader
// *
// * @param baseName the filename for additional error messages
// * @param propertyLoader the PropertyLoader used to load additional error messages
// */
// public void initialize(String baseName, PropertyLoader propertyLoader) {
// ResourceBundle resourceBundle = ResourceBundle.getBundle("errors");
// errorMessages = convertResourceBundleToProperties(resourceBundle);
// if (baseName != null) {
// errorMessages.putAll(propertyLoader.load(baseName));
// }
// }
//
// private Properties convertResourceBundleToProperties(ResourceBundle resource) {
// Properties properties = new Properties();
//
// Enumeration<String> keys = resource.getKeys();
// while (keys.hasMoreElements()) {
// String key = keys.nextElement();
// properties.put(key, resource.getString(key));
// }
// return properties;
// }
//
// public String getErrorMessage(Throwable e, String... variables) {
// String message = errorMessages.getProperty(e.getClass().getName());
// return message == null ? String.format(errorMessages.getProperty("standardMessage"), e.getClass().getName()) : String.format(message, variables);
// }
//
// public String getErrorMessage(Class exceptionClass, String... variables) {
// String message = errorMessages.getProperty(exceptionClass.getName());
// return message == null ? String.format(errorMessages.getProperty("standardMessage"), exceptionClass.getName()) : String.format(message, variables);
// }
// }
//
// Path: src/main/java/com/tngtech/configbuilder/exception/ValidatorException.java
// public class ValidatorException extends RuntimeException {
//
// Set<ConstraintViolation> constraintViolations;
//
// public <T> ValidatorException(String message, Set<ConstraintViolation<T>> constraintViolations) {
// super(message);
// this.constraintViolations = Sets.newHashSet(Iterables.transform(constraintViolations, new Function<ConstraintViolation<T>, ConstraintViolation>() {
// @Override
// public ConstraintViolation apply(ConstraintViolation<T> constraintViolation) {
// return constraintViolation;
// }
// }));
// }
//
// public ValidatorException(String message, Throwable e) {
// super(message, e);
// }
// }
// Path: src/test/java/com/tngtech/configbuilder/util/ConfigValidatorTest.java
import com.google.common.collect.Sets;
import com.tngtech.configbuilder.annotation.validation.Validation;
import com.tngtech.configbuilder.configuration.ErrorMessageSetup;
import com.tngtech.configbuilder.exception.ValidatorException;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.mockito.Matchers;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import javax.validation.ConstraintViolation;
import javax.validation.ValidatorFactory;
import java.util.Set;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
private TestConfig testConfig;
@Mock
private ConstraintViolation<TestConfig> constraintViolation1, constraintViolation2;
@Mock
private ErrorMessageSetup errorMessageSetup;
@Mock
private AnnotationHelper annotationHelper;
@Rule
public ExpectedException expectedException = ExpectedException.none();
@Before
public void setUp() throws Exception {
when(configBuilderFactory.getInstance(AnnotationHelper.class)).thenReturn(annotationHelper);
when(configBuilderFactory.getInstance(ErrorMessageSetup.class)).thenReturn(errorMessageSetup);
when(configBuilderFactory.getInstance(ValidatorFactory.class)).thenReturn(validatorFactory);
when(validatorFactory.getValidator()).thenReturn(validator);
configValidator = new ConfigValidator<>(configBuilderFactory);
}
@Test
public void testValidateWithConstraintViolations() throws Exception {
Set<ConstraintViolation<TestConfig>> constraintViolations = Sets.newHashSet(constraintViolation1, constraintViolation2);
when(validator.validate(testConfig)).thenReturn(constraintViolations);
when(errorMessageSetup.getErrorMessage(Matchers.any(Class.class))).thenReturn("Validation found the following constraint violations:");
| expectedException.expect(ValidatorException.class); |
bmatthias/config-builder | src/test/java/com/tngtech/configbuilder/util/PropertyLoaderConfiguratorTest.java | // Path: src/test/java/com/tngtech/configbuilder/testclasses/TestConfig.java
// @PropertyExtension("testproperties")
// @PropertySuffixes(extraSuffixes = {"test"})
// @PropertyLocations(resourcesForClasses = {PropertyLoader.class})
// @PropertiesFiles("demoapp-configuration")
// public class TestConfig {
//
// public TestConfig() {
//
// }
//
// public class TestConfigFactory extends ValueTransformer<String,TestConfig> {
// public TestConfig transform(String input) {
// TestConfig testConfig = new TestConfig();
// testConfig.setSomeString(input);
// return testConfig;
// }
// }
//
// public static class ListElementIncrementer extends ValueTransformer<ArrayList<Integer>,ArrayList<Integer>> {
// public ArrayList<Integer> transform(ArrayList<Integer> input) {
// ArrayList<Integer> result = Lists.newArrayList();
// for(Integer element : input) {
// result.add(element + 1);
// }
// return result;
// }
// }
//
// @DefaultValue("3")
// @ImportedValue("someNumber")
// private int someNumber;
//
// @PropertyValue("keyThatDoesNotExist")
// private int shouldBeZero;
//
// @PropertyValue("a")
// private String someString;
//
// @CommandLineValue(shortOpt = "u", longOpt = "user")
// private boolean aBoolean;
//
// @LoadingOrder(value = {CommandLineValue.class})
// @CommandLineValue(shortOpt = "c", longOpt = "collection", hasArg = true, description = "command line option description")
// @ValueTransformers({CharacterSeparatedStringToStringListTransformer.class})
// private Collection<String> stringCollection;
//
// @DefaultValue("/etc,/usr")
// @ImportedValue("stringCollection")
// private HashSet<Path> pathCollection;
//
// @ImportedValue("stringCollection")
// private Iterable<String> copiedStringCollection;
//
// @Separator(";")
// @DefaultValue("0;1;2;3;4")
// @ValueTransformers(ListElementIncrementer.class)
// private List<Integer> integerList;
//
// @ValueTransformers(TestConfigFactory.class)
// private ArrayList<TestConfig> testConfigList;
//
// @EnvironmentVariableValue("HOME")
// private Path homeDir;
//
// @SystemPropertyValue("user.language")
// private String systemProperty;
//
// public void setSomeNumber(Integer someNumber) {
// this.someNumber = someNumber;
// }
//
// public void setSomeString(String someString) {
// this.someString = someString;
// }
//
// public void setBoolean(boolean aBoolean) {
// this.aBoolean = aBoolean;
// }
//
// public void setStringCollection(Collection<String> stringCollection) {
// this.stringCollection = stringCollection;
// }
//
// public void setHomeDir(Path homeDir) {
// this.homeDir = homeDir;
// }
//
// public void setSystemProperty(String systemProperty) {
// this.systemProperty = systemProperty;
// }
//
// public Collection<Path> getPathCollection() {
// return pathCollection;
// }
//
// public void setPathCollection(HashSet<Path> pathCollection) {
// this.pathCollection = pathCollection;
// }
//
// public List<Integer> getIntegerList() {
// return integerList;
// }
//
// public void setIntegerList(List<Integer> integerList) {
// this.integerList = integerList;
// }
//
// public ArrayList<TestConfig> getTestConfigList() {
// return testConfigList;
// }
//
// public Collection<String> getStringCollection() {
// return stringCollection;
// }
//
// public void setCopiedStringCollection(Iterable<String> copiedStringCollection) {
// this.copiedStringCollection = copiedStringCollection;
// }
//
// @Validation
// private void validate() {
// System.out.println("config validated");
// }
// }
| import com.google.common.collect.Lists;
import com.tngtech.configbuilder.annotation.propertyloaderconfiguration.*;
import com.tngtech.configbuilder.testclasses.TestConfig;
import com.tngtech.propertyloader.PropertyLoader;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import java.lang.annotation.Annotation;
import java.util.List;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when; | package com.tngtech.configbuilder.util;
@RunWith(MockitoJUnitRunner.class)
public class PropertyLoaderConfiguratorTest {
@Mock
private ConfigBuilderFactory configBuilderFactory;
@Mock
private AnnotationHelper annotationHelper;
@Mock
private PropertySuffixProcessor propertySuffixProcessor;
@Mock
private PropertyLocationsProcessor propertyLocationsProcessor;
@Mock
private PropertyLoader propertyLoader;
| // Path: src/test/java/com/tngtech/configbuilder/testclasses/TestConfig.java
// @PropertyExtension("testproperties")
// @PropertySuffixes(extraSuffixes = {"test"})
// @PropertyLocations(resourcesForClasses = {PropertyLoader.class})
// @PropertiesFiles("demoapp-configuration")
// public class TestConfig {
//
// public TestConfig() {
//
// }
//
// public class TestConfigFactory extends ValueTransformer<String,TestConfig> {
// public TestConfig transform(String input) {
// TestConfig testConfig = new TestConfig();
// testConfig.setSomeString(input);
// return testConfig;
// }
// }
//
// public static class ListElementIncrementer extends ValueTransformer<ArrayList<Integer>,ArrayList<Integer>> {
// public ArrayList<Integer> transform(ArrayList<Integer> input) {
// ArrayList<Integer> result = Lists.newArrayList();
// for(Integer element : input) {
// result.add(element + 1);
// }
// return result;
// }
// }
//
// @DefaultValue("3")
// @ImportedValue("someNumber")
// private int someNumber;
//
// @PropertyValue("keyThatDoesNotExist")
// private int shouldBeZero;
//
// @PropertyValue("a")
// private String someString;
//
// @CommandLineValue(shortOpt = "u", longOpt = "user")
// private boolean aBoolean;
//
// @LoadingOrder(value = {CommandLineValue.class})
// @CommandLineValue(shortOpt = "c", longOpt = "collection", hasArg = true, description = "command line option description")
// @ValueTransformers({CharacterSeparatedStringToStringListTransformer.class})
// private Collection<String> stringCollection;
//
// @DefaultValue("/etc,/usr")
// @ImportedValue("stringCollection")
// private HashSet<Path> pathCollection;
//
// @ImportedValue("stringCollection")
// private Iterable<String> copiedStringCollection;
//
// @Separator(";")
// @DefaultValue("0;1;2;3;4")
// @ValueTransformers(ListElementIncrementer.class)
// private List<Integer> integerList;
//
// @ValueTransformers(TestConfigFactory.class)
// private ArrayList<TestConfig> testConfigList;
//
// @EnvironmentVariableValue("HOME")
// private Path homeDir;
//
// @SystemPropertyValue("user.language")
// private String systemProperty;
//
// public void setSomeNumber(Integer someNumber) {
// this.someNumber = someNumber;
// }
//
// public void setSomeString(String someString) {
// this.someString = someString;
// }
//
// public void setBoolean(boolean aBoolean) {
// this.aBoolean = aBoolean;
// }
//
// public void setStringCollection(Collection<String> stringCollection) {
// this.stringCollection = stringCollection;
// }
//
// public void setHomeDir(Path homeDir) {
// this.homeDir = homeDir;
// }
//
// public void setSystemProperty(String systemProperty) {
// this.systemProperty = systemProperty;
// }
//
// public Collection<Path> getPathCollection() {
// return pathCollection;
// }
//
// public void setPathCollection(HashSet<Path> pathCollection) {
// this.pathCollection = pathCollection;
// }
//
// public List<Integer> getIntegerList() {
// return integerList;
// }
//
// public void setIntegerList(List<Integer> integerList) {
// this.integerList = integerList;
// }
//
// public ArrayList<TestConfig> getTestConfigList() {
// return testConfigList;
// }
//
// public Collection<String> getStringCollection() {
// return stringCollection;
// }
//
// public void setCopiedStringCollection(Iterable<String> copiedStringCollection) {
// this.copiedStringCollection = copiedStringCollection;
// }
//
// @Validation
// private void validate() {
// System.out.println("config validated");
// }
// }
// Path: src/test/java/com/tngtech/configbuilder/util/PropertyLoaderConfiguratorTest.java
import com.google.common.collect.Lists;
import com.tngtech.configbuilder.annotation.propertyloaderconfiguration.*;
import com.tngtech.configbuilder.testclasses.TestConfig;
import com.tngtech.propertyloader.PropertyLoader;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import java.lang.annotation.Annotation;
import java.util.List;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
package com.tngtech.configbuilder.util;
@RunWith(MockitoJUnitRunner.class)
public class PropertyLoaderConfiguratorTest {
@Mock
private ConfigBuilderFactory configBuilderFactory;
@Mock
private AnnotationHelper annotationHelper;
@Mock
private PropertySuffixProcessor propertySuffixProcessor;
@Mock
private PropertyLocationsProcessor propertyLocationsProcessor;
@Mock
private PropertyLoader propertyLoader;
| PropertySuffixes propertySuffixes = TestConfig.class.getAnnotation(PropertySuffixes.class); |
bmatthias/config-builder | src/test/java/com/tngtech/configbuilder/util/ConfigBuilderFactoryTest.java | // Path: src/main/java/com/tngtech/configbuilder/configuration/ErrorMessageSetup.java
// public class ErrorMessageSetup {
//
// private Properties errorMessages;
//
// /**
// * loads the default error messages for the system locale, then merges them with additional error messages loaded with the PropertyLoader
// *
// * @param baseName the filename for additional error messages
// * @param propertyLoader the PropertyLoader used to load additional error messages
// */
// public void initialize(String baseName, PropertyLoader propertyLoader) {
// ResourceBundle resourceBundle = ResourceBundle.getBundle("errors");
// errorMessages = convertResourceBundleToProperties(resourceBundle);
// if (baseName != null) {
// errorMessages.putAll(propertyLoader.load(baseName));
// }
// }
//
// private Properties convertResourceBundleToProperties(ResourceBundle resource) {
// Properties properties = new Properties();
//
// Enumeration<String> keys = resource.getKeys();
// while (keys.hasMoreElements()) {
// String key = keys.nextElement();
// properties.put(key, resource.getString(key));
// }
// return properties;
// }
//
// public String getErrorMessage(Throwable e, String... variables) {
// String message = errorMessages.getProperty(e.getClass().getName());
// return message == null ? String.format(errorMessages.getProperty("standardMessage"), e.getClass().getName()) : String.format(message, variables);
// }
//
// public String getErrorMessage(Class exceptionClass, String... variables) {
// String message = errorMessages.getProperty(exceptionClass.getName());
// return message == null ? String.format(errorMessages.getProperty("standardMessage"), exceptionClass.getName()) : String.format(message, variables);
// }
// }
//
// Path: src/main/java/com/tngtech/configbuilder/exception/FactoryInstantiationException.java
// public class FactoryInstantiationException extends RuntimeException {
// public FactoryInstantiationException(String errorMessage) {
// super(errorMessage);
// }
// }
| import com.tngtech.configbuilder.configuration.ErrorMessageSetup;
import com.tngtech.configbuilder.exception.FactoryInstantiationException;
import com.tngtech.propertyloader.PropertyLoader;
import org.apache.commons.cli.GnuParser;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import javax.validation.Validation;
import javax.validation.ValidatorFactory;
import java.util.List;
import static org.junit.Assert.assertEquals; | package com.tngtech.configbuilder.util;
public class ConfigBuilderFactoryTest {
public class InnerClass {
public class InnerInnerClass{}
}
public static class NestedClass {}
public static class ClassWithoutDefaultConstructor {
private ClassWithoutDefaultConstructor(){}
}
private ConfigBuilderFactory configBuilderFactory;
@Rule
public ExpectedException expectedException = ExpectedException.none();
@Before
public void setUp() throws Exception {
configBuilderFactory = new ConfigBuilderFactory();
configBuilderFactory.initialize();
}
@Test
public void testInitialize() throws Exception {
}
@Test
public void testGetInstance() throws Exception { | // Path: src/main/java/com/tngtech/configbuilder/configuration/ErrorMessageSetup.java
// public class ErrorMessageSetup {
//
// private Properties errorMessages;
//
// /**
// * loads the default error messages for the system locale, then merges them with additional error messages loaded with the PropertyLoader
// *
// * @param baseName the filename for additional error messages
// * @param propertyLoader the PropertyLoader used to load additional error messages
// */
// public void initialize(String baseName, PropertyLoader propertyLoader) {
// ResourceBundle resourceBundle = ResourceBundle.getBundle("errors");
// errorMessages = convertResourceBundleToProperties(resourceBundle);
// if (baseName != null) {
// errorMessages.putAll(propertyLoader.load(baseName));
// }
// }
//
// private Properties convertResourceBundleToProperties(ResourceBundle resource) {
// Properties properties = new Properties();
//
// Enumeration<String> keys = resource.getKeys();
// while (keys.hasMoreElements()) {
// String key = keys.nextElement();
// properties.put(key, resource.getString(key));
// }
// return properties;
// }
//
// public String getErrorMessage(Throwable e, String... variables) {
// String message = errorMessages.getProperty(e.getClass().getName());
// return message == null ? String.format(errorMessages.getProperty("standardMessage"), e.getClass().getName()) : String.format(message, variables);
// }
//
// public String getErrorMessage(Class exceptionClass, String... variables) {
// String message = errorMessages.getProperty(exceptionClass.getName());
// return message == null ? String.format(errorMessages.getProperty("standardMessage"), exceptionClass.getName()) : String.format(message, variables);
// }
// }
//
// Path: src/main/java/com/tngtech/configbuilder/exception/FactoryInstantiationException.java
// public class FactoryInstantiationException extends RuntimeException {
// public FactoryInstantiationException(String errorMessage) {
// super(errorMessage);
// }
// }
// Path: src/test/java/com/tngtech/configbuilder/util/ConfigBuilderFactoryTest.java
import com.tngtech.configbuilder.configuration.ErrorMessageSetup;
import com.tngtech.configbuilder.exception.FactoryInstantiationException;
import com.tngtech.propertyloader.PropertyLoader;
import org.apache.commons.cli.GnuParser;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import javax.validation.Validation;
import javax.validation.ValidatorFactory;
import java.util.List;
import static org.junit.Assert.assertEquals;
package com.tngtech.configbuilder.util;
public class ConfigBuilderFactoryTest {
public class InnerClass {
public class InnerInnerClass{}
}
public static class NestedClass {}
public static class ClassWithoutDefaultConstructor {
private ClassWithoutDefaultConstructor(){}
}
private ConfigBuilderFactory configBuilderFactory;
@Rule
public ExpectedException expectedException = ExpectedException.none();
@Before
public void setUp() throws Exception {
configBuilderFactory = new ConfigBuilderFactory();
configBuilderFactory.initialize();
}
@Test
public void testInitialize() throws Exception {
}
@Test
public void testGetInstance() throws Exception { | assertEquals(ErrorMessageSetup.class, configBuilderFactory.getInstance(ErrorMessageSetup.class).getClass()); |
bmatthias/config-builder | src/test/java/com/tngtech/configbuilder/util/ConfigBuilderFactoryTest.java | // Path: src/main/java/com/tngtech/configbuilder/configuration/ErrorMessageSetup.java
// public class ErrorMessageSetup {
//
// private Properties errorMessages;
//
// /**
// * loads the default error messages for the system locale, then merges them with additional error messages loaded with the PropertyLoader
// *
// * @param baseName the filename for additional error messages
// * @param propertyLoader the PropertyLoader used to load additional error messages
// */
// public void initialize(String baseName, PropertyLoader propertyLoader) {
// ResourceBundle resourceBundle = ResourceBundle.getBundle("errors");
// errorMessages = convertResourceBundleToProperties(resourceBundle);
// if (baseName != null) {
// errorMessages.putAll(propertyLoader.load(baseName));
// }
// }
//
// private Properties convertResourceBundleToProperties(ResourceBundle resource) {
// Properties properties = new Properties();
//
// Enumeration<String> keys = resource.getKeys();
// while (keys.hasMoreElements()) {
// String key = keys.nextElement();
// properties.put(key, resource.getString(key));
// }
// return properties;
// }
//
// public String getErrorMessage(Throwable e, String... variables) {
// String message = errorMessages.getProperty(e.getClass().getName());
// return message == null ? String.format(errorMessages.getProperty("standardMessage"), e.getClass().getName()) : String.format(message, variables);
// }
//
// public String getErrorMessage(Class exceptionClass, String... variables) {
// String message = errorMessages.getProperty(exceptionClass.getName());
// return message == null ? String.format(errorMessages.getProperty("standardMessage"), exceptionClass.getName()) : String.format(message, variables);
// }
// }
//
// Path: src/main/java/com/tngtech/configbuilder/exception/FactoryInstantiationException.java
// public class FactoryInstantiationException extends RuntimeException {
// public FactoryInstantiationException(String errorMessage) {
// super(errorMessage);
// }
// }
| import com.tngtech.configbuilder.configuration.ErrorMessageSetup;
import com.tngtech.configbuilder.exception.FactoryInstantiationException;
import com.tngtech.propertyloader.PropertyLoader;
import org.apache.commons.cli.GnuParser;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import javax.validation.Validation;
import javax.validation.ValidatorFactory;
import java.util.List;
import static org.junit.Assert.assertEquals; | package com.tngtech.configbuilder.util;
public class ConfigBuilderFactoryTest {
public class InnerClass {
public class InnerInnerClass{}
}
public static class NestedClass {}
public static class ClassWithoutDefaultConstructor {
private ClassWithoutDefaultConstructor(){}
}
private ConfigBuilderFactory configBuilderFactory;
@Rule
public ExpectedException expectedException = ExpectedException.none();
@Before
public void setUp() throws Exception {
configBuilderFactory = new ConfigBuilderFactory();
configBuilderFactory.initialize();
}
@Test
public void testInitialize() throws Exception {
}
@Test
public void testGetInstance() throws Exception {
assertEquals(ErrorMessageSetup.class, configBuilderFactory.getInstance(ErrorMessageSetup.class).getClass());
assertEquals(Validation.buildDefaultValidatorFactory().getClass(), configBuilderFactory.getInstance(ValidatorFactory.class).getClass());
//test instantiation of arbitrary class
assertEquals(GnuParser.class, configBuilderFactory.getInstance(GnuParser.class).getClass());
//test instantiation of nested and inner classes
assertEquals(InnerClass.class, configBuilderFactory.getInstance(InnerClass.class).getClass());
assertEquals(NestedClass.class, configBuilderFactory.getInstance(NestedClass.class).getClass());
}
| // Path: src/main/java/com/tngtech/configbuilder/configuration/ErrorMessageSetup.java
// public class ErrorMessageSetup {
//
// private Properties errorMessages;
//
// /**
// * loads the default error messages for the system locale, then merges them with additional error messages loaded with the PropertyLoader
// *
// * @param baseName the filename for additional error messages
// * @param propertyLoader the PropertyLoader used to load additional error messages
// */
// public void initialize(String baseName, PropertyLoader propertyLoader) {
// ResourceBundle resourceBundle = ResourceBundle.getBundle("errors");
// errorMessages = convertResourceBundleToProperties(resourceBundle);
// if (baseName != null) {
// errorMessages.putAll(propertyLoader.load(baseName));
// }
// }
//
// private Properties convertResourceBundleToProperties(ResourceBundle resource) {
// Properties properties = new Properties();
//
// Enumeration<String> keys = resource.getKeys();
// while (keys.hasMoreElements()) {
// String key = keys.nextElement();
// properties.put(key, resource.getString(key));
// }
// return properties;
// }
//
// public String getErrorMessage(Throwable e, String... variables) {
// String message = errorMessages.getProperty(e.getClass().getName());
// return message == null ? String.format(errorMessages.getProperty("standardMessage"), e.getClass().getName()) : String.format(message, variables);
// }
//
// public String getErrorMessage(Class exceptionClass, String... variables) {
// String message = errorMessages.getProperty(exceptionClass.getName());
// return message == null ? String.format(errorMessages.getProperty("standardMessage"), exceptionClass.getName()) : String.format(message, variables);
// }
// }
//
// Path: src/main/java/com/tngtech/configbuilder/exception/FactoryInstantiationException.java
// public class FactoryInstantiationException extends RuntimeException {
// public FactoryInstantiationException(String errorMessage) {
// super(errorMessage);
// }
// }
// Path: src/test/java/com/tngtech/configbuilder/util/ConfigBuilderFactoryTest.java
import com.tngtech.configbuilder.configuration.ErrorMessageSetup;
import com.tngtech.configbuilder.exception.FactoryInstantiationException;
import com.tngtech.propertyloader.PropertyLoader;
import org.apache.commons.cli.GnuParser;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import javax.validation.Validation;
import javax.validation.ValidatorFactory;
import java.util.List;
import static org.junit.Assert.assertEquals;
package com.tngtech.configbuilder.util;
public class ConfigBuilderFactoryTest {
public class InnerClass {
public class InnerInnerClass{}
}
public static class NestedClass {}
public static class ClassWithoutDefaultConstructor {
private ClassWithoutDefaultConstructor(){}
}
private ConfigBuilderFactory configBuilderFactory;
@Rule
public ExpectedException expectedException = ExpectedException.none();
@Before
public void setUp() throws Exception {
configBuilderFactory = new ConfigBuilderFactory();
configBuilderFactory.initialize();
}
@Test
public void testInitialize() throws Exception {
}
@Test
public void testGetInstance() throws Exception {
assertEquals(ErrorMessageSetup.class, configBuilderFactory.getInstance(ErrorMessageSetup.class).getClass());
assertEquals(Validation.buildDefaultValidatorFactory().getClass(), configBuilderFactory.getInstance(ValidatorFactory.class).getClass());
//test instantiation of arbitrary class
assertEquals(GnuParser.class, configBuilderFactory.getInstance(GnuParser.class).getClass());
//test instantiation of nested and inner classes
assertEquals(InnerClass.class, configBuilderFactory.getInstance(InnerClass.class).getClass());
assertEquals(NestedClass.class, configBuilderFactory.getInstance(NestedClass.class).getClass());
}
| @Test(expected = FactoryInstantiationException.class) |
bmatthias/config-builder | src/test/java/com/tngtech/configbuilder/annotation/valueextractor/DefaultValueProcessorTest.java | // Path: src/main/java/com/tngtech/configbuilder/util/ConfigBuilderFactory.java
// public class ConfigBuilderFactory {
//
// private Map<Class,Object> singletonMap = Maps.newHashMap();
//
// public <T> void initialize() {
//
// //Order is IMPORTANT!
//
// //configuration
// singletonMap.put(ErrorMessageSetup.class, new ErrorMessageSetup());
// singletonMap.put(BuilderConfiguration.class, new BuilderConfiguration());
//
// //util
// singletonMap.put(AnnotationHelper.class, new AnnotationHelper());
// singletonMap.put(GenericsAndCastingHelper.class, new GenericsAndCastingHelper());
// singletonMap.put(FieldValueExtractor.class, new FieldValueExtractor(this));
// singletonMap.put(FieldValueTransformer.class, new FieldValueTransformer(this));
// singletonMap.put(PropertyLoaderConfigurator.class, new PropertyLoaderConfigurator(this));
// singletonMap.put(ConstructionHelper.class, new ConstructionHelper<T>(this));
// singletonMap.put(FieldSetter.class, new FieldSetter<T>(this));
// singletonMap.put(ConfigValidator.class, new ConfigValidator<T>(this));
// singletonMap.put(CommandLineHelper.class, new CommandLineHelper(this));
//
// //AnnotationProcessors
// singletonMap.put(SystemPropertyProcessor.class, new SystemPropertyProcessor());
// singletonMap.put(PropertyValueProcessor.class, new PropertyValueProcessor());
// singletonMap.put(EnvironmentVariableProcessor.class, new EnvironmentVariableProcessor());
// singletonMap.put(CommandLineValueProcessor.class, new CommandLineValueProcessor());
// singletonMap.put(PropertySuffixProcessor.class, new PropertySuffixProcessor());
// singletonMap.put(PropertyLocationsProcessor.class, new PropertyLocationsProcessor());
// singletonMap.put(PropertyExtensionProcessor.class, new PropertyExtensionProcessor());
// singletonMap.put(PropertiesFilesProcessor.class, new PropertiesFilesProcessor());
// singletonMap.put(DefaultValueProcessor.class, new DefaultValueProcessor());
//
// //ValueTransformers
// singletonMap.put(StringOrPrimitiveToPrimitiveTransformer.class, new StringOrPrimitiveToPrimitiveTransformer());
// singletonMap.put(CollectionToArrayListTransformer.class, new CollectionToArrayListTransformer());
// singletonMap.put(CollectionToHashSetTransformer.class, new CollectionToHashSetTransformer());
// singletonMap.put(CharacterSeparatedStringToStringListTransformer.class, new CharacterSeparatedStringToStringListTransformer());
// singletonMap.put(CharacterSeparatedStringToStringSetTransformer.class, new CharacterSeparatedStringToStringSetTransformer());
// singletonMap.put(StringCollectionToCommaSeparatedStringTransformer.class, new StringCollectionToCommaSeparatedStringTransformer());
// singletonMap.put(StringToPathTransformer.class, new StringToPathTransformer());
//
// //other
// singletonMap.put(ValidatorFactory.class, Validation.buildDefaultValidatorFactory());
// }
//
// public <K> K getInstance(Class<K> clazz) {
// if(singletonMap.get(clazz) != null) {
// return (K)singletonMap.get(clazz);
// }
// else {
// return createInstance(clazz);
// }
// }
//
// //TODO: exception message
// public <K> K createInstance(Class<K> clazz) {
// try {
// return clazz.newInstance();
// } catch (IllegalAccessException e) {
// ErrorMessageSetup errorMessageSetup = (ErrorMessageSetup)singletonMap.get(ErrorMessageSetup.class);
// throw new FactoryInstantiationException(errorMessageSetup.getErrorMessage(FactoryInstantiationException.class, clazz.toString()));
// } catch (InstantiationException e) {
// return createInstanceOfInnerClass(clazz);
// }
// }
//
// //TODO: exception message
// private <K> K createInstanceOfInnerClass(Class<K> clazz) {
// Class superClass = clazz.getDeclaringClass();
// try {
// Object superInstance = superClass.newInstance();
// Constructor<K> constructor = clazz.getConstructor(superClass);
// return constructor.newInstance(superInstance);
// } catch (Exception e) {
// ErrorMessageSetup errorMessageSetup = (ErrorMessageSetup)singletonMap.get(ErrorMessageSetup.class);
// throw new FactoryInstantiationException(errorMessageSetup.getErrorMessage(FactoryInstantiationException.class, clazz.toString()));
// }
// }
// }
| import com.tngtech.configbuilder.util.ConfigBuilderFactory;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.when; | package com.tngtech.configbuilder.annotation.valueextractor;
@RunWith(MockitoJUnitRunner.class)
public class DefaultValueProcessorTest {
private DefaultValueProcessor defaultValueProcessor;
@Mock | // Path: src/main/java/com/tngtech/configbuilder/util/ConfigBuilderFactory.java
// public class ConfigBuilderFactory {
//
// private Map<Class,Object> singletonMap = Maps.newHashMap();
//
// public <T> void initialize() {
//
// //Order is IMPORTANT!
//
// //configuration
// singletonMap.put(ErrorMessageSetup.class, new ErrorMessageSetup());
// singletonMap.put(BuilderConfiguration.class, new BuilderConfiguration());
//
// //util
// singletonMap.put(AnnotationHelper.class, new AnnotationHelper());
// singletonMap.put(GenericsAndCastingHelper.class, new GenericsAndCastingHelper());
// singletonMap.put(FieldValueExtractor.class, new FieldValueExtractor(this));
// singletonMap.put(FieldValueTransformer.class, new FieldValueTransformer(this));
// singletonMap.put(PropertyLoaderConfigurator.class, new PropertyLoaderConfigurator(this));
// singletonMap.put(ConstructionHelper.class, new ConstructionHelper<T>(this));
// singletonMap.put(FieldSetter.class, new FieldSetter<T>(this));
// singletonMap.put(ConfigValidator.class, new ConfigValidator<T>(this));
// singletonMap.put(CommandLineHelper.class, new CommandLineHelper(this));
//
// //AnnotationProcessors
// singletonMap.put(SystemPropertyProcessor.class, new SystemPropertyProcessor());
// singletonMap.put(PropertyValueProcessor.class, new PropertyValueProcessor());
// singletonMap.put(EnvironmentVariableProcessor.class, new EnvironmentVariableProcessor());
// singletonMap.put(CommandLineValueProcessor.class, new CommandLineValueProcessor());
// singletonMap.put(PropertySuffixProcessor.class, new PropertySuffixProcessor());
// singletonMap.put(PropertyLocationsProcessor.class, new PropertyLocationsProcessor());
// singletonMap.put(PropertyExtensionProcessor.class, new PropertyExtensionProcessor());
// singletonMap.put(PropertiesFilesProcessor.class, new PropertiesFilesProcessor());
// singletonMap.put(DefaultValueProcessor.class, new DefaultValueProcessor());
//
// //ValueTransformers
// singletonMap.put(StringOrPrimitiveToPrimitiveTransformer.class, new StringOrPrimitiveToPrimitiveTransformer());
// singletonMap.put(CollectionToArrayListTransformer.class, new CollectionToArrayListTransformer());
// singletonMap.put(CollectionToHashSetTransformer.class, new CollectionToHashSetTransformer());
// singletonMap.put(CharacterSeparatedStringToStringListTransformer.class, new CharacterSeparatedStringToStringListTransformer());
// singletonMap.put(CharacterSeparatedStringToStringSetTransformer.class, new CharacterSeparatedStringToStringSetTransformer());
// singletonMap.put(StringCollectionToCommaSeparatedStringTransformer.class, new StringCollectionToCommaSeparatedStringTransformer());
// singletonMap.put(StringToPathTransformer.class, new StringToPathTransformer());
//
// //other
// singletonMap.put(ValidatorFactory.class, Validation.buildDefaultValidatorFactory());
// }
//
// public <K> K getInstance(Class<K> clazz) {
// if(singletonMap.get(clazz) != null) {
// return (K)singletonMap.get(clazz);
// }
// else {
// return createInstance(clazz);
// }
// }
//
// //TODO: exception message
// public <K> K createInstance(Class<K> clazz) {
// try {
// return clazz.newInstance();
// } catch (IllegalAccessException e) {
// ErrorMessageSetup errorMessageSetup = (ErrorMessageSetup)singletonMap.get(ErrorMessageSetup.class);
// throw new FactoryInstantiationException(errorMessageSetup.getErrorMessage(FactoryInstantiationException.class, clazz.toString()));
// } catch (InstantiationException e) {
// return createInstanceOfInnerClass(clazz);
// }
// }
//
// //TODO: exception message
// private <K> K createInstanceOfInnerClass(Class<K> clazz) {
// Class superClass = clazz.getDeclaringClass();
// try {
// Object superInstance = superClass.newInstance();
// Constructor<K> constructor = clazz.getConstructor(superClass);
// return constructor.newInstance(superInstance);
// } catch (Exception e) {
// ErrorMessageSetup errorMessageSetup = (ErrorMessageSetup)singletonMap.get(ErrorMessageSetup.class);
// throw new FactoryInstantiationException(errorMessageSetup.getErrorMessage(FactoryInstantiationException.class, clazz.toString()));
// }
// }
// }
// Path: src/test/java/com/tngtech/configbuilder/annotation/valueextractor/DefaultValueProcessorTest.java
import com.tngtech.configbuilder.util.ConfigBuilderFactory;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.when;
package com.tngtech.configbuilder.annotation.valueextractor;
@RunWith(MockitoJUnitRunner.class)
public class DefaultValueProcessorTest {
private DefaultValueProcessor defaultValueProcessor;
@Mock | private ConfigBuilderFactory configBuilderFactory; |
bmatthias/config-builder | src/main/java/com/tngtech/configbuilder/util/ConfigValidator.java | // Path: src/main/java/com/tngtech/configbuilder/configuration/ErrorMessageSetup.java
// public class ErrorMessageSetup {
//
// private Properties errorMessages;
//
// /**
// * loads the default error messages for the system locale, then merges them with additional error messages loaded with the PropertyLoader
// *
// * @param baseName the filename for additional error messages
// * @param propertyLoader the PropertyLoader used to load additional error messages
// */
// public void initialize(String baseName, PropertyLoader propertyLoader) {
// ResourceBundle resourceBundle = ResourceBundle.getBundle("errors");
// errorMessages = convertResourceBundleToProperties(resourceBundle);
// if (baseName != null) {
// errorMessages.putAll(propertyLoader.load(baseName));
// }
// }
//
// private Properties convertResourceBundleToProperties(ResourceBundle resource) {
// Properties properties = new Properties();
//
// Enumeration<String> keys = resource.getKeys();
// while (keys.hasMoreElements()) {
// String key = keys.nextElement();
// properties.put(key, resource.getString(key));
// }
// return properties;
// }
//
// public String getErrorMessage(Throwable e, String... variables) {
// String message = errorMessages.getProperty(e.getClass().getName());
// return message == null ? String.format(errorMessages.getProperty("standardMessage"), e.getClass().getName()) : String.format(message, variables);
// }
//
// public String getErrorMessage(Class exceptionClass, String... variables) {
// String message = errorMessages.getProperty(exceptionClass.getName());
// return message == null ? String.format(errorMessages.getProperty("standardMessage"), exceptionClass.getName()) : String.format(message, variables);
// }
// }
//
// Path: src/main/java/com/tngtech/configbuilder/exception/ValidatorException.java
// public class ValidatorException extends RuntimeException {
//
// Set<ConstraintViolation> constraintViolations;
//
// public <T> ValidatorException(String message, Set<ConstraintViolation<T>> constraintViolations) {
// super(message);
// this.constraintViolations = Sets.newHashSet(Iterables.transform(constraintViolations, new Function<ConstraintViolation<T>, ConstraintViolation>() {
// @Override
// public ConstraintViolation apply(ConstraintViolation<T> constraintViolation) {
// return constraintViolation;
// }
// }));
// }
//
// public ValidatorException(String message, Throwable e) {
// super(message, e);
// }
// }
| import com.tngtech.configbuilder.annotation.validation.Validation;
import com.tngtech.configbuilder.configuration.ErrorMessageSetup;
import com.tngtech.configbuilder.exception.ValidatorException;
import org.apache.log4j.Logger;
import javax.validation.ConstraintViolation;
import javax.validation.ValidatorFactory;
import java.lang.reflect.Method;
import java.util.Set; | package com.tngtech.configbuilder.util;
public class ConfigValidator<T> {
private final static Logger log = Logger.getLogger(ConfigValidator.class);
private final ConfigBuilderFactory configBuilderFactory; | // Path: src/main/java/com/tngtech/configbuilder/configuration/ErrorMessageSetup.java
// public class ErrorMessageSetup {
//
// private Properties errorMessages;
//
// /**
// * loads the default error messages for the system locale, then merges them with additional error messages loaded with the PropertyLoader
// *
// * @param baseName the filename for additional error messages
// * @param propertyLoader the PropertyLoader used to load additional error messages
// */
// public void initialize(String baseName, PropertyLoader propertyLoader) {
// ResourceBundle resourceBundle = ResourceBundle.getBundle("errors");
// errorMessages = convertResourceBundleToProperties(resourceBundle);
// if (baseName != null) {
// errorMessages.putAll(propertyLoader.load(baseName));
// }
// }
//
// private Properties convertResourceBundleToProperties(ResourceBundle resource) {
// Properties properties = new Properties();
//
// Enumeration<String> keys = resource.getKeys();
// while (keys.hasMoreElements()) {
// String key = keys.nextElement();
// properties.put(key, resource.getString(key));
// }
// return properties;
// }
//
// public String getErrorMessage(Throwable e, String... variables) {
// String message = errorMessages.getProperty(e.getClass().getName());
// return message == null ? String.format(errorMessages.getProperty("standardMessage"), e.getClass().getName()) : String.format(message, variables);
// }
//
// public String getErrorMessage(Class exceptionClass, String... variables) {
// String message = errorMessages.getProperty(exceptionClass.getName());
// return message == null ? String.format(errorMessages.getProperty("standardMessage"), exceptionClass.getName()) : String.format(message, variables);
// }
// }
//
// Path: src/main/java/com/tngtech/configbuilder/exception/ValidatorException.java
// public class ValidatorException extends RuntimeException {
//
// Set<ConstraintViolation> constraintViolations;
//
// public <T> ValidatorException(String message, Set<ConstraintViolation<T>> constraintViolations) {
// super(message);
// this.constraintViolations = Sets.newHashSet(Iterables.transform(constraintViolations, new Function<ConstraintViolation<T>, ConstraintViolation>() {
// @Override
// public ConstraintViolation apply(ConstraintViolation<T> constraintViolation) {
// return constraintViolation;
// }
// }));
// }
//
// public ValidatorException(String message, Throwable e) {
// super(message, e);
// }
// }
// Path: src/main/java/com/tngtech/configbuilder/util/ConfigValidator.java
import com.tngtech.configbuilder.annotation.validation.Validation;
import com.tngtech.configbuilder.configuration.ErrorMessageSetup;
import com.tngtech.configbuilder.exception.ValidatorException;
import org.apache.log4j.Logger;
import javax.validation.ConstraintViolation;
import javax.validation.ValidatorFactory;
import java.lang.reflect.Method;
import java.util.Set;
package com.tngtech.configbuilder.util;
public class ConfigValidator<T> {
private final static Logger log = Logger.getLogger(ConfigValidator.class);
private final ConfigBuilderFactory configBuilderFactory; | private final ErrorMessageSetup errorMessageSetup; |
bmatthias/config-builder | src/main/java/com/tngtech/configbuilder/util/ConfigValidator.java | // Path: src/main/java/com/tngtech/configbuilder/configuration/ErrorMessageSetup.java
// public class ErrorMessageSetup {
//
// private Properties errorMessages;
//
// /**
// * loads the default error messages for the system locale, then merges them with additional error messages loaded with the PropertyLoader
// *
// * @param baseName the filename for additional error messages
// * @param propertyLoader the PropertyLoader used to load additional error messages
// */
// public void initialize(String baseName, PropertyLoader propertyLoader) {
// ResourceBundle resourceBundle = ResourceBundle.getBundle("errors");
// errorMessages = convertResourceBundleToProperties(resourceBundle);
// if (baseName != null) {
// errorMessages.putAll(propertyLoader.load(baseName));
// }
// }
//
// private Properties convertResourceBundleToProperties(ResourceBundle resource) {
// Properties properties = new Properties();
//
// Enumeration<String> keys = resource.getKeys();
// while (keys.hasMoreElements()) {
// String key = keys.nextElement();
// properties.put(key, resource.getString(key));
// }
// return properties;
// }
//
// public String getErrorMessage(Throwable e, String... variables) {
// String message = errorMessages.getProperty(e.getClass().getName());
// return message == null ? String.format(errorMessages.getProperty("standardMessage"), e.getClass().getName()) : String.format(message, variables);
// }
//
// public String getErrorMessage(Class exceptionClass, String... variables) {
// String message = errorMessages.getProperty(exceptionClass.getName());
// return message == null ? String.format(errorMessages.getProperty("standardMessage"), exceptionClass.getName()) : String.format(message, variables);
// }
// }
//
// Path: src/main/java/com/tngtech/configbuilder/exception/ValidatorException.java
// public class ValidatorException extends RuntimeException {
//
// Set<ConstraintViolation> constraintViolations;
//
// public <T> ValidatorException(String message, Set<ConstraintViolation<T>> constraintViolations) {
// super(message);
// this.constraintViolations = Sets.newHashSet(Iterables.transform(constraintViolations, new Function<ConstraintViolation<T>, ConstraintViolation>() {
// @Override
// public ConstraintViolation apply(ConstraintViolation<T> constraintViolation) {
// return constraintViolation;
// }
// }));
// }
//
// public ValidatorException(String message, Throwable e) {
// super(message, e);
// }
// }
| import com.tngtech.configbuilder.annotation.validation.Validation;
import com.tngtech.configbuilder.configuration.ErrorMessageSetup;
import com.tngtech.configbuilder.exception.ValidatorException;
import org.apache.log4j.Logger;
import javax.validation.ConstraintViolation;
import javax.validation.ValidatorFactory;
import java.lang.reflect.Method;
import java.util.Set; | package com.tngtech.configbuilder.util;
public class ConfigValidator<T> {
private final static Logger log = Logger.getLogger(ConfigValidator.class);
private final ConfigBuilderFactory configBuilderFactory;
private final ErrorMessageSetup errorMessageSetup;
private final AnnotationHelper annotationHelper;
public ConfigValidator(ConfigBuilderFactory miscFactory) {
this.configBuilderFactory = miscFactory;
this.annotationHelper = configBuilderFactory.getInstance(AnnotationHelper.class);
this.errorMessageSetup = configBuilderFactory.getInstance(ErrorMessageSetup.class);
}
public void validate(T instanceOfConfigClass) {
log.info(String.format("validating instance of %s", instanceOfConfigClass.getClass()));
callValidationMethods(instanceOfConfigClass);
callJSRValidation(instanceOfConfigClass);
}
private void callValidationMethods(T instanceOfConfigClass) {
for (Method method : annotationHelper.getMethodsAnnotatedWith(instanceOfConfigClass.getClass(), Validation.class)) {
try {
method.setAccessible(true);
method.invoke(instanceOfConfigClass);
} catch (Exception e) { | // Path: src/main/java/com/tngtech/configbuilder/configuration/ErrorMessageSetup.java
// public class ErrorMessageSetup {
//
// private Properties errorMessages;
//
// /**
// * loads the default error messages for the system locale, then merges them with additional error messages loaded with the PropertyLoader
// *
// * @param baseName the filename for additional error messages
// * @param propertyLoader the PropertyLoader used to load additional error messages
// */
// public void initialize(String baseName, PropertyLoader propertyLoader) {
// ResourceBundle resourceBundle = ResourceBundle.getBundle("errors");
// errorMessages = convertResourceBundleToProperties(resourceBundle);
// if (baseName != null) {
// errorMessages.putAll(propertyLoader.load(baseName));
// }
// }
//
// private Properties convertResourceBundleToProperties(ResourceBundle resource) {
// Properties properties = new Properties();
//
// Enumeration<String> keys = resource.getKeys();
// while (keys.hasMoreElements()) {
// String key = keys.nextElement();
// properties.put(key, resource.getString(key));
// }
// return properties;
// }
//
// public String getErrorMessage(Throwable e, String... variables) {
// String message = errorMessages.getProperty(e.getClass().getName());
// return message == null ? String.format(errorMessages.getProperty("standardMessage"), e.getClass().getName()) : String.format(message, variables);
// }
//
// public String getErrorMessage(Class exceptionClass, String... variables) {
// String message = errorMessages.getProperty(exceptionClass.getName());
// return message == null ? String.format(errorMessages.getProperty("standardMessage"), exceptionClass.getName()) : String.format(message, variables);
// }
// }
//
// Path: src/main/java/com/tngtech/configbuilder/exception/ValidatorException.java
// public class ValidatorException extends RuntimeException {
//
// Set<ConstraintViolation> constraintViolations;
//
// public <T> ValidatorException(String message, Set<ConstraintViolation<T>> constraintViolations) {
// super(message);
// this.constraintViolations = Sets.newHashSet(Iterables.transform(constraintViolations, new Function<ConstraintViolation<T>, ConstraintViolation>() {
// @Override
// public ConstraintViolation apply(ConstraintViolation<T> constraintViolation) {
// return constraintViolation;
// }
// }));
// }
//
// public ValidatorException(String message, Throwable e) {
// super(message, e);
// }
// }
// Path: src/main/java/com/tngtech/configbuilder/util/ConfigValidator.java
import com.tngtech.configbuilder.annotation.validation.Validation;
import com.tngtech.configbuilder.configuration.ErrorMessageSetup;
import com.tngtech.configbuilder.exception.ValidatorException;
import org.apache.log4j.Logger;
import javax.validation.ConstraintViolation;
import javax.validation.ValidatorFactory;
import java.lang.reflect.Method;
import java.util.Set;
package com.tngtech.configbuilder.util;
public class ConfigValidator<T> {
private final static Logger log = Logger.getLogger(ConfigValidator.class);
private final ConfigBuilderFactory configBuilderFactory;
private final ErrorMessageSetup errorMessageSetup;
private final AnnotationHelper annotationHelper;
public ConfigValidator(ConfigBuilderFactory miscFactory) {
this.configBuilderFactory = miscFactory;
this.annotationHelper = configBuilderFactory.getInstance(AnnotationHelper.class);
this.errorMessageSetup = configBuilderFactory.getInstance(ErrorMessageSetup.class);
}
public void validate(T instanceOfConfigClass) {
log.info(String.format("validating instance of %s", instanceOfConfigClass.getClass()));
callValidationMethods(instanceOfConfigClass);
callJSRValidation(instanceOfConfigClass);
}
private void callValidationMethods(T instanceOfConfigClass) {
for (Method method : annotationHelper.getMethodsAnnotatedWith(instanceOfConfigClass.getClass(), Validation.class)) {
try {
method.setAccessible(true);
method.invoke(instanceOfConfigClass);
} catch (Exception e) { | throw new ValidatorException(errorMessageSetup.getErrorMessage(e), e); |
bmatthias/config-builder | src/test/java/com/tngtech/configbuilder/ConfigBuilderIntegrationTest.java | // Path: src/test/java/com/tngtech/configbuilder/testclasses/TestConfig.java
// @PropertyExtension("testproperties")
// @PropertySuffixes(extraSuffixes = {"test"})
// @PropertyLocations(resourcesForClasses = {PropertyLoader.class})
// @PropertiesFiles("demoapp-configuration")
// public class TestConfig {
//
// public TestConfig() {
//
// }
//
// public class TestConfigFactory extends ValueTransformer<String,TestConfig> {
// public TestConfig transform(String input) {
// TestConfig testConfig = new TestConfig();
// testConfig.setSomeString(input);
// return testConfig;
// }
// }
//
// public static class ListElementIncrementer extends ValueTransformer<ArrayList<Integer>,ArrayList<Integer>> {
// public ArrayList<Integer> transform(ArrayList<Integer> input) {
// ArrayList<Integer> result = Lists.newArrayList();
// for(Integer element : input) {
// result.add(element + 1);
// }
// return result;
// }
// }
//
// @DefaultValue("3")
// @ImportedValue("someNumber")
// private int someNumber;
//
// @PropertyValue("keyThatDoesNotExist")
// private int shouldBeZero;
//
// @PropertyValue("a")
// private String someString;
//
// @CommandLineValue(shortOpt = "u", longOpt = "user")
// private boolean aBoolean;
//
// @LoadingOrder(value = {CommandLineValue.class})
// @CommandLineValue(shortOpt = "c", longOpt = "collection", hasArg = true, description = "command line option description")
// @ValueTransformers({CharacterSeparatedStringToStringListTransformer.class})
// private Collection<String> stringCollection;
//
// @DefaultValue("/etc,/usr")
// @ImportedValue("stringCollection")
// private HashSet<Path> pathCollection;
//
// @ImportedValue("stringCollection")
// private Iterable<String> copiedStringCollection;
//
// @Separator(";")
// @DefaultValue("0;1;2;3;4")
// @ValueTransformers(ListElementIncrementer.class)
// private List<Integer> integerList;
//
// @ValueTransformers(TestConfigFactory.class)
// private ArrayList<TestConfig> testConfigList;
//
// @EnvironmentVariableValue("HOME")
// private Path homeDir;
//
// @SystemPropertyValue("user.language")
// private String systemProperty;
//
// public void setSomeNumber(Integer someNumber) {
// this.someNumber = someNumber;
// }
//
// public void setSomeString(String someString) {
// this.someString = someString;
// }
//
// public void setBoolean(boolean aBoolean) {
// this.aBoolean = aBoolean;
// }
//
// public void setStringCollection(Collection<String> stringCollection) {
// this.stringCollection = stringCollection;
// }
//
// public void setHomeDir(Path homeDir) {
// this.homeDir = homeDir;
// }
//
// public void setSystemProperty(String systemProperty) {
// this.systemProperty = systemProperty;
// }
//
// public Collection<Path> getPathCollection() {
// return pathCollection;
// }
//
// public void setPathCollection(HashSet<Path> pathCollection) {
// this.pathCollection = pathCollection;
// }
//
// public List<Integer> getIntegerList() {
// return integerList;
// }
//
// public void setIntegerList(List<Integer> integerList) {
// this.integerList = integerList;
// }
//
// public ArrayList<TestConfig> getTestConfigList() {
// return testConfigList;
// }
//
// public Collection<String> getStringCollection() {
// return stringCollection;
// }
//
// public void setCopiedStringCollection(Iterable<String> copiedStringCollection) {
// this.copiedStringCollection = copiedStringCollection;
// }
//
// @Validation
// private void validate() {
// System.out.println("config validated");
// }
// }
//
// Path: src/test/java/com/tngtech/configbuilder/testclasses/TestConfigWithoutDefaultConstructor.java
// @PropertyExtension("testproperties")
// @PropertySuffixes(extraSuffixes = {"test"})
// @PropertyLocations(resourcesForClasses = {PropertyLoader.class})
// @PropertiesFiles("demoapp-configuration")
// @LoadingOrder(value = {CommandLineValue.class, PropertyValue.class, DefaultValue.class})
// public class TestConfigWithoutDefaultConstructor {
//
// private int number;
//
// public TestConfigWithoutDefaultConstructor(Integer i) {
// this.number = i;
// }
//
//
// public int getNumber() {
// return number;
// }
// }
| import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import com.tngtech.configbuilder.testclasses.TestConfig;
import com.tngtech.configbuilder.testclasses.TestConfigWithoutDefaultConstructor;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.unitils.reflectionassert.ReflectionAssert.assertReflectionEquals; | package com.tngtech.configbuilder;
@RunWith(Parameterized.class)
public class ConfigBuilderIntegrationTest {
private final ByteArrayOutputStream outContent = new ByteArrayOutputStream();
private Class configClass;
private Object configInstance;
@Before
public void setUp() {
System.setOut(new PrintStream(outContent));
}
@After
public void tearDown() {
System.setOut(null);
}
@Parameterized.Parameters
public static Collection configs() { | // Path: src/test/java/com/tngtech/configbuilder/testclasses/TestConfig.java
// @PropertyExtension("testproperties")
// @PropertySuffixes(extraSuffixes = {"test"})
// @PropertyLocations(resourcesForClasses = {PropertyLoader.class})
// @PropertiesFiles("demoapp-configuration")
// public class TestConfig {
//
// public TestConfig() {
//
// }
//
// public class TestConfigFactory extends ValueTransformer<String,TestConfig> {
// public TestConfig transform(String input) {
// TestConfig testConfig = new TestConfig();
// testConfig.setSomeString(input);
// return testConfig;
// }
// }
//
// public static class ListElementIncrementer extends ValueTransformer<ArrayList<Integer>,ArrayList<Integer>> {
// public ArrayList<Integer> transform(ArrayList<Integer> input) {
// ArrayList<Integer> result = Lists.newArrayList();
// for(Integer element : input) {
// result.add(element + 1);
// }
// return result;
// }
// }
//
// @DefaultValue("3")
// @ImportedValue("someNumber")
// private int someNumber;
//
// @PropertyValue("keyThatDoesNotExist")
// private int shouldBeZero;
//
// @PropertyValue("a")
// private String someString;
//
// @CommandLineValue(shortOpt = "u", longOpt = "user")
// private boolean aBoolean;
//
// @LoadingOrder(value = {CommandLineValue.class})
// @CommandLineValue(shortOpt = "c", longOpt = "collection", hasArg = true, description = "command line option description")
// @ValueTransformers({CharacterSeparatedStringToStringListTransformer.class})
// private Collection<String> stringCollection;
//
// @DefaultValue("/etc,/usr")
// @ImportedValue("stringCollection")
// private HashSet<Path> pathCollection;
//
// @ImportedValue("stringCollection")
// private Iterable<String> copiedStringCollection;
//
// @Separator(";")
// @DefaultValue("0;1;2;3;4")
// @ValueTransformers(ListElementIncrementer.class)
// private List<Integer> integerList;
//
// @ValueTransformers(TestConfigFactory.class)
// private ArrayList<TestConfig> testConfigList;
//
// @EnvironmentVariableValue("HOME")
// private Path homeDir;
//
// @SystemPropertyValue("user.language")
// private String systemProperty;
//
// public void setSomeNumber(Integer someNumber) {
// this.someNumber = someNumber;
// }
//
// public void setSomeString(String someString) {
// this.someString = someString;
// }
//
// public void setBoolean(boolean aBoolean) {
// this.aBoolean = aBoolean;
// }
//
// public void setStringCollection(Collection<String> stringCollection) {
// this.stringCollection = stringCollection;
// }
//
// public void setHomeDir(Path homeDir) {
// this.homeDir = homeDir;
// }
//
// public void setSystemProperty(String systemProperty) {
// this.systemProperty = systemProperty;
// }
//
// public Collection<Path> getPathCollection() {
// return pathCollection;
// }
//
// public void setPathCollection(HashSet<Path> pathCollection) {
// this.pathCollection = pathCollection;
// }
//
// public List<Integer> getIntegerList() {
// return integerList;
// }
//
// public void setIntegerList(List<Integer> integerList) {
// this.integerList = integerList;
// }
//
// public ArrayList<TestConfig> getTestConfigList() {
// return testConfigList;
// }
//
// public Collection<String> getStringCollection() {
// return stringCollection;
// }
//
// public void setCopiedStringCollection(Iterable<String> copiedStringCollection) {
// this.copiedStringCollection = copiedStringCollection;
// }
//
// @Validation
// private void validate() {
// System.out.println("config validated");
// }
// }
//
// Path: src/test/java/com/tngtech/configbuilder/testclasses/TestConfigWithoutDefaultConstructor.java
// @PropertyExtension("testproperties")
// @PropertySuffixes(extraSuffixes = {"test"})
// @PropertyLocations(resourcesForClasses = {PropertyLoader.class})
// @PropertiesFiles("demoapp-configuration")
// @LoadingOrder(value = {CommandLineValue.class, PropertyValue.class, DefaultValue.class})
// public class TestConfigWithoutDefaultConstructor {
//
// private int number;
//
// public TestConfigWithoutDefaultConstructor(Integer i) {
// this.number = i;
// }
//
//
// public int getNumber() {
// return number;
// }
// }
// Path: src/test/java/com/tngtech/configbuilder/ConfigBuilderIntegrationTest.java
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import com.tngtech.configbuilder.testclasses.TestConfig;
import com.tngtech.configbuilder.testclasses.TestConfigWithoutDefaultConstructor;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.unitils.reflectionassert.ReflectionAssert.assertReflectionEquals;
package com.tngtech.configbuilder;
@RunWith(Parameterized.class)
public class ConfigBuilderIntegrationTest {
private final ByteArrayOutputStream outContent = new ByteArrayOutputStream();
private Class configClass;
private Object configInstance;
@Before
public void setUp() {
System.setOut(new PrintStream(outContent));
}
@After
public void tearDown() {
System.setOut(null);
}
@Parameterized.Parameters
public static Collection configs() { | TestConfig testConfig = new TestConfig(); |
bmatthias/config-builder | src/test/java/com/tngtech/configbuilder/util/FieldSetterTest.java | // Path: src/main/java/com/tngtech/configbuilder/configuration/BuilderConfiguration.java
// public class BuilderConfiguration {
//
// private Properties properties;
// private CommandLine commandLine;
// private Object importedConfiguration;
// private Class<? extends Annotation>[] annotationOrder = new Class[]{CommandLineValue.class, PropertyValue.class, EnvironmentVariableValue.class, SystemPropertyValue.class, ImportedValue.class, DefaultValue.class};
//
// public BuilderConfiguration() {
// properties = new Properties();
// commandLine = null;
// importedConfiguration = null;
// }
//
// public CommandLine getCommandLine() {
// return commandLine;
// }
//
// public Properties getProperties() {
// return properties;
// }
//
// public Object getImportedConfiguration() {
// return importedConfiguration;
// }
//
// public void setProperties(Properties properties) {
// this.properties = properties;
// }
//
// public void setCommandLine(CommandLine commandLine) {
// this.commandLine = commandLine;
// }
//
// public void setImportedConfiguration(Object importedConfiguration) {
// this.importedConfiguration = importedConfiguration;
// }
//
// public void setAnnotationOrder(Class<? extends Annotation>[] annotationOrder) {
// this.annotationOrder = annotationOrder;
// }
//
// public Class<? extends Annotation>[] getAnnotationOrder() {
// return annotationOrder;
// }
// }
//
// Path: src/main/java/com/tngtech/configbuilder/configuration/ErrorMessageSetup.java
// public class ErrorMessageSetup {
//
// private Properties errorMessages;
//
// /**
// * loads the default error messages for the system locale, then merges them with additional error messages loaded with the PropertyLoader
// *
// * @param baseName the filename for additional error messages
// * @param propertyLoader the PropertyLoader used to load additional error messages
// */
// public void initialize(String baseName, PropertyLoader propertyLoader) {
// ResourceBundle resourceBundle = ResourceBundle.getBundle("errors");
// errorMessages = convertResourceBundleToProperties(resourceBundle);
// if (baseName != null) {
// errorMessages.putAll(propertyLoader.load(baseName));
// }
// }
//
// private Properties convertResourceBundleToProperties(ResourceBundle resource) {
// Properties properties = new Properties();
//
// Enumeration<String> keys = resource.getKeys();
// while (keys.hasMoreElements()) {
// String key = keys.nextElement();
// properties.put(key, resource.getString(key));
// }
// return properties;
// }
//
// public String getErrorMessage(Throwable e, String... variables) {
// String message = errorMessages.getProperty(e.getClass().getName());
// return message == null ? String.format(errorMessages.getProperty("standardMessage"), e.getClass().getName()) : String.format(message, variables);
// }
//
// public String getErrorMessage(Class exceptionClass, String... variables) {
// String message = errorMessages.getProperty(exceptionClass.getName());
// return message == null ? String.format(errorMessages.getProperty("standardMessage"), exceptionClass.getName()) : String.format(message, variables);
// }
// }
//
// Path: src/main/java/com/tngtech/configbuilder/exception/ConfigBuilderException.java
// public class ConfigBuilderException extends RuntimeException {
//
// public ConfigBuilderException(String message, Throwable e) {
// super(message, e);
// }
// }
| import com.tngtech.configbuilder.annotation.valueextractor.DefaultValue;
import com.tngtech.configbuilder.configuration.BuilderConfiguration;
import com.tngtech.configbuilder.configuration.ErrorMessageSetup;
import com.tngtech.configbuilder.exception.ConfigBuilderException;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.mockito.Matchers;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import java.lang.reflect.Field;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.when; | package com.tngtech.configbuilder.util;
@RunWith(MockitoJUnitRunner.class)
public class FieldSetterTest {
@Rule
public ExpectedException expectedException = ExpectedException.none();
private static class TestConfig {
@DefaultValue("stringValue")
public String emptyTestString;
@DefaultValue("stringValue")
public String testString = "defaultValue";
}
private static class TestConfigForIllegalArgumentException {
@DefaultValue("user")
public int testInt;
}
private static class TestConfigWithoutAnnotations {
public String testString = "testString";
}
@Mock | // Path: src/main/java/com/tngtech/configbuilder/configuration/BuilderConfiguration.java
// public class BuilderConfiguration {
//
// private Properties properties;
// private CommandLine commandLine;
// private Object importedConfiguration;
// private Class<? extends Annotation>[] annotationOrder = new Class[]{CommandLineValue.class, PropertyValue.class, EnvironmentVariableValue.class, SystemPropertyValue.class, ImportedValue.class, DefaultValue.class};
//
// public BuilderConfiguration() {
// properties = new Properties();
// commandLine = null;
// importedConfiguration = null;
// }
//
// public CommandLine getCommandLine() {
// return commandLine;
// }
//
// public Properties getProperties() {
// return properties;
// }
//
// public Object getImportedConfiguration() {
// return importedConfiguration;
// }
//
// public void setProperties(Properties properties) {
// this.properties = properties;
// }
//
// public void setCommandLine(CommandLine commandLine) {
// this.commandLine = commandLine;
// }
//
// public void setImportedConfiguration(Object importedConfiguration) {
// this.importedConfiguration = importedConfiguration;
// }
//
// public void setAnnotationOrder(Class<? extends Annotation>[] annotationOrder) {
// this.annotationOrder = annotationOrder;
// }
//
// public Class<? extends Annotation>[] getAnnotationOrder() {
// return annotationOrder;
// }
// }
//
// Path: src/main/java/com/tngtech/configbuilder/configuration/ErrorMessageSetup.java
// public class ErrorMessageSetup {
//
// private Properties errorMessages;
//
// /**
// * loads the default error messages for the system locale, then merges them with additional error messages loaded with the PropertyLoader
// *
// * @param baseName the filename for additional error messages
// * @param propertyLoader the PropertyLoader used to load additional error messages
// */
// public void initialize(String baseName, PropertyLoader propertyLoader) {
// ResourceBundle resourceBundle = ResourceBundle.getBundle("errors");
// errorMessages = convertResourceBundleToProperties(resourceBundle);
// if (baseName != null) {
// errorMessages.putAll(propertyLoader.load(baseName));
// }
// }
//
// private Properties convertResourceBundleToProperties(ResourceBundle resource) {
// Properties properties = new Properties();
//
// Enumeration<String> keys = resource.getKeys();
// while (keys.hasMoreElements()) {
// String key = keys.nextElement();
// properties.put(key, resource.getString(key));
// }
// return properties;
// }
//
// public String getErrorMessage(Throwable e, String... variables) {
// String message = errorMessages.getProperty(e.getClass().getName());
// return message == null ? String.format(errorMessages.getProperty("standardMessage"), e.getClass().getName()) : String.format(message, variables);
// }
//
// public String getErrorMessage(Class exceptionClass, String... variables) {
// String message = errorMessages.getProperty(exceptionClass.getName());
// return message == null ? String.format(errorMessages.getProperty("standardMessage"), exceptionClass.getName()) : String.format(message, variables);
// }
// }
//
// Path: src/main/java/com/tngtech/configbuilder/exception/ConfigBuilderException.java
// public class ConfigBuilderException extends RuntimeException {
//
// public ConfigBuilderException(String message, Throwable e) {
// super(message, e);
// }
// }
// Path: src/test/java/com/tngtech/configbuilder/util/FieldSetterTest.java
import com.tngtech.configbuilder.annotation.valueextractor.DefaultValue;
import com.tngtech.configbuilder.configuration.BuilderConfiguration;
import com.tngtech.configbuilder.configuration.ErrorMessageSetup;
import com.tngtech.configbuilder.exception.ConfigBuilderException;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.mockito.Matchers;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import java.lang.reflect.Field;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.when;
package com.tngtech.configbuilder.util;
@RunWith(MockitoJUnitRunner.class)
public class FieldSetterTest {
@Rule
public ExpectedException expectedException = ExpectedException.none();
private static class TestConfig {
@DefaultValue("stringValue")
public String emptyTestString;
@DefaultValue("stringValue")
public String testString = "defaultValue";
}
private static class TestConfigForIllegalArgumentException {
@DefaultValue("user")
public int testInt;
}
private static class TestConfigWithoutAnnotations {
public String testString = "testString";
}
@Mock | private BuilderConfiguration builderConfiguration; |
bmatthias/config-builder | src/test/java/com/tngtech/configbuilder/util/FieldSetterTest.java | // Path: src/main/java/com/tngtech/configbuilder/configuration/BuilderConfiguration.java
// public class BuilderConfiguration {
//
// private Properties properties;
// private CommandLine commandLine;
// private Object importedConfiguration;
// private Class<? extends Annotation>[] annotationOrder = new Class[]{CommandLineValue.class, PropertyValue.class, EnvironmentVariableValue.class, SystemPropertyValue.class, ImportedValue.class, DefaultValue.class};
//
// public BuilderConfiguration() {
// properties = new Properties();
// commandLine = null;
// importedConfiguration = null;
// }
//
// public CommandLine getCommandLine() {
// return commandLine;
// }
//
// public Properties getProperties() {
// return properties;
// }
//
// public Object getImportedConfiguration() {
// return importedConfiguration;
// }
//
// public void setProperties(Properties properties) {
// this.properties = properties;
// }
//
// public void setCommandLine(CommandLine commandLine) {
// this.commandLine = commandLine;
// }
//
// public void setImportedConfiguration(Object importedConfiguration) {
// this.importedConfiguration = importedConfiguration;
// }
//
// public void setAnnotationOrder(Class<? extends Annotation>[] annotationOrder) {
// this.annotationOrder = annotationOrder;
// }
//
// public Class<? extends Annotation>[] getAnnotationOrder() {
// return annotationOrder;
// }
// }
//
// Path: src/main/java/com/tngtech/configbuilder/configuration/ErrorMessageSetup.java
// public class ErrorMessageSetup {
//
// private Properties errorMessages;
//
// /**
// * loads the default error messages for the system locale, then merges them with additional error messages loaded with the PropertyLoader
// *
// * @param baseName the filename for additional error messages
// * @param propertyLoader the PropertyLoader used to load additional error messages
// */
// public void initialize(String baseName, PropertyLoader propertyLoader) {
// ResourceBundle resourceBundle = ResourceBundle.getBundle("errors");
// errorMessages = convertResourceBundleToProperties(resourceBundle);
// if (baseName != null) {
// errorMessages.putAll(propertyLoader.load(baseName));
// }
// }
//
// private Properties convertResourceBundleToProperties(ResourceBundle resource) {
// Properties properties = new Properties();
//
// Enumeration<String> keys = resource.getKeys();
// while (keys.hasMoreElements()) {
// String key = keys.nextElement();
// properties.put(key, resource.getString(key));
// }
// return properties;
// }
//
// public String getErrorMessage(Throwable e, String... variables) {
// String message = errorMessages.getProperty(e.getClass().getName());
// return message == null ? String.format(errorMessages.getProperty("standardMessage"), e.getClass().getName()) : String.format(message, variables);
// }
//
// public String getErrorMessage(Class exceptionClass, String... variables) {
// String message = errorMessages.getProperty(exceptionClass.getName());
// return message == null ? String.format(errorMessages.getProperty("standardMessage"), exceptionClass.getName()) : String.format(message, variables);
// }
// }
//
// Path: src/main/java/com/tngtech/configbuilder/exception/ConfigBuilderException.java
// public class ConfigBuilderException extends RuntimeException {
//
// public ConfigBuilderException(String message, Throwable e) {
// super(message, e);
// }
// }
| import com.tngtech.configbuilder.annotation.valueextractor.DefaultValue;
import com.tngtech.configbuilder.configuration.BuilderConfiguration;
import com.tngtech.configbuilder.configuration.ErrorMessageSetup;
import com.tngtech.configbuilder.exception.ConfigBuilderException;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.mockito.Matchers;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import java.lang.reflect.Field;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.when; | package com.tngtech.configbuilder.util;
@RunWith(MockitoJUnitRunner.class)
public class FieldSetterTest {
@Rule
public ExpectedException expectedException = ExpectedException.none();
private static class TestConfig {
@DefaultValue("stringValue")
public String emptyTestString;
@DefaultValue("stringValue")
public String testString = "defaultValue";
}
private static class TestConfigForIllegalArgumentException {
@DefaultValue("user")
public int testInt;
}
private static class TestConfigWithoutAnnotations {
public String testString = "testString";
}
@Mock
private BuilderConfiguration builderConfiguration;
@Mock
private FieldValueTransformer fieldValueTransformer;
@Mock
private FieldValueExtractor fieldValueExtractor;
@Mock | // Path: src/main/java/com/tngtech/configbuilder/configuration/BuilderConfiguration.java
// public class BuilderConfiguration {
//
// private Properties properties;
// private CommandLine commandLine;
// private Object importedConfiguration;
// private Class<? extends Annotation>[] annotationOrder = new Class[]{CommandLineValue.class, PropertyValue.class, EnvironmentVariableValue.class, SystemPropertyValue.class, ImportedValue.class, DefaultValue.class};
//
// public BuilderConfiguration() {
// properties = new Properties();
// commandLine = null;
// importedConfiguration = null;
// }
//
// public CommandLine getCommandLine() {
// return commandLine;
// }
//
// public Properties getProperties() {
// return properties;
// }
//
// public Object getImportedConfiguration() {
// return importedConfiguration;
// }
//
// public void setProperties(Properties properties) {
// this.properties = properties;
// }
//
// public void setCommandLine(CommandLine commandLine) {
// this.commandLine = commandLine;
// }
//
// public void setImportedConfiguration(Object importedConfiguration) {
// this.importedConfiguration = importedConfiguration;
// }
//
// public void setAnnotationOrder(Class<? extends Annotation>[] annotationOrder) {
// this.annotationOrder = annotationOrder;
// }
//
// public Class<? extends Annotation>[] getAnnotationOrder() {
// return annotationOrder;
// }
// }
//
// Path: src/main/java/com/tngtech/configbuilder/configuration/ErrorMessageSetup.java
// public class ErrorMessageSetup {
//
// private Properties errorMessages;
//
// /**
// * loads the default error messages for the system locale, then merges them with additional error messages loaded with the PropertyLoader
// *
// * @param baseName the filename for additional error messages
// * @param propertyLoader the PropertyLoader used to load additional error messages
// */
// public void initialize(String baseName, PropertyLoader propertyLoader) {
// ResourceBundle resourceBundle = ResourceBundle.getBundle("errors");
// errorMessages = convertResourceBundleToProperties(resourceBundle);
// if (baseName != null) {
// errorMessages.putAll(propertyLoader.load(baseName));
// }
// }
//
// private Properties convertResourceBundleToProperties(ResourceBundle resource) {
// Properties properties = new Properties();
//
// Enumeration<String> keys = resource.getKeys();
// while (keys.hasMoreElements()) {
// String key = keys.nextElement();
// properties.put(key, resource.getString(key));
// }
// return properties;
// }
//
// public String getErrorMessage(Throwable e, String... variables) {
// String message = errorMessages.getProperty(e.getClass().getName());
// return message == null ? String.format(errorMessages.getProperty("standardMessage"), e.getClass().getName()) : String.format(message, variables);
// }
//
// public String getErrorMessage(Class exceptionClass, String... variables) {
// String message = errorMessages.getProperty(exceptionClass.getName());
// return message == null ? String.format(errorMessages.getProperty("standardMessage"), exceptionClass.getName()) : String.format(message, variables);
// }
// }
//
// Path: src/main/java/com/tngtech/configbuilder/exception/ConfigBuilderException.java
// public class ConfigBuilderException extends RuntimeException {
//
// public ConfigBuilderException(String message, Throwable e) {
// super(message, e);
// }
// }
// Path: src/test/java/com/tngtech/configbuilder/util/FieldSetterTest.java
import com.tngtech.configbuilder.annotation.valueextractor.DefaultValue;
import com.tngtech.configbuilder.configuration.BuilderConfiguration;
import com.tngtech.configbuilder.configuration.ErrorMessageSetup;
import com.tngtech.configbuilder.exception.ConfigBuilderException;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.mockito.Matchers;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import java.lang.reflect.Field;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.when;
package com.tngtech.configbuilder.util;
@RunWith(MockitoJUnitRunner.class)
public class FieldSetterTest {
@Rule
public ExpectedException expectedException = ExpectedException.none();
private static class TestConfig {
@DefaultValue("stringValue")
public String emptyTestString;
@DefaultValue("stringValue")
public String testString = "defaultValue";
}
private static class TestConfigForIllegalArgumentException {
@DefaultValue("user")
public int testInt;
}
private static class TestConfigWithoutAnnotations {
public String testString = "testString";
}
@Mock
private BuilderConfiguration builderConfiguration;
@Mock
private FieldValueTransformer fieldValueTransformer;
@Mock
private FieldValueExtractor fieldValueExtractor;
@Mock | private ErrorMessageSetup errorMessageSetup; |
bmatthias/config-builder | src/test/java/com/tngtech/configbuilder/util/FieldSetterTest.java | // Path: src/main/java/com/tngtech/configbuilder/configuration/BuilderConfiguration.java
// public class BuilderConfiguration {
//
// private Properties properties;
// private CommandLine commandLine;
// private Object importedConfiguration;
// private Class<? extends Annotation>[] annotationOrder = new Class[]{CommandLineValue.class, PropertyValue.class, EnvironmentVariableValue.class, SystemPropertyValue.class, ImportedValue.class, DefaultValue.class};
//
// public BuilderConfiguration() {
// properties = new Properties();
// commandLine = null;
// importedConfiguration = null;
// }
//
// public CommandLine getCommandLine() {
// return commandLine;
// }
//
// public Properties getProperties() {
// return properties;
// }
//
// public Object getImportedConfiguration() {
// return importedConfiguration;
// }
//
// public void setProperties(Properties properties) {
// this.properties = properties;
// }
//
// public void setCommandLine(CommandLine commandLine) {
// this.commandLine = commandLine;
// }
//
// public void setImportedConfiguration(Object importedConfiguration) {
// this.importedConfiguration = importedConfiguration;
// }
//
// public void setAnnotationOrder(Class<? extends Annotation>[] annotationOrder) {
// this.annotationOrder = annotationOrder;
// }
//
// public Class<? extends Annotation>[] getAnnotationOrder() {
// return annotationOrder;
// }
// }
//
// Path: src/main/java/com/tngtech/configbuilder/configuration/ErrorMessageSetup.java
// public class ErrorMessageSetup {
//
// private Properties errorMessages;
//
// /**
// * loads the default error messages for the system locale, then merges them with additional error messages loaded with the PropertyLoader
// *
// * @param baseName the filename for additional error messages
// * @param propertyLoader the PropertyLoader used to load additional error messages
// */
// public void initialize(String baseName, PropertyLoader propertyLoader) {
// ResourceBundle resourceBundle = ResourceBundle.getBundle("errors");
// errorMessages = convertResourceBundleToProperties(resourceBundle);
// if (baseName != null) {
// errorMessages.putAll(propertyLoader.load(baseName));
// }
// }
//
// private Properties convertResourceBundleToProperties(ResourceBundle resource) {
// Properties properties = new Properties();
//
// Enumeration<String> keys = resource.getKeys();
// while (keys.hasMoreElements()) {
// String key = keys.nextElement();
// properties.put(key, resource.getString(key));
// }
// return properties;
// }
//
// public String getErrorMessage(Throwable e, String... variables) {
// String message = errorMessages.getProperty(e.getClass().getName());
// return message == null ? String.format(errorMessages.getProperty("standardMessage"), e.getClass().getName()) : String.format(message, variables);
// }
//
// public String getErrorMessage(Class exceptionClass, String... variables) {
// String message = errorMessages.getProperty(exceptionClass.getName());
// return message == null ? String.format(errorMessages.getProperty("standardMessage"), exceptionClass.getName()) : String.format(message, variables);
// }
// }
//
// Path: src/main/java/com/tngtech/configbuilder/exception/ConfigBuilderException.java
// public class ConfigBuilderException extends RuntimeException {
//
// public ConfigBuilderException(String message, Throwable e) {
// super(message, e);
// }
// }
| import com.tngtech.configbuilder.annotation.valueextractor.DefaultValue;
import com.tngtech.configbuilder.configuration.BuilderConfiguration;
import com.tngtech.configbuilder.configuration.ErrorMessageSetup;
import com.tngtech.configbuilder.exception.ConfigBuilderException;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.mockito.Matchers;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import java.lang.reflect.Field;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.when; | @Mock
private FieldValueTransformer fieldValueTransformer;
@Mock
private FieldValueExtractor fieldValueExtractor;
@Mock
private ErrorMessageSetup errorMessageSetup;
@Mock
private AnnotationHelper annotationHelper;
@Mock
private ConfigBuilderFactory configBuilderFactory;
@Before
public void setUp() throws Exception {
when(configBuilderFactory.getInstance(FieldValueTransformer.class)).thenReturn(fieldValueTransformer);
when(configBuilderFactory.getInstance(FieldValueExtractor.class)).thenReturn(fieldValueExtractor);
when(configBuilderFactory.getInstance(AnnotationHelper.class)).thenReturn(annotationHelper);
when(configBuilderFactory.getInstance(ErrorMessageSetup.class)).thenReturn(errorMessageSetup);
when(annotationHelper.fieldHasAnnotationAnnotatedWith(Matchers.any(Field.class), Matchers.any(Class.class))).thenReturn(true);
}
@Test
public void testSetFieldsThrowsIllegalArgumentException() throws Exception {
when(fieldValueExtractor.extractValue(Matchers.any(Field.class), Matchers.any(BuilderConfiguration.class))).thenReturn("stringValue");
when(fieldValueTransformer.transformFieldValue(Matchers.any(Field.class), Matchers.any(String.class))).thenReturn("stringValue");
when(errorMessageSetup.getErrorMessage(Matchers.any(IllegalArgumentException.class), Matchers.any(String.class), Matchers.any(String.class), Matchers.any(String.class))).thenReturn("IllegalArgumentException");
FieldSetter<TestConfigForIllegalArgumentException> fieldSetter = new FieldSetter<>(configBuilderFactory);
TestConfigForIllegalArgumentException testConfigForIllegalArgumentException = new TestConfigForIllegalArgumentException();
| // Path: src/main/java/com/tngtech/configbuilder/configuration/BuilderConfiguration.java
// public class BuilderConfiguration {
//
// private Properties properties;
// private CommandLine commandLine;
// private Object importedConfiguration;
// private Class<? extends Annotation>[] annotationOrder = new Class[]{CommandLineValue.class, PropertyValue.class, EnvironmentVariableValue.class, SystemPropertyValue.class, ImportedValue.class, DefaultValue.class};
//
// public BuilderConfiguration() {
// properties = new Properties();
// commandLine = null;
// importedConfiguration = null;
// }
//
// public CommandLine getCommandLine() {
// return commandLine;
// }
//
// public Properties getProperties() {
// return properties;
// }
//
// public Object getImportedConfiguration() {
// return importedConfiguration;
// }
//
// public void setProperties(Properties properties) {
// this.properties = properties;
// }
//
// public void setCommandLine(CommandLine commandLine) {
// this.commandLine = commandLine;
// }
//
// public void setImportedConfiguration(Object importedConfiguration) {
// this.importedConfiguration = importedConfiguration;
// }
//
// public void setAnnotationOrder(Class<? extends Annotation>[] annotationOrder) {
// this.annotationOrder = annotationOrder;
// }
//
// public Class<? extends Annotation>[] getAnnotationOrder() {
// return annotationOrder;
// }
// }
//
// Path: src/main/java/com/tngtech/configbuilder/configuration/ErrorMessageSetup.java
// public class ErrorMessageSetup {
//
// private Properties errorMessages;
//
// /**
// * loads the default error messages for the system locale, then merges them with additional error messages loaded with the PropertyLoader
// *
// * @param baseName the filename for additional error messages
// * @param propertyLoader the PropertyLoader used to load additional error messages
// */
// public void initialize(String baseName, PropertyLoader propertyLoader) {
// ResourceBundle resourceBundle = ResourceBundle.getBundle("errors");
// errorMessages = convertResourceBundleToProperties(resourceBundle);
// if (baseName != null) {
// errorMessages.putAll(propertyLoader.load(baseName));
// }
// }
//
// private Properties convertResourceBundleToProperties(ResourceBundle resource) {
// Properties properties = new Properties();
//
// Enumeration<String> keys = resource.getKeys();
// while (keys.hasMoreElements()) {
// String key = keys.nextElement();
// properties.put(key, resource.getString(key));
// }
// return properties;
// }
//
// public String getErrorMessage(Throwable e, String... variables) {
// String message = errorMessages.getProperty(e.getClass().getName());
// return message == null ? String.format(errorMessages.getProperty("standardMessage"), e.getClass().getName()) : String.format(message, variables);
// }
//
// public String getErrorMessage(Class exceptionClass, String... variables) {
// String message = errorMessages.getProperty(exceptionClass.getName());
// return message == null ? String.format(errorMessages.getProperty("standardMessage"), exceptionClass.getName()) : String.format(message, variables);
// }
// }
//
// Path: src/main/java/com/tngtech/configbuilder/exception/ConfigBuilderException.java
// public class ConfigBuilderException extends RuntimeException {
//
// public ConfigBuilderException(String message, Throwable e) {
// super(message, e);
// }
// }
// Path: src/test/java/com/tngtech/configbuilder/util/FieldSetterTest.java
import com.tngtech.configbuilder.annotation.valueextractor.DefaultValue;
import com.tngtech.configbuilder.configuration.BuilderConfiguration;
import com.tngtech.configbuilder.configuration.ErrorMessageSetup;
import com.tngtech.configbuilder.exception.ConfigBuilderException;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.mockito.Matchers;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import java.lang.reflect.Field;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.when;
@Mock
private FieldValueTransformer fieldValueTransformer;
@Mock
private FieldValueExtractor fieldValueExtractor;
@Mock
private ErrorMessageSetup errorMessageSetup;
@Mock
private AnnotationHelper annotationHelper;
@Mock
private ConfigBuilderFactory configBuilderFactory;
@Before
public void setUp() throws Exception {
when(configBuilderFactory.getInstance(FieldValueTransformer.class)).thenReturn(fieldValueTransformer);
when(configBuilderFactory.getInstance(FieldValueExtractor.class)).thenReturn(fieldValueExtractor);
when(configBuilderFactory.getInstance(AnnotationHelper.class)).thenReturn(annotationHelper);
when(configBuilderFactory.getInstance(ErrorMessageSetup.class)).thenReturn(errorMessageSetup);
when(annotationHelper.fieldHasAnnotationAnnotatedWith(Matchers.any(Field.class), Matchers.any(Class.class))).thenReturn(true);
}
@Test
public void testSetFieldsThrowsIllegalArgumentException() throws Exception {
when(fieldValueExtractor.extractValue(Matchers.any(Field.class), Matchers.any(BuilderConfiguration.class))).thenReturn("stringValue");
when(fieldValueTransformer.transformFieldValue(Matchers.any(Field.class), Matchers.any(String.class))).thenReturn("stringValue");
when(errorMessageSetup.getErrorMessage(Matchers.any(IllegalArgumentException.class), Matchers.any(String.class), Matchers.any(String.class), Matchers.any(String.class))).thenReturn("IllegalArgumentException");
FieldSetter<TestConfigForIllegalArgumentException> fieldSetter = new FieldSetter<>(configBuilderFactory);
TestConfigForIllegalArgumentException testConfigForIllegalArgumentException = new TestConfigForIllegalArgumentException();
| expectedException.expect(ConfigBuilderException.class); |
bmatthias/config-builder | src/test/java/com/tngtech/configbuilder/annotation/valueextractor/SystemPropertyProcessorTest.java | // Path: src/main/java/com/tngtech/configbuilder/util/ConfigBuilderFactory.java
// public class ConfigBuilderFactory {
//
// private Map<Class,Object> singletonMap = Maps.newHashMap();
//
// public <T> void initialize() {
//
// //Order is IMPORTANT!
//
// //configuration
// singletonMap.put(ErrorMessageSetup.class, new ErrorMessageSetup());
// singletonMap.put(BuilderConfiguration.class, new BuilderConfiguration());
//
// //util
// singletonMap.put(AnnotationHelper.class, new AnnotationHelper());
// singletonMap.put(GenericsAndCastingHelper.class, new GenericsAndCastingHelper());
// singletonMap.put(FieldValueExtractor.class, new FieldValueExtractor(this));
// singletonMap.put(FieldValueTransformer.class, new FieldValueTransformer(this));
// singletonMap.put(PropertyLoaderConfigurator.class, new PropertyLoaderConfigurator(this));
// singletonMap.put(ConstructionHelper.class, new ConstructionHelper<T>(this));
// singletonMap.put(FieldSetter.class, new FieldSetter<T>(this));
// singletonMap.put(ConfigValidator.class, new ConfigValidator<T>(this));
// singletonMap.put(CommandLineHelper.class, new CommandLineHelper(this));
//
// //AnnotationProcessors
// singletonMap.put(SystemPropertyProcessor.class, new SystemPropertyProcessor());
// singletonMap.put(PropertyValueProcessor.class, new PropertyValueProcessor());
// singletonMap.put(EnvironmentVariableProcessor.class, new EnvironmentVariableProcessor());
// singletonMap.put(CommandLineValueProcessor.class, new CommandLineValueProcessor());
// singletonMap.put(PropertySuffixProcessor.class, new PropertySuffixProcessor());
// singletonMap.put(PropertyLocationsProcessor.class, new PropertyLocationsProcessor());
// singletonMap.put(PropertyExtensionProcessor.class, new PropertyExtensionProcessor());
// singletonMap.put(PropertiesFilesProcessor.class, new PropertiesFilesProcessor());
// singletonMap.put(DefaultValueProcessor.class, new DefaultValueProcessor());
//
// //ValueTransformers
// singletonMap.put(StringOrPrimitiveToPrimitiveTransformer.class, new StringOrPrimitiveToPrimitiveTransformer());
// singletonMap.put(CollectionToArrayListTransformer.class, new CollectionToArrayListTransformer());
// singletonMap.put(CollectionToHashSetTransformer.class, new CollectionToHashSetTransformer());
// singletonMap.put(CharacterSeparatedStringToStringListTransformer.class, new CharacterSeparatedStringToStringListTransformer());
// singletonMap.put(CharacterSeparatedStringToStringSetTransformer.class, new CharacterSeparatedStringToStringSetTransformer());
// singletonMap.put(StringCollectionToCommaSeparatedStringTransformer.class, new StringCollectionToCommaSeparatedStringTransformer());
// singletonMap.put(StringToPathTransformer.class, new StringToPathTransformer());
//
// //other
// singletonMap.put(ValidatorFactory.class, Validation.buildDefaultValidatorFactory());
// }
//
// public <K> K getInstance(Class<K> clazz) {
// if(singletonMap.get(clazz) != null) {
// return (K)singletonMap.get(clazz);
// }
// else {
// return createInstance(clazz);
// }
// }
//
// //TODO: exception message
// public <K> K createInstance(Class<K> clazz) {
// try {
// return clazz.newInstance();
// } catch (IllegalAccessException e) {
// ErrorMessageSetup errorMessageSetup = (ErrorMessageSetup)singletonMap.get(ErrorMessageSetup.class);
// throw new FactoryInstantiationException(errorMessageSetup.getErrorMessage(FactoryInstantiationException.class, clazz.toString()));
// } catch (InstantiationException e) {
// return createInstanceOfInnerClass(clazz);
// }
// }
//
// //TODO: exception message
// private <K> K createInstanceOfInnerClass(Class<K> clazz) {
// Class superClass = clazz.getDeclaringClass();
// try {
// Object superInstance = superClass.newInstance();
// Constructor<K> constructor = clazz.getConstructor(superClass);
// return constructor.newInstance(superInstance);
// } catch (Exception e) {
// ErrorMessageSetup errorMessageSetup = (ErrorMessageSetup)singletonMap.get(ErrorMessageSetup.class);
// throw new FactoryInstantiationException(errorMessageSetup.getErrorMessage(FactoryInstantiationException.class, clazz.toString()));
// }
// }
// }
| import com.tngtech.configbuilder.util.ConfigBuilderFactory;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.when; | package com.tngtech.configbuilder.annotation.valueextractor;
@RunWith(MockitoJUnitRunner.class)
public class SystemPropertyProcessorTest {
private SystemPropertyProcessor systemPropertyProcessor;
@Mock
private SystemPropertyValue systemPropertyValue;
@Mock | // Path: src/main/java/com/tngtech/configbuilder/util/ConfigBuilderFactory.java
// public class ConfigBuilderFactory {
//
// private Map<Class,Object> singletonMap = Maps.newHashMap();
//
// public <T> void initialize() {
//
// //Order is IMPORTANT!
//
// //configuration
// singletonMap.put(ErrorMessageSetup.class, new ErrorMessageSetup());
// singletonMap.put(BuilderConfiguration.class, new BuilderConfiguration());
//
// //util
// singletonMap.put(AnnotationHelper.class, new AnnotationHelper());
// singletonMap.put(GenericsAndCastingHelper.class, new GenericsAndCastingHelper());
// singletonMap.put(FieldValueExtractor.class, new FieldValueExtractor(this));
// singletonMap.put(FieldValueTransformer.class, new FieldValueTransformer(this));
// singletonMap.put(PropertyLoaderConfigurator.class, new PropertyLoaderConfigurator(this));
// singletonMap.put(ConstructionHelper.class, new ConstructionHelper<T>(this));
// singletonMap.put(FieldSetter.class, new FieldSetter<T>(this));
// singletonMap.put(ConfigValidator.class, new ConfigValidator<T>(this));
// singletonMap.put(CommandLineHelper.class, new CommandLineHelper(this));
//
// //AnnotationProcessors
// singletonMap.put(SystemPropertyProcessor.class, new SystemPropertyProcessor());
// singletonMap.put(PropertyValueProcessor.class, new PropertyValueProcessor());
// singletonMap.put(EnvironmentVariableProcessor.class, new EnvironmentVariableProcessor());
// singletonMap.put(CommandLineValueProcessor.class, new CommandLineValueProcessor());
// singletonMap.put(PropertySuffixProcessor.class, new PropertySuffixProcessor());
// singletonMap.put(PropertyLocationsProcessor.class, new PropertyLocationsProcessor());
// singletonMap.put(PropertyExtensionProcessor.class, new PropertyExtensionProcessor());
// singletonMap.put(PropertiesFilesProcessor.class, new PropertiesFilesProcessor());
// singletonMap.put(DefaultValueProcessor.class, new DefaultValueProcessor());
//
// //ValueTransformers
// singletonMap.put(StringOrPrimitiveToPrimitiveTransformer.class, new StringOrPrimitiveToPrimitiveTransformer());
// singletonMap.put(CollectionToArrayListTransformer.class, new CollectionToArrayListTransformer());
// singletonMap.put(CollectionToHashSetTransformer.class, new CollectionToHashSetTransformer());
// singletonMap.put(CharacterSeparatedStringToStringListTransformer.class, new CharacterSeparatedStringToStringListTransformer());
// singletonMap.put(CharacterSeparatedStringToStringSetTransformer.class, new CharacterSeparatedStringToStringSetTransformer());
// singletonMap.put(StringCollectionToCommaSeparatedStringTransformer.class, new StringCollectionToCommaSeparatedStringTransformer());
// singletonMap.put(StringToPathTransformer.class, new StringToPathTransformer());
//
// //other
// singletonMap.put(ValidatorFactory.class, Validation.buildDefaultValidatorFactory());
// }
//
// public <K> K getInstance(Class<K> clazz) {
// if(singletonMap.get(clazz) != null) {
// return (K)singletonMap.get(clazz);
// }
// else {
// return createInstance(clazz);
// }
// }
//
// //TODO: exception message
// public <K> K createInstance(Class<K> clazz) {
// try {
// return clazz.newInstance();
// } catch (IllegalAccessException e) {
// ErrorMessageSetup errorMessageSetup = (ErrorMessageSetup)singletonMap.get(ErrorMessageSetup.class);
// throw new FactoryInstantiationException(errorMessageSetup.getErrorMessage(FactoryInstantiationException.class, clazz.toString()));
// } catch (InstantiationException e) {
// return createInstanceOfInnerClass(clazz);
// }
// }
//
// //TODO: exception message
// private <K> K createInstanceOfInnerClass(Class<K> clazz) {
// Class superClass = clazz.getDeclaringClass();
// try {
// Object superInstance = superClass.newInstance();
// Constructor<K> constructor = clazz.getConstructor(superClass);
// return constructor.newInstance(superInstance);
// } catch (Exception e) {
// ErrorMessageSetup errorMessageSetup = (ErrorMessageSetup)singletonMap.get(ErrorMessageSetup.class);
// throw new FactoryInstantiationException(errorMessageSetup.getErrorMessage(FactoryInstantiationException.class, clazz.toString()));
// }
// }
// }
// Path: src/test/java/com/tngtech/configbuilder/annotation/valueextractor/SystemPropertyProcessorTest.java
import com.tngtech.configbuilder.util.ConfigBuilderFactory;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.when;
package com.tngtech.configbuilder.annotation.valueextractor;
@RunWith(MockitoJUnitRunner.class)
public class SystemPropertyProcessorTest {
private SystemPropertyProcessor systemPropertyProcessor;
@Mock
private SystemPropertyValue systemPropertyValue;
@Mock | private ConfigBuilderFactory configBuilderFactory; |
bmatthias/config-builder | src/test/java/com/tngtech/configbuilder/util/ConstructionHelperTest.java | // Path: src/main/java/com/tngtech/configbuilder/configuration/ErrorMessageSetup.java
// public class ErrorMessageSetup {
//
// private Properties errorMessages;
//
// /**
// * loads the default error messages for the system locale, then merges them with additional error messages loaded with the PropertyLoader
// *
// * @param baseName the filename for additional error messages
// * @param propertyLoader the PropertyLoader used to load additional error messages
// */
// public void initialize(String baseName, PropertyLoader propertyLoader) {
// ResourceBundle resourceBundle = ResourceBundle.getBundle("errors");
// errorMessages = convertResourceBundleToProperties(resourceBundle);
// if (baseName != null) {
// errorMessages.putAll(propertyLoader.load(baseName));
// }
// }
//
// private Properties convertResourceBundleToProperties(ResourceBundle resource) {
// Properties properties = new Properties();
//
// Enumeration<String> keys = resource.getKeys();
// while (keys.hasMoreElements()) {
// String key = keys.nextElement();
// properties.put(key, resource.getString(key));
// }
// return properties;
// }
//
// public String getErrorMessage(Throwable e, String... variables) {
// String message = errorMessages.getProperty(e.getClass().getName());
// return message == null ? String.format(errorMessages.getProperty("standardMessage"), e.getClass().getName()) : String.format(message, variables);
// }
//
// public String getErrorMessage(Class exceptionClass, String... variables) {
// String message = errorMessages.getProperty(exceptionClass.getName());
// return message == null ? String.format(errorMessages.getProperty("standardMessage"), exceptionClass.getName()) : String.format(message, variables);
// }
// }
//
// Path: src/main/java/com/tngtech/configbuilder/exception/NoConstructorFoundException.java
// public class NoConstructorFoundException extends RuntimeException {
// public NoConstructorFoundException(String message) {
// super(message);
// }
// }
| import com.tngtech.configbuilder.configuration.ErrorMessageSetup;
import com.tngtech.configbuilder.exception.NoConstructorFoundException;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.when; | package com.tngtech.configbuilder.util;
@RunWith(MockitoJUnitRunner.class)
public class ConstructionHelperTest {
private static class TestConfig {
private String string;
private Integer integer;
public TestConfig(String string, Integer integer) {
this.string = string;
this.integer = integer;
}
private Integer getInteger() {
return integer;
}
private String getString() {
return string;
}
}
private static class TestConfigForException {
public TestConfigForException(String string, int i) {
}
}
@Rule
public ExpectedException expectedException = ExpectedException.none();
@Mock
private ConfigBuilderFactory configBuilderFactory;
@Mock | // Path: src/main/java/com/tngtech/configbuilder/configuration/ErrorMessageSetup.java
// public class ErrorMessageSetup {
//
// private Properties errorMessages;
//
// /**
// * loads the default error messages for the system locale, then merges them with additional error messages loaded with the PropertyLoader
// *
// * @param baseName the filename for additional error messages
// * @param propertyLoader the PropertyLoader used to load additional error messages
// */
// public void initialize(String baseName, PropertyLoader propertyLoader) {
// ResourceBundle resourceBundle = ResourceBundle.getBundle("errors");
// errorMessages = convertResourceBundleToProperties(resourceBundle);
// if (baseName != null) {
// errorMessages.putAll(propertyLoader.load(baseName));
// }
// }
//
// private Properties convertResourceBundleToProperties(ResourceBundle resource) {
// Properties properties = new Properties();
//
// Enumeration<String> keys = resource.getKeys();
// while (keys.hasMoreElements()) {
// String key = keys.nextElement();
// properties.put(key, resource.getString(key));
// }
// return properties;
// }
//
// public String getErrorMessage(Throwable e, String... variables) {
// String message = errorMessages.getProperty(e.getClass().getName());
// return message == null ? String.format(errorMessages.getProperty("standardMessage"), e.getClass().getName()) : String.format(message, variables);
// }
//
// public String getErrorMessage(Class exceptionClass, String... variables) {
// String message = errorMessages.getProperty(exceptionClass.getName());
// return message == null ? String.format(errorMessages.getProperty("standardMessage"), exceptionClass.getName()) : String.format(message, variables);
// }
// }
//
// Path: src/main/java/com/tngtech/configbuilder/exception/NoConstructorFoundException.java
// public class NoConstructorFoundException extends RuntimeException {
// public NoConstructorFoundException(String message) {
// super(message);
// }
// }
// Path: src/test/java/com/tngtech/configbuilder/util/ConstructionHelperTest.java
import com.tngtech.configbuilder.configuration.ErrorMessageSetup;
import com.tngtech.configbuilder.exception.NoConstructorFoundException;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.when;
package com.tngtech.configbuilder.util;
@RunWith(MockitoJUnitRunner.class)
public class ConstructionHelperTest {
private static class TestConfig {
private String string;
private Integer integer;
public TestConfig(String string, Integer integer) {
this.string = string;
this.integer = integer;
}
private Integer getInteger() {
return integer;
}
private String getString() {
return string;
}
}
private static class TestConfigForException {
public TestConfigForException(String string, int i) {
}
}
@Rule
public ExpectedException expectedException = ExpectedException.none();
@Mock
private ConfigBuilderFactory configBuilderFactory;
@Mock | private ErrorMessageSetup errorMessageSetup; |
bmatthias/config-builder | src/test/java/com/tngtech/configbuilder/util/ConstructionHelperTest.java | // Path: src/main/java/com/tngtech/configbuilder/configuration/ErrorMessageSetup.java
// public class ErrorMessageSetup {
//
// private Properties errorMessages;
//
// /**
// * loads the default error messages for the system locale, then merges them with additional error messages loaded with the PropertyLoader
// *
// * @param baseName the filename for additional error messages
// * @param propertyLoader the PropertyLoader used to load additional error messages
// */
// public void initialize(String baseName, PropertyLoader propertyLoader) {
// ResourceBundle resourceBundle = ResourceBundle.getBundle("errors");
// errorMessages = convertResourceBundleToProperties(resourceBundle);
// if (baseName != null) {
// errorMessages.putAll(propertyLoader.load(baseName));
// }
// }
//
// private Properties convertResourceBundleToProperties(ResourceBundle resource) {
// Properties properties = new Properties();
//
// Enumeration<String> keys = resource.getKeys();
// while (keys.hasMoreElements()) {
// String key = keys.nextElement();
// properties.put(key, resource.getString(key));
// }
// return properties;
// }
//
// public String getErrorMessage(Throwable e, String... variables) {
// String message = errorMessages.getProperty(e.getClass().getName());
// return message == null ? String.format(errorMessages.getProperty("standardMessage"), e.getClass().getName()) : String.format(message, variables);
// }
//
// public String getErrorMessage(Class exceptionClass, String... variables) {
// String message = errorMessages.getProperty(exceptionClass.getName());
// return message == null ? String.format(errorMessages.getProperty("standardMessage"), exceptionClass.getName()) : String.format(message, variables);
// }
// }
//
// Path: src/main/java/com/tngtech/configbuilder/exception/NoConstructorFoundException.java
// public class NoConstructorFoundException extends RuntimeException {
// public NoConstructorFoundException(String message) {
// super(message);
// }
// }
| import com.tngtech.configbuilder.configuration.ErrorMessageSetup;
import com.tngtech.configbuilder.exception.NoConstructorFoundException;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.when; | package com.tngtech.configbuilder.util;
@RunWith(MockitoJUnitRunner.class)
public class ConstructionHelperTest {
private static class TestConfig {
private String string;
private Integer integer;
public TestConfig(String string, Integer integer) {
this.string = string;
this.integer = integer;
}
private Integer getInteger() {
return integer;
}
private String getString() {
return string;
}
}
private static class TestConfigForException {
public TestConfigForException(String string, int i) {
}
}
@Rule
public ExpectedException expectedException = ExpectedException.none();
@Mock
private ConfigBuilderFactory configBuilderFactory;
@Mock
private ErrorMessageSetup errorMessageSetup;
@Before
public void setUp() throws Exception {
when(configBuilderFactory.getInstance(ErrorMessageSetup.class)).thenReturn(errorMessageSetup); | // Path: src/main/java/com/tngtech/configbuilder/configuration/ErrorMessageSetup.java
// public class ErrorMessageSetup {
//
// private Properties errorMessages;
//
// /**
// * loads the default error messages for the system locale, then merges them with additional error messages loaded with the PropertyLoader
// *
// * @param baseName the filename for additional error messages
// * @param propertyLoader the PropertyLoader used to load additional error messages
// */
// public void initialize(String baseName, PropertyLoader propertyLoader) {
// ResourceBundle resourceBundle = ResourceBundle.getBundle("errors");
// errorMessages = convertResourceBundleToProperties(resourceBundle);
// if (baseName != null) {
// errorMessages.putAll(propertyLoader.load(baseName));
// }
// }
//
// private Properties convertResourceBundleToProperties(ResourceBundle resource) {
// Properties properties = new Properties();
//
// Enumeration<String> keys = resource.getKeys();
// while (keys.hasMoreElements()) {
// String key = keys.nextElement();
// properties.put(key, resource.getString(key));
// }
// return properties;
// }
//
// public String getErrorMessage(Throwable e, String... variables) {
// String message = errorMessages.getProperty(e.getClass().getName());
// return message == null ? String.format(errorMessages.getProperty("standardMessage"), e.getClass().getName()) : String.format(message, variables);
// }
//
// public String getErrorMessage(Class exceptionClass, String... variables) {
// String message = errorMessages.getProperty(exceptionClass.getName());
// return message == null ? String.format(errorMessages.getProperty("standardMessage"), exceptionClass.getName()) : String.format(message, variables);
// }
// }
//
// Path: src/main/java/com/tngtech/configbuilder/exception/NoConstructorFoundException.java
// public class NoConstructorFoundException extends RuntimeException {
// public NoConstructorFoundException(String message) {
// super(message);
// }
// }
// Path: src/test/java/com/tngtech/configbuilder/util/ConstructionHelperTest.java
import com.tngtech.configbuilder.configuration.ErrorMessageSetup;
import com.tngtech.configbuilder.exception.NoConstructorFoundException;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.when;
package com.tngtech.configbuilder.util;
@RunWith(MockitoJUnitRunner.class)
public class ConstructionHelperTest {
private static class TestConfig {
private String string;
private Integer integer;
public TestConfig(String string, Integer integer) {
this.string = string;
this.integer = integer;
}
private Integer getInteger() {
return integer;
}
private String getString() {
return string;
}
}
private static class TestConfigForException {
public TestConfigForException(String string, int i) {
}
}
@Rule
public ExpectedException expectedException = ExpectedException.none();
@Mock
private ConfigBuilderFactory configBuilderFactory;
@Mock
private ErrorMessageSetup errorMessageSetup;
@Before
public void setUp() throws Exception {
when(configBuilderFactory.getInstance(ErrorMessageSetup.class)).thenReturn(errorMessageSetup); | when(errorMessageSetup.getErrorMessage(NoConstructorFoundException.class)).thenReturn("NoConstructorFoundException"); |
bmatthias/config-builder | src/main/java/com/tngtech/configbuilder/util/CommandLineHelper.java | // Path: src/main/java/com/tngtech/configbuilder/configuration/ErrorMessageSetup.java
// public class ErrorMessageSetup {
//
// private Properties errorMessages;
//
// /**
// * loads the default error messages for the system locale, then merges them with additional error messages loaded with the PropertyLoader
// *
// * @param baseName the filename for additional error messages
// * @param propertyLoader the PropertyLoader used to load additional error messages
// */
// public void initialize(String baseName, PropertyLoader propertyLoader) {
// ResourceBundle resourceBundle = ResourceBundle.getBundle("errors");
// errorMessages = convertResourceBundleToProperties(resourceBundle);
// if (baseName != null) {
// errorMessages.putAll(propertyLoader.load(baseName));
// }
// }
//
// private Properties convertResourceBundleToProperties(ResourceBundle resource) {
// Properties properties = new Properties();
//
// Enumeration<String> keys = resource.getKeys();
// while (keys.hasMoreElements()) {
// String key = keys.nextElement();
// properties.put(key, resource.getString(key));
// }
// return properties;
// }
//
// public String getErrorMessage(Throwable e, String... variables) {
// String message = errorMessages.getProperty(e.getClass().getName());
// return message == null ? String.format(errorMessages.getProperty("standardMessage"), e.getClass().getName()) : String.format(message, variables);
// }
//
// public String getErrorMessage(Class exceptionClass, String... variables) {
// String message = errorMessages.getProperty(exceptionClass.getName());
// return message == null ? String.format(errorMessages.getProperty("standardMessage"), exceptionClass.getName()) : String.format(message, variables);
// }
// }
//
// Path: src/main/java/com/tngtech/configbuilder/exception/ConfigBuilderException.java
// public class ConfigBuilderException extends RuntimeException {
//
// public ConfigBuilderException(String message, Throwable e) {
// super(message, e);
// }
// }
| import com.tngtech.configbuilder.annotation.valueextractor.CommandLineValue;
import com.tngtech.configbuilder.configuration.ErrorMessageSetup;
import com.tngtech.configbuilder.exception.ConfigBuilderException;
import org.apache.commons.cli.*;
import org.apache.log4j.Logger;
import java.lang.reflect.Field; | package com.tngtech.configbuilder.util;
public class CommandLineHelper {
private final static Logger log = Logger.getLogger(CommandLineHelper.class);
private final ConfigBuilderFactory configBuilderFactory;
private final AnnotationHelper annotationHelper; | // Path: src/main/java/com/tngtech/configbuilder/configuration/ErrorMessageSetup.java
// public class ErrorMessageSetup {
//
// private Properties errorMessages;
//
// /**
// * loads the default error messages for the system locale, then merges them with additional error messages loaded with the PropertyLoader
// *
// * @param baseName the filename for additional error messages
// * @param propertyLoader the PropertyLoader used to load additional error messages
// */
// public void initialize(String baseName, PropertyLoader propertyLoader) {
// ResourceBundle resourceBundle = ResourceBundle.getBundle("errors");
// errorMessages = convertResourceBundleToProperties(resourceBundle);
// if (baseName != null) {
// errorMessages.putAll(propertyLoader.load(baseName));
// }
// }
//
// private Properties convertResourceBundleToProperties(ResourceBundle resource) {
// Properties properties = new Properties();
//
// Enumeration<String> keys = resource.getKeys();
// while (keys.hasMoreElements()) {
// String key = keys.nextElement();
// properties.put(key, resource.getString(key));
// }
// return properties;
// }
//
// public String getErrorMessage(Throwable e, String... variables) {
// String message = errorMessages.getProperty(e.getClass().getName());
// return message == null ? String.format(errorMessages.getProperty("standardMessage"), e.getClass().getName()) : String.format(message, variables);
// }
//
// public String getErrorMessage(Class exceptionClass, String... variables) {
// String message = errorMessages.getProperty(exceptionClass.getName());
// return message == null ? String.format(errorMessages.getProperty("standardMessage"), exceptionClass.getName()) : String.format(message, variables);
// }
// }
//
// Path: src/main/java/com/tngtech/configbuilder/exception/ConfigBuilderException.java
// public class ConfigBuilderException extends RuntimeException {
//
// public ConfigBuilderException(String message, Throwable e) {
// super(message, e);
// }
// }
// Path: src/main/java/com/tngtech/configbuilder/util/CommandLineHelper.java
import com.tngtech.configbuilder.annotation.valueextractor.CommandLineValue;
import com.tngtech.configbuilder.configuration.ErrorMessageSetup;
import com.tngtech.configbuilder.exception.ConfigBuilderException;
import org.apache.commons.cli.*;
import org.apache.log4j.Logger;
import java.lang.reflect.Field;
package com.tngtech.configbuilder.util;
public class CommandLineHelper {
private final static Logger log = Logger.getLogger(CommandLineHelper.class);
private final ConfigBuilderFactory configBuilderFactory;
private final AnnotationHelper annotationHelper; | private final ErrorMessageSetup errorMessageSetup; |
bmatthias/config-builder | src/main/java/com/tngtech/configbuilder/util/CommandLineHelper.java | // Path: src/main/java/com/tngtech/configbuilder/configuration/ErrorMessageSetup.java
// public class ErrorMessageSetup {
//
// private Properties errorMessages;
//
// /**
// * loads the default error messages for the system locale, then merges them with additional error messages loaded with the PropertyLoader
// *
// * @param baseName the filename for additional error messages
// * @param propertyLoader the PropertyLoader used to load additional error messages
// */
// public void initialize(String baseName, PropertyLoader propertyLoader) {
// ResourceBundle resourceBundle = ResourceBundle.getBundle("errors");
// errorMessages = convertResourceBundleToProperties(resourceBundle);
// if (baseName != null) {
// errorMessages.putAll(propertyLoader.load(baseName));
// }
// }
//
// private Properties convertResourceBundleToProperties(ResourceBundle resource) {
// Properties properties = new Properties();
//
// Enumeration<String> keys = resource.getKeys();
// while (keys.hasMoreElements()) {
// String key = keys.nextElement();
// properties.put(key, resource.getString(key));
// }
// return properties;
// }
//
// public String getErrorMessage(Throwable e, String... variables) {
// String message = errorMessages.getProperty(e.getClass().getName());
// return message == null ? String.format(errorMessages.getProperty("standardMessage"), e.getClass().getName()) : String.format(message, variables);
// }
//
// public String getErrorMessage(Class exceptionClass, String... variables) {
// String message = errorMessages.getProperty(exceptionClass.getName());
// return message == null ? String.format(errorMessages.getProperty("standardMessage"), exceptionClass.getName()) : String.format(message, variables);
// }
// }
//
// Path: src/main/java/com/tngtech/configbuilder/exception/ConfigBuilderException.java
// public class ConfigBuilderException extends RuntimeException {
//
// public ConfigBuilderException(String message, Throwable e) {
// super(message, e);
// }
// }
| import com.tngtech.configbuilder.annotation.valueextractor.CommandLineValue;
import com.tngtech.configbuilder.configuration.ErrorMessageSetup;
import com.tngtech.configbuilder.exception.ConfigBuilderException;
import org.apache.commons.cli.*;
import org.apache.log4j.Logger;
import java.lang.reflect.Field; | log.info("getting command line options from fields and parsing command line arguments");
Options options = getOptions(configClass);
return parseCommandLine(args, options);
}
public Options getOptions(Class configClass) {
Options options = configBuilderFactory.createInstance(Options.class);
for (Field field : annotationHelper.getFieldsAnnotatedWith(configClass, CommandLineValue.class)) {
options.addOption(getOption(field));
}
return options;
}
@SuppressWarnings("AccessStaticViaInstance")
private Option getOption(Field field) {
CommandLineValue commandLineValue = field.getAnnotation(CommandLineValue.class);
log.debug(String.format("adding command line option %s for field %s", commandLineValue.shortOpt(), field.getName()));
return OptionBuilder.withLongOpt(commandLineValue.longOpt())
.hasArg()
.isRequired(commandLineValue.required())
.withDescription(commandLineValue.description())
.hasArg(commandLineValue.hasArg())
.create(commandLineValue.shortOpt());
}
private CommandLine parseCommandLine(String[] args, Options options) {
CommandLine commandLine;
try {
commandLine = configBuilderFactory.createInstance(GnuParser.class).parse(options, args);
} catch (ParseException e) { | // Path: src/main/java/com/tngtech/configbuilder/configuration/ErrorMessageSetup.java
// public class ErrorMessageSetup {
//
// private Properties errorMessages;
//
// /**
// * loads the default error messages for the system locale, then merges them with additional error messages loaded with the PropertyLoader
// *
// * @param baseName the filename for additional error messages
// * @param propertyLoader the PropertyLoader used to load additional error messages
// */
// public void initialize(String baseName, PropertyLoader propertyLoader) {
// ResourceBundle resourceBundle = ResourceBundle.getBundle("errors");
// errorMessages = convertResourceBundleToProperties(resourceBundle);
// if (baseName != null) {
// errorMessages.putAll(propertyLoader.load(baseName));
// }
// }
//
// private Properties convertResourceBundleToProperties(ResourceBundle resource) {
// Properties properties = new Properties();
//
// Enumeration<String> keys = resource.getKeys();
// while (keys.hasMoreElements()) {
// String key = keys.nextElement();
// properties.put(key, resource.getString(key));
// }
// return properties;
// }
//
// public String getErrorMessage(Throwable e, String... variables) {
// String message = errorMessages.getProperty(e.getClass().getName());
// return message == null ? String.format(errorMessages.getProperty("standardMessage"), e.getClass().getName()) : String.format(message, variables);
// }
//
// public String getErrorMessage(Class exceptionClass, String... variables) {
// String message = errorMessages.getProperty(exceptionClass.getName());
// return message == null ? String.format(errorMessages.getProperty("standardMessage"), exceptionClass.getName()) : String.format(message, variables);
// }
// }
//
// Path: src/main/java/com/tngtech/configbuilder/exception/ConfigBuilderException.java
// public class ConfigBuilderException extends RuntimeException {
//
// public ConfigBuilderException(String message, Throwable e) {
// super(message, e);
// }
// }
// Path: src/main/java/com/tngtech/configbuilder/util/CommandLineHelper.java
import com.tngtech.configbuilder.annotation.valueextractor.CommandLineValue;
import com.tngtech.configbuilder.configuration.ErrorMessageSetup;
import com.tngtech.configbuilder.exception.ConfigBuilderException;
import org.apache.commons.cli.*;
import org.apache.log4j.Logger;
import java.lang.reflect.Field;
log.info("getting command line options from fields and parsing command line arguments");
Options options = getOptions(configClass);
return parseCommandLine(args, options);
}
public Options getOptions(Class configClass) {
Options options = configBuilderFactory.createInstance(Options.class);
for (Field field : annotationHelper.getFieldsAnnotatedWith(configClass, CommandLineValue.class)) {
options.addOption(getOption(field));
}
return options;
}
@SuppressWarnings("AccessStaticViaInstance")
private Option getOption(Field field) {
CommandLineValue commandLineValue = field.getAnnotation(CommandLineValue.class);
log.debug(String.format("adding command line option %s for field %s", commandLineValue.shortOpt(), field.getName()));
return OptionBuilder.withLongOpt(commandLineValue.longOpt())
.hasArg()
.isRequired(commandLineValue.required())
.withDescription(commandLineValue.description())
.hasArg(commandLineValue.hasArg())
.create(commandLineValue.shortOpt());
}
private CommandLine parseCommandLine(String[] args, Options options) {
CommandLine commandLine;
try {
commandLine = configBuilderFactory.createInstance(GnuParser.class).parse(options, args);
} catch (ParseException e) { | throw new ConfigBuilderException(errorMessageSetup.getErrorMessage(e.getClass().getSuperclass()), e); |
bmatthias/config-builder | src/test/java/com/tngtech/configbuilder/util/GenericsAndCastingHelperTest.java | // Path: src/main/java/com/tngtech/configbuilder/annotation/valuetransformer/ValueTransformer.java
// public abstract class ValueTransformer<SourceClass, TargetClass> {
//
// protected Type targetType;
// protected FieldValueTransformer fieldValueTransformer;
// protected GenericsAndCastingHelper genericsAndCastingHelper;
// protected ErrorMessageSetup errorMessageSetup;
// protected Object[] additionalOptions;
//
// public abstract TargetClass transform(SourceClass argument);
//
// public void initialize(FieldValueTransformer fieldValueTransformer, ConfigBuilderFactory configBuilderFactory, Object... additionalOptions) {
// this.fieldValueTransformer = fieldValueTransformer;
// this.genericsAndCastingHelper = configBuilderFactory.getInstance(GenericsAndCastingHelper.class);
// this.errorMessageSetup = configBuilderFactory.getInstance(ErrorMessageSetup.class);
// this.additionalOptions = additionalOptions;
// }
//
// public boolean isMatching(Object sourceValue, Type targetType) {
// if(sourceValue == null) {
// return false;
// }
// Class<?> sourceClass = genericsAndCastingHelper.getWrapperClassIfPrimitive(sourceValue.getClass());
// Class<?> targetClass = genericsAndCastingHelper.getWrapperClassIfPrimitive(genericsAndCastingHelper.castTypeToClass(targetType));
// Class<?> transformerSourceClass = getTransformerSourceClass();
// Class<?> transformerTargetClass = getTransformerTargetClass();
// if(transformerSourceClass.isAssignableFrom(sourceClass) && targetClass.isAssignableFrom(transformerTargetClass)) {
// return true;
// }
// return false;
// }
//
// public Class<?> getTransformerSourceClass() {
// Type typeOfInterface = this.getClass().getGenericSuperclass();
// Type[] genericTypes = ((ParameterizedType) typeOfInterface).getActualTypeArguments();
// return genericsAndCastingHelper.castTypeToClass(genericTypes[0]);
// }
//
// public Class<?> getTransformerTargetClass() {
// Type typeOfInterface = this.getClass().getGenericSuperclass();
// Type[] genericTypes = ((ParameterizedType) typeOfInterface).getActualTypeArguments();
// return genericsAndCastingHelper.castTypeToClass(genericTypes[1]);
// }
//
// public void setTargetType(Type targetType) {
// this.targetType = targetType;
// }
//
// public boolean isContentTransformer() {
// return getTransformerTargetClass().isAssignableFrom(getTransformerSourceClass());
// }
// }
| import com.google.common.collect.Lists;
import com.tngtech.configbuilder.annotation.valuetransformer.ValueTransformer;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.runners.MockitoJUnitRunner;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.Collection;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue; | package com.tngtech.configbuilder.util;
@RunWith(MockitoJUnitRunner.class)
public class GenericsAndCastingHelperTest {
| // Path: src/main/java/com/tngtech/configbuilder/annotation/valuetransformer/ValueTransformer.java
// public abstract class ValueTransformer<SourceClass, TargetClass> {
//
// protected Type targetType;
// protected FieldValueTransformer fieldValueTransformer;
// protected GenericsAndCastingHelper genericsAndCastingHelper;
// protected ErrorMessageSetup errorMessageSetup;
// protected Object[] additionalOptions;
//
// public abstract TargetClass transform(SourceClass argument);
//
// public void initialize(FieldValueTransformer fieldValueTransformer, ConfigBuilderFactory configBuilderFactory, Object... additionalOptions) {
// this.fieldValueTransformer = fieldValueTransformer;
// this.genericsAndCastingHelper = configBuilderFactory.getInstance(GenericsAndCastingHelper.class);
// this.errorMessageSetup = configBuilderFactory.getInstance(ErrorMessageSetup.class);
// this.additionalOptions = additionalOptions;
// }
//
// public boolean isMatching(Object sourceValue, Type targetType) {
// if(sourceValue == null) {
// return false;
// }
// Class<?> sourceClass = genericsAndCastingHelper.getWrapperClassIfPrimitive(sourceValue.getClass());
// Class<?> targetClass = genericsAndCastingHelper.getWrapperClassIfPrimitive(genericsAndCastingHelper.castTypeToClass(targetType));
// Class<?> transformerSourceClass = getTransformerSourceClass();
// Class<?> transformerTargetClass = getTransformerTargetClass();
// if(transformerSourceClass.isAssignableFrom(sourceClass) && targetClass.isAssignableFrom(transformerTargetClass)) {
// return true;
// }
// return false;
// }
//
// public Class<?> getTransformerSourceClass() {
// Type typeOfInterface = this.getClass().getGenericSuperclass();
// Type[] genericTypes = ((ParameterizedType) typeOfInterface).getActualTypeArguments();
// return genericsAndCastingHelper.castTypeToClass(genericTypes[0]);
// }
//
// public Class<?> getTransformerTargetClass() {
// Type typeOfInterface = this.getClass().getGenericSuperclass();
// Type[] genericTypes = ((ParameterizedType) typeOfInterface).getActualTypeArguments();
// return genericsAndCastingHelper.castTypeToClass(genericTypes[1]);
// }
//
// public void setTargetType(Type targetType) {
// this.targetType = targetType;
// }
//
// public boolean isContentTransformer() {
// return getTransformerTargetClass().isAssignableFrom(getTransformerSourceClass());
// }
// }
// Path: src/test/java/com/tngtech/configbuilder/util/GenericsAndCastingHelperTest.java
import com.google.common.collect.Lists;
import com.tngtech.configbuilder.annotation.valuetransformer.ValueTransformer;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.runners.MockitoJUnitRunner;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.Collection;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
package com.tngtech.configbuilder.util;
@RunWith(MockitoJUnitRunner.class)
public class GenericsAndCastingHelperTest {
| private class TestClass extends ValueTransformer<Collection<String>, Iterable<String>> { |
bmatthias/config-builder | src/main/java/com/tngtech/configbuilder/annotation/valueextractor/CommandLineValueProcessor.java | // Path: src/main/java/com/tngtech/configbuilder/configuration/BuilderConfiguration.java
// public class BuilderConfiguration {
//
// private Properties properties;
// private CommandLine commandLine;
// private Object importedConfiguration;
// private Class<? extends Annotation>[] annotationOrder = new Class[]{CommandLineValue.class, PropertyValue.class, EnvironmentVariableValue.class, SystemPropertyValue.class, ImportedValue.class, DefaultValue.class};
//
// public BuilderConfiguration() {
// properties = new Properties();
// commandLine = null;
// importedConfiguration = null;
// }
//
// public CommandLine getCommandLine() {
// return commandLine;
// }
//
// public Properties getProperties() {
// return properties;
// }
//
// public Object getImportedConfiguration() {
// return importedConfiguration;
// }
//
// public void setProperties(Properties properties) {
// this.properties = properties;
// }
//
// public void setCommandLine(CommandLine commandLine) {
// this.commandLine = commandLine;
// }
//
// public void setImportedConfiguration(Object importedConfiguration) {
// this.importedConfiguration = importedConfiguration;
// }
//
// public void setAnnotationOrder(Class<? extends Annotation>[] annotationOrder) {
// this.annotationOrder = annotationOrder;
// }
//
// public Class<? extends Annotation>[] getAnnotationOrder() {
// return annotationOrder;
// }
// }
//
// Path: src/main/java/com/tngtech/configbuilder/util/ConfigBuilderFactory.java
// public class ConfigBuilderFactory {
//
// private Map<Class,Object> singletonMap = Maps.newHashMap();
//
// public <T> void initialize() {
//
// //Order is IMPORTANT!
//
// //configuration
// singletonMap.put(ErrorMessageSetup.class, new ErrorMessageSetup());
// singletonMap.put(BuilderConfiguration.class, new BuilderConfiguration());
//
// //util
// singletonMap.put(AnnotationHelper.class, new AnnotationHelper());
// singletonMap.put(GenericsAndCastingHelper.class, new GenericsAndCastingHelper());
// singletonMap.put(FieldValueExtractor.class, new FieldValueExtractor(this));
// singletonMap.put(FieldValueTransformer.class, new FieldValueTransformer(this));
// singletonMap.put(PropertyLoaderConfigurator.class, new PropertyLoaderConfigurator(this));
// singletonMap.put(ConstructionHelper.class, new ConstructionHelper<T>(this));
// singletonMap.put(FieldSetter.class, new FieldSetter<T>(this));
// singletonMap.put(ConfigValidator.class, new ConfigValidator<T>(this));
// singletonMap.put(CommandLineHelper.class, new CommandLineHelper(this));
//
// //AnnotationProcessors
// singletonMap.put(SystemPropertyProcessor.class, new SystemPropertyProcessor());
// singletonMap.put(PropertyValueProcessor.class, new PropertyValueProcessor());
// singletonMap.put(EnvironmentVariableProcessor.class, new EnvironmentVariableProcessor());
// singletonMap.put(CommandLineValueProcessor.class, new CommandLineValueProcessor());
// singletonMap.put(PropertySuffixProcessor.class, new PropertySuffixProcessor());
// singletonMap.put(PropertyLocationsProcessor.class, new PropertyLocationsProcessor());
// singletonMap.put(PropertyExtensionProcessor.class, new PropertyExtensionProcessor());
// singletonMap.put(PropertiesFilesProcessor.class, new PropertiesFilesProcessor());
// singletonMap.put(DefaultValueProcessor.class, new DefaultValueProcessor());
//
// //ValueTransformers
// singletonMap.put(StringOrPrimitiveToPrimitiveTransformer.class, new StringOrPrimitiveToPrimitiveTransformer());
// singletonMap.put(CollectionToArrayListTransformer.class, new CollectionToArrayListTransformer());
// singletonMap.put(CollectionToHashSetTransformer.class, new CollectionToHashSetTransformer());
// singletonMap.put(CharacterSeparatedStringToStringListTransformer.class, new CharacterSeparatedStringToStringListTransformer());
// singletonMap.put(CharacterSeparatedStringToStringSetTransformer.class, new CharacterSeparatedStringToStringSetTransformer());
// singletonMap.put(StringCollectionToCommaSeparatedStringTransformer.class, new StringCollectionToCommaSeparatedStringTransformer());
// singletonMap.put(StringToPathTransformer.class, new StringToPathTransformer());
//
// //other
// singletonMap.put(ValidatorFactory.class, Validation.buildDefaultValidatorFactory());
// }
//
// public <K> K getInstance(Class<K> clazz) {
// if(singletonMap.get(clazz) != null) {
// return (K)singletonMap.get(clazz);
// }
// else {
// return createInstance(clazz);
// }
// }
//
// //TODO: exception message
// public <K> K createInstance(Class<K> clazz) {
// try {
// return clazz.newInstance();
// } catch (IllegalAccessException e) {
// ErrorMessageSetup errorMessageSetup = (ErrorMessageSetup)singletonMap.get(ErrorMessageSetup.class);
// throw new FactoryInstantiationException(errorMessageSetup.getErrorMessage(FactoryInstantiationException.class, clazz.toString()));
// } catch (InstantiationException e) {
// return createInstanceOfInnerClass(clazz);
// }
// }
//
// //TODO: exception message
// private <K> K createInstanceOfInnerClass(Class<K> clazz) {
// Class superClass = clazz.getDeclaringClass();
// try {
// Object superInstance = superClass.newInstance();
// Constructor<K> constructor = clazz.getConstructor(superClass);
// return constructor.newInstance(superInstance);
// } catch (Exception e) {
// ErrorMessageSetup errorMessageSetup = (ErrorMessageSetup)singletonMap.get(ErrorMessageSetup.class);
// throw new FactoryInstantiationException(errorMessageSetup.getErrorMessage(FactoryInstantiationException.class, clazz.toString()));
// }
// }
// }
| import com.tngtech.configbuilder.configuration.BuilderConfiguration;
import com.tngtech.configbuilder.util.ConfigBuilderFactory;
import java.lang.annotation.Annotation; | package com.tngtech.configbuilder.annotation.valueextractor;
/**
* Processes CommandLineValue annotations, implements ValueExtractorProcessor
*/
public class CommandLineValueProcessor implements ValueExtractorProcessor {
public String getValue(Annotation annotation, ConfigBuilderFactory configBuilderFactory) { | // Path: src/main/java/com/tngtech/configbuilder/configuration/BuilderConfiguration.java
// public class BuilderConfiguration {
//
// private Properties properties;
// private CommandLine commandLine;
// private Object importedConfiguration;
// private Class<? extends Annotation>[] annotationOrder = new Class[]{CommandLineValue.class, PropertyValue.class, EnvironmentVariableValue.class, SystemPropertyValue.class, ImportedValue.class, DefaultValue.class};
//
// public BuilderConfiguration() {
// properties = new Properties();
// commandLine = null;
// importedConfiguration = null;
// }
//
// public CommandLine getCommandLine() {
// return commandLine;
// }
//
// public Properties getProperties() {
// return properties;
// }
//
// public Object getImportedConfiguration() {
// return importedConfiguration;
// }
//
// public void setProperties(Properties properties) {
// this.properties = properties;
// }
//
// public void setCommandLine(CommandLine commandLine) {
// this.commandLine = commandLine;
// }
//
// public void setImportedConfiguration(Object importedConfiguration) {
// this.importedConfiguration = importedConfiguration;
// }
//
// public void setAnnotationOrder(Class<? extends Annotation>[] annotationOrder) {
// this.annotationOrder = annotationOrder;
// }
//
// public Class<? extends Annotation>[] getAnnotationOrder() {
// return annotationOrder;
// }
// }
//
// Path: src/main/java/com/tngtech/configbuilder/util/ConfigBuilderFactory.java
// public class ConfigBuilderFactory {
//
// private Map<Class,Object> singletonMap = Maps.newHashMap();
//
// public <T> void initialize() {
//
// //Order is IMPORTANT!
//
// //configuration
// singletonMap.put(ErrorMessageSetup.class, new ErrorMessageSetup());
// singletonMap.put(BuilderConfiguration.class, new BuilderConfiguration());
//
// //util
// singletonMap.put(AnnotationHelper.class, new AnnotationHelper());
// singletonMap.put(GenericsAndCastingHelper.class, new GenericsAndCastingHelper());
// singletonMap.put(FieldValueExtractor.class, new FieldValueExtractor(this));
// singletonMap.put(FieldValueTransformer.class, new FieldValueTransformer(this));
// singletonMap.put(PropertyLoaderConfigurator.class, new PropertyLoaderConfigurator(this));
// singletonMap.put(ConstructionHelper.class, new ConstructionHelper<T>(this));
// singletonMap.put(FieldSetter.class, new FieldSetter<T>(this));
// singletonMap.put(ConfigValidator.class, new ConfigValidator<T>(this));
// singletonMap.put(CommandLineHelper.class, new CommandLineHelper(this));
//
// //AnnotationProcessors
// singletonMap.put(SystemPropertyProcessor.class, new SystemPropertyProcessor());
// singletonMap.put(PropertyValueProcessor.class, new PropertyValueProcessor());
// singletonMap.put(EnvironmentVariableProcessor.class, new EnvironmentVariableProcessor());
// singletonMap.put(CommandLineValueProcessor.class, new CommandLineValueProcessor());
// singletonMap.put(PropertySuffixProcessor.class, new PropertySuffixProcessor());
// singletonMap.put(PropertyLocationsProcessor.class, new PropertyLocationsProcessor());
// singletonMap.put(PropertyExtensionProcessor.class, new PropertyExtensionProcessor());
// singletonMap.put(PropertiesFilesProcessor.class, new PropertiesFilesProcessor());
// singletonMap.put(DefaultValueProcessor.class, new DefaultValueProcessor());
//
// //ValueTransformers
// singletonMap.put(StringOrPrimitiveToPrimitiveTransformer.class, new StringOrPrimitiveToPrimitiveTransformer());
// singletonMap.put(CollectionToArrayListTransformer.class, new CollectionToArrayListTransformer());
// singletonMap.put(CollectionToHashSetTransformer.class, new CollectionToHashSetTransformer());
// singletonMap.put(CharacterSeparatedStringToStringListTransformer.class, new CharacterSeparatedStringToStringListTransformer());
// singletonMap.put(CharacterSeparatedStringToStringSetTransformer.class, new CharacterSeparatedStringToStringSetTransformer());
// singletonMap.put(StringCollectionToCommaSeparatedStringTransformer.class, new StringCollectionToCommaSeparatedStringTransformer());
// singletonMap.put(StringToPathTransformer.class, new StringToPathTransformer());
//
// //other
// singletonMap.put(ValidatorFactory.class, Validation.buildDefaultValidatorFactory());
// }
//
// public <K> K getInstance(Class<K> clazz) {
// if(singletonMap.get(clazz) != null) {
// return (K)singletonMap.get(clazz);
// }
// else {
// return createInstance(clazz);
// }
// }
//
// //TODO: exception message
// public <K> K createInstance(Class<K> clazz) {
// try {
// return clazz.newInstance();
// } catch (IllegalAccessException e) {
// ErrorMessageSetup errorMessageSetup = (ErrorMessageSetup)singletonMap.get(ErrorMessageSetup.class);
// throw new FactoryInstantiationException(errorMessageSetup.getErrorMessage(FactoryInstantiationException.class, clazz.toString()));
// } catch (InstantiationException e) {
// return createInstanceOfInnerClass(clazz);
// }
// }
//
// //TODO: exception message
// private <K> K createInstanceOfInnerClass(Class<K> clazz) {
// Class superClass = clazz.getDeclaringClass();
// try {
// Object superInstance = superClass.newInstance();
// Constructor<K> constructor = clazz.getConstructor(superClass);
// return constructor.newInstance(superInstance);
// } catch (Exception e) {
// ErrorMessageSetup errorMessageSetup = (ErrorMessageSetup)singletonMap.get(ErrorMessageSetup.class);
// throw new FactoryInstantiationException(errorMessageSetup.getErrorMessage(FactoryInstantiationException.class, clazz.toString()));
// }
// }
// }
// Path: src/main/java/com/tngtech/configbuilder/annotation/valueextractor/CommandLineValueProcessor.java
import com.tngtech.configbuilder.configuration.BuilderConfiguration;
import com.tngtech.configbuilder.util.ConfigBuilderFactory;
import java.lang.annotation.Annotation;
package com.tngtech.configbuilder.annotation.valueextractor;
/**
* Processes CommandLineValue annotations, implements ValueExtractorProcessor
*/
public class CommandLineValueProcessor implements ValueExtractorProcessor {
public String getValue(Annotation annotation, ConfigBuilderFactory configBuilderFactory) { | BuilderConfiguration builderConfiguration = configBuilderFactory.getInstance(BuilderConfiguration.class); |
bmatthias/config-builder | src/test/java/com/tngtech/configbuilder/util/AnnotationHelperTest.java | // Path: src/main/java/com/tngtech/configbuilder/annotation/valuetransformer/StringCollectionToCommaSeparatedStringTransformer.java
// public class StringCollectionToCommaSeparatedStringTransformer extends ValueTransformer<Collection<String>, String> {
//
// @Override
// public String transform(Collection<String> argument) {
// Joiner joiner = Joiner.on((String)additionalOptions[0]);
// return joiner.join(argument);
// }
// }
| import com.google.common.collect.Lists;
import com.tngtech.configbuilder.annotation.propertyloaderconfiguration.PropertyLoaderConfigurationAnnotation;
import com.tngtech.configbuilder.annotation.valuetransformer.StringCollectionToCommaSeparatedStringTransformer;
import com.tngtech.configbuilder.annotation.valuetransformer.ValueTransformers;
import com.tngtech.configbuilder.annotation.valueextractor.CommandLineValue;
import com.tngtech.configbuilder.annotation.valueextractor.PropertyValue;
import com.tngtech.configbuilder.annotation.valueextractor.ValueExtractorAnnotation;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.runners.MockitoJUnitRunner;
import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.util.Collection;
import java.util.List;
import static org.junit.Assert.*; | package com.tngtech.configbuilder.util;
@RunWith(MockitoJUnitRunner.class)
public class AnnotationHelperTest {
public class TestConfig {
@PropertyValue("testField")
@CommandLineValue(shortOpt = "t", longOpt = "testField") | // Path: src/main/java/com/tngtech/configbuilder/annotation/valuetransformer/StringCollectionToCommaSeparatedStringTransformer.java
// public class StringCollectionToCommaSeparatedStringTransformer extends ValueTransformer<Collection<String>, String> {
//
// @Override
// public String transform(Collection<String> argument) {
// Joiner joiner = Joiner.on((String)additionalOptions[0]);
// return joiner.join(argument);
// }
// }
// Path: src/test/java/com/tngtech/configbuilder/util/AnnotationHelperTest.java
import com.google.common.collect.Lists;
import com.tngtech.configbuilder.annotation.propertyloaderconfiguration.PropertyLoaderConfigurationAnnotation;
import com.tngtech.configbuilder.annotation.valuetransformer.StringCollectionToCommaSeparatedStringTransformer;
import com.tngtech.configbuilder.annotation.valuetransformer.ValueTransformers;
import com.tngtech.configbuilder.annotation.valueextractor.CommandLineValue;
import com.tngtech.configbuilder.annotation.valueextractor.PropertyValue;
import com.tngtech.configbuilder.annotation.valueextractor.ValueExtractorAnnotation;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.runners.MockitoJUnitRunner;
import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.util.Collection;
import java.util.List;
import static org.junit.Assert.*;
package com.tngtech.configbuilder.util;
@RunWith(MockitoJUnitRunner.class)
public class AnnotationHelperTest {
public class TestConfig {
@PropertyValue("testField")
@CommandLineValue(shortOpt = "t", longOpt = "testField") | @ValueTransformers({StringCollectionToCommaSeparatedStringTransformer.class}) |
bmatthias/config-builder | src/main/java/com/tngtech/configbuilder/util/ConstructionHelper.java | // Path: src/main/java/com/tngtech/configbuilder/configuration/ErrorMessageSetup.java
// public class ErrorMessageSetup {
//
// private Properties errorMessages;
//
// /**
// * loads the default error messages for the system locale, then merges them with additional error messages loaded with the PropertyLoader
// *
// * @param baseName the filename for additional error messages
// * @param propertyLoader the PropertyLoader used to load additional error messages
// */
// public void initialize(String baseName, PropertyLoader propertyLoader) {
// ResourceBundle resourceBundle = ResourceBundle.getBundle("errors");
// errorMessages = convertResourceBundleToProperties(resourceBundle);
// if (baseName != null) {
// errorMessages.putAll(propertyLoader.load(baseName));
// }
// }
//
// private Properties convertResourceBundleToProperties(ResourceBundle resource) {
// Properties properties = new Properties();
//
// Enumeration<String> keys = resource.getKeys();
// while (keys.hasMoreElements()) {
// String key = keys.nextElement();
// properties.put(key, resource.getString(key));
// }
// return properties;
// }
//
// public String getErrorMessage(Throwable e, String... variables) {
// String message = errorMessages.getProperty(e.getClass().getName());
// return message == null ? String.format(errorMessages.getProperty("standardMessage"), e.getClass().getName()) : String.format(message, variables);
// }
//
// public String getErrorMessage(Class exceptionClass, String... variables) {
// String message = errorMessages.getProperty(exceptionClass.getName());
// return message == null ? String.format(errorMessages.getProperty("standardMessage"), exceptionClass.getName()) : String.format(message, variables);
// }
// }
//
// Path: src/main/java/com/tngtech/configbuilder/exception/ConfigBuilderException.java
// public class ConfigBuilderException extends RuntimeException {
//
// public ConfigBuilderException(String message, Throwable e) {
// super(message, e);
// }
// }
//
// Path: src/main/java/com/tngtech/configbuilder/exception/NoConstructorFoundException.java
// public class NoConstructorFoundException extends RuntimeException {
// public NoConstructorFoundException(String message) {
// super(message);
// }
// }
| import com.tngtech.configbuilder.configuration.ErrorMessageSetup;
import com.tngtech.configbuilder.exception.ConfigBuilderException;
import com.tngtech.configbuilder.exception.NoConstructorFoundException;
import org.apache.log4j.Logger;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException; | package com.tngtech.configbuilder.util;
public class ConstructionHelper<T> {
private final static Logger log = Logger.getLogger(ConstructionHelper.class);
| // Path: src/main/java/com/tngtech/configbuilder/configuration/ErrorMessageSetup.java
// public class ErrorMessageSetup {
//
// private Properties errorMessages;
//
// /**
// * loads the default error messages for the system locale, then merges them with additional error messages loaded with the PropertyLoader
// *
// * @param baseName the filename for additional error messages
// * @param propertyLoader the PropertyLoader used to load additional error messages
// */
// public void initialize(String baseName, PropertyLoader propertyLoader) {
// ResourceBundle resourceBundle = ResourceBundle.getBundle("errors");
// errorMessages = convertResourceBundleToProperties(resourceBundle);
// if (baseName != null) {
// errorMessages.putAll(propertyLoader.load(baseName));
// }
// }
//
// private Properties convertResourceBundleToProperties(ResourceBundle resource) {
// Properties properties = new Properties();
//
// Enumeration<String> keys = resource.getKeys();
// while (keys.hasMoreElements()) {
// String key = keys.nextElement();
// properties.put(key, resource.getString(key));
// }
// return properties;
// }
//
// public String getErrorMessage(Throwable e, String... variables) {
// String message = errorMessages.getProperty(e.getClass().getName());
// return message == null ? String.format(errorMessages.getProperty("standardMessage"), e.getClass().getName()) : String.format(message, variables);
// }
//
// public String getErrorMessage(Class exceptionClass, String... variables) {
// String message = errorMessages.getProperty(exceptionClass.getName());
// return message == null ? String.format(errorMessages.getProperty("standardMessage"), exceptionClass.getName()) : String.format(message, variables);
// }
// }
//
// Path: src/main/java/com/tngtech/configbuilder/exception/ConfigBuilderException.java
// public class ConfigBuilderException extends RuntimeException {
//
// public ConfigBuilderException(String message, Throwable e) {
// super(message, e);
// }
// }
//
// Path: src/main/java/com/tngtech/configbuilder/exception/NoConstructorFoundException.java
// public class NoConstructorFoundException extends RuntimeException {
// public NoConstructorFoundException(String message) {
// super(message);
// }
// }
// Path: src/main/java/com/tngtech/configbuilder/util/ConstructionHelper.java
import com.tngtech.configbuilder.configuration.ErrorMessageSetup;
import com.tngtech.configbuilder.exception.ConfigBuilderException;
import com.tngtech.configbuilder.exception.NoConstructorFoundException;
import org.apache.log4j.Logger;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
package com.tngtech.configbuilder.util;
public class ConstructionHelper<T> {
private final static Logger log = Logger.getLogger(ConstructionHelper.class);
| private ErrorMessageSetup errorMessageSetup; |
bmatthias/config-builder | src/main/java/com/tngtech/configbuilder/util/ConstructionHelper.java | // Path: src/main/java/com/tngtech/configbuilder/configuration/ErrorMessageSetup.java
// public class ErrorMessageSetup {
//
// private Properties errorMessages;
//
// /**
// * loads the default error messages for the system locale, then merges them with additional error messages loaded with the PropertyLoader
// *
// * @param baseName the filename for additional error messages
// * @param propertyLoader the PropertyLoader used to load additional error messages
// */
// public void initialize(String baseName, PropertyLoader propertyLoader) {
// ResourceBundle resourceBundle = ResourceBundle.getBundle("errors");
// errorMessages = convertResourceBundleToProperties(resourceBundle);
// if (baseName != null) {
// errorMessages.putAll(propertyLoader.load(baseName));
// }
// }
//
// private Properties convertResourceBundleToProperties(ResourceBundle resource) {
// Properties properties = new Properties();
//
// Enumeration<String> keys = resource.getKeys();
// while (keys.hasMoreElements()) {
// String key = keys.nextElement();
// properties.put(key, resource.getString(key));
// }
// return properties;
// }
//
// public String getErrorMessage(Throwable e, String... variables) {
// String message = errorMessages.getProperty(e.getClass().getName());
// return message == null ? String.format(errorMessages.getProperty("standardMessage"), e.getClass().getName()) : String.format(message, variables);
// }
//
// public String getErrorMessage(Class exceptionClass, String... variables) {
// String message = errorMessages.getProperty(exceptionClass.getName());
// return message == null ? String.format(errorMessages.getProperty("standardMessage"), exceptionClass.getName()) : String.format(message, variables);
// }
// }
//
// Path: src/main/java/com/tngtech/configbuilder/exception/ConfigBuilderException.java
// public class ConfigBuilderException extends RuntimeException {
//
// public ConfigBuilderException(String message, Throwable e) {
// super(message, e);
// }
// }
//
// Path: src/main/java/com/tngtech/configbuilder/exception/NoConstructorFoundException.java
// public class NoConstructorFoundException extends RuntimeException {
// public NoConstructorFoundException(String message) {
// super(message);
// }
// }
| import com.tngtech.configbuilder.configuration.ErrorMessageSetup;
import com.tngtech.configbuilder.exception.ConfigBuilderException;
import com.tngtech.configbuilder.exception.NoConstructorFoundException;
import org.apache.log4j.Logger;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException; | package com.tngtech.configbuilder.util;
public class ConstructionHelper<T> {
private final static Logger log = Logger.getLogger(ConstructionHelper.class);
private ErrorMessageSetup errorMessageSetup;
public ConstructionHelper(ConfigBuilderFactory configBuilderFactory) {
this.errorMessageSetup = configBuilderFactory.getInstance(ErrorMessageSetup.class);
}
public T getInstance(Class<T> configClass, Object... objects) {
try {
Constructor<T> tConstructor = findSuitableConstructor(configClass, objects);
log.info(String.format("found constructor - instantiating %s", configClass.getName()));
tConstructor.setAccessible(true);
return tConstructor.newInstance(objects);
} catch (InstantiationException | IllegalAccessException | InvocationTargetException e) { | // Path: src/main/java/com/tngtech/configbuilder/configuration/ErrorMessageSetup.java
// public class ErrorMessageSetup {
//
// private Properties errorMessages;
//
// /**
// * loads the default error messages for the system locale, then merges them with additional error messages loaded with the PropertyLoader
// *
// * @param baseName the filename for additional error messages
// * @param propertyLoader the PropertyLoader used to load additional error messages
// */
// public void initialize(String baseName, PropertyLoader propertyLoader) {
// ResourceBundle resourceBundle = ResourceBundle.getBundle("errors");
// errorMessages = convertResourceBundleToProperties(resourceBundle);
// if (baseName != null) {
// errorMessages.putAll(propertyLoader.load(baseName));
// }
// }
//
// private Properties convertResourceBundleToProperties(ResourceBundle resource) {
// Properties properties = new Properties();
//
// Enumeration<String> keys = resource.getKeys();
// while (keys.hasMoreElements()) {
// String key = keys.nextElement();
// properties.put(key, resource.getString(key));
// }
// return properties;
// }
//
// public String getErrorMessage(Throwable e, String... variables) {
// String message = errorMessages.getProperty(e.getClass().getName());
// return message == null ? String.format(errorMessages.getProperty("standardMessage"), e.getClass().getName()) : String.format(message, variables);
// }
//
// public String getErrorMessage(Class exceptionClass, String... variables) {
// String message = errorMessages.getProperty(exceptionClass.getName());
// return message == null ? String.format(errorMessages.getProperty("standardMessage"), exceptionClass.getName()) : String.format(message, variables);
// }
// }
//
// Path: src/main/java/com/tngtech/configbuilder/exception/ConfigBuilderException.java
// public class ConfigBuilderException extends RuntimeException {
//
// public ConfigBuilderException(String message, Throwable e) {
// super(message, e);
// }
// }
//
// Path: src/main/java/com/tngtech/configbuilder/exception/NoConstructorFoundException.java
// public class NoConstructorFoundException extends RuntimeException {
// public NoConstructorFoundException(String message) {
// super(message);
// }
// }
// Path: src/main/java/com/tngtech/configbuilder/util/ConstructionHelper.java
import com.tngtech.configbuilder.configuration.ErrorMessageSetup;
import com.tngtech.configbuilder.exception.ConfigBuilderException;
import com.tngtech.configbuilder.exception.NoConstructorFoundException;
import org.apache.log4j.Logger;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
package com.tngtech.configbuilder.util;
public class ConstructionHelper<T> {
private final static Logger log = Logger.getLogger(ConstructionHelper.class);
private ErrorMessageSetup errorMessageSetup;
public ConstructionHelper(ConfigBuilderFactory configBuilderFactory) {
this.errorMessageSetup = configBuilderFactory.getInstance(ErrorMessageSetup.class);
}
public T getInstance(Class<T> configClass, Object... objects) {
try {
Constructor<T> tConstructor = findSuitableConstructor(configClass, objects);
log.info(String.format("found constructor - instantiating %s", configClass.getName()));
tConstructor.setAccessible(true);
return tConstructor.newInstance(objects);
} catch (InstantiationException | IllegalAccessException | InvocationTargetException e) { | throw new ConfigBuilderException(errorMessageSetup.getErrorMessage(e), e); |
bmatthias/config-builder | src/main/java/com/tngtech/configbuilder/util/ConstructionHelper.java | // Path: src/main/java/com/tngtech/configbuilder/configuration/ErrorMessageSetup.java
// public class ErrorMessageSetup {
//
// private Properties errorMessages;
//
// /**
// * loads the default error messages for the system locale, then merges them with additional error messages loaded with the PropertyLoader
// *
// * @param baseName the filename for additional error messages
// * @param propertyLoader the PropertyLoader used to load additional error messages
// */
// public void initialize(String baseName, PropertyLoader propertyLoader) {
// ResourceBundle resourceBundle = ResourceBundle.getBundle("errors");
// errorMessages = convertResourceBundleToProperties(resourceBundle);
// if (baseName != null) {
// errorMessages.putAll(propertyLoader.load(baseName));
// }
// }
//
// private Properties convertResourceBundleToProperties(ResourceBundle resource) {
// Properties properties = new Properties();
//
// Enumeration<String> keys = resource.getKeys();
// while (keys.hasMoreElements()) {
// String key = keys.nextElement();
// properties.put(key, resource.getString(key));
// }
// return properties;
// }
//
// public String getErrorMessage(Throwable e, String... variables) {
// String message = errorMessages.getProperty(e.getClass().getName());
// return message == null ? String.format(errorMessages.getProperty("standardMessage"), e.getClass().getName()) : String.format(message, variables);
// }
//
// public String getErrorMessage(Class exceptionClass, String... variables) {
// String message = errorMessages.getProperty(exceptionClass.getName());
// return message == null ? String.format(errorMessages.getProperty("standardMessage"), exceptionClass.getName()) : String.format(message, variables);
// }
// }
//
// Path: src/main/java/com/tngtech/configbuilder/exception/ConfigBuilderException.java
// public class ConfigBuilderException extends RuntimeException {
//
// public ConfigBuilderException(String message, Throwable e) {
// super(message, e);
// }
// }
//
// Path: src/main/java/com/tngtech/configbuilder/exception/NoConstructorFoundException.java
// public class NoConstructorFoundException extends RuntimeException {
// public NoConstructorFoundException(String message) {
// super(message);
// }
// }
| import com.tngtech.configbuilder.configuration.ErrorMessageSetup;
import com.tngtech.configbuilder.exception.ConfigBuilderException;
import com.tngtech.configbuilder.exception.NoConstructorFoundException;
import org.apache.log4j.Logger;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException; | package com.tngtech.configbuilder.util;
public class ConstructionHelper<T> {
private final static Logger log = Logger.getLogger(ConstructionHelper.class);
private ErrorMessageSetup errorMessageSetup;
public ConstructionHelper(ConfigBuilderFactory configBuilderFactory) {
this.errorMessageSetup = configBuilderFactory.getInstance(ErrorMessageSetup.class);
}
public T getInstance(Class<T> configClass, Object... objects) {
try {
Constructor<T> tConstructor = findSuitableConstructor(configClass, objects);
log.info(String.format("found constructor - instantiating %s", configClass.getName()));
tConstructor.setAccessible(true);
return tConstructor.newInstance(objects);
} catch (InstantiationException | IllegalAccessException | InvocationTargetException e) {
throw new ConfigBuilderException(errorMessageSetup.getErrorMessage(e), e);
}
}
@SuppressWarnings("unchecked")
private Constructor<T> findSuitableConstructor(Class<T> configClass, Object... objects) {
log.debug(String.format("trying to find a constructor for %s matching the arguments of build()", configClass.getName()));
Constructor[] constructors = configClass.getDeclaredConstructors();
for (Constructor<T> constructor : constructors) {
if (constructorIsMatching(constructor, objects)) {
return constructor;
}
} | // Path: src/main/java/com/tngtech/configbuilder/configuration/ErrorMessageSetup.java
// public class ErrorMessageSetup {
//
// private Properties errorMessages;
//
// /**
// * loads the default error messages for the system locale, then merges them with additional error messages loaded with the PropertyLoader
// *
// * @param baseName the filename for additional error messages
// * @param propertyLoader the PropertyLoader used to load additional error messages
// */
// public void initialize(String baseName, PropertyLoader propertyLoader) {
// ResourceBundle resourceBundle = ResourceBundle.getBundle("errors");
// errorMessages = convertResourceBundleToProperties(resourceBundle);
// if (baseName != null) {
// errorMessages.putAll(propertyLoader.load(baseName));
// }
// }
//
// private Properties convertResourceBundleToProperties(ResourceBundle resource) {
// Properties properties = new Properties();
//
// Enumeration<String> keys = resource.getKeys();
// while (keys.hasMoreElements()) {
// String key = keys.nextElement();
// properties.put(key, resource.getString(key));
// }
// return properties;
// }
//
// public String getErrorMessage(Throwable e, String... variables) {
// String message = errorMessages.getProperty(e.getClass().getName());
// return message == null ? String.format(errorMessages.getProperty("standardMessage"), e.getClass().getName()) : String.format(message, variables);
// }
//
// public String getErrorMessage(Class exceptionClass, String... variables) {
// String message = errorMessages.getProperty(exceptionClass.getName());
// return message == null ? String.format(errorMessages.getProperty("standardMessage"), exceptionClass.getName()) : String.format(message, variables);
// }
// }
//
// Path: src/main/java/com/tngtech/configbuilder/exception/ConfigBuilderException.java
// public class ConfigBuilderException extends RuntimeException {
//
// public ConfigBuilderException(String message, Throwable e) {
// super(message, e);
// }
// }
//
// Path: src/main/java/com/tngtech/configbuilder/exception/NoConstructorFoundException.java
// public class NoConstructorFoundException extends RuntimeException {
// public NoConstructorFoundException(String message) {
// super(message);
// }
// }
// Path: src/main/java/com/tngtech/configbuilder/util/ConstructionHelper.java
import com.tngtech.configbuilder.configuration.ErrorMessageSetup;
import com.tngtech.configbuilder.exception.ConfigBuilderException;
import com.tngtech.configbuilder.exception.NoConstructorFoundException;
import org.apache.log4j.Logger;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
package com.tngtech.configbuilder.util;
public class ConstructionHelper<T> {
private final static Logger log = Logger.getLogger(ConstructionHelper.class);
private ErrorMessageSetup errorMessageSetup;
public ConstructionHelper(ConfigBuilderFactory configBuilderFactory) {
this.errorMessageSetup = configBuilderFactory.getInstance(ErrorMessageSetup.class);
}
public T getInstance(Class<T> configClass, Object... objects) {
try {
Constructor<T> tConstructor = findSuitableConstructor(configClass, objects);
log.info(String.format("found constructor - instantiating %s", configClass.getName()));
tConstructor.setAccessible(true);
return tConstructor.newInstance(objects);
} catch (InstantiationException | IllegalAccessException | InvocationTargetException e) {
throw new ConfigBuilderException(errorMessageSetup.getErrorMessage(e), e);
}
}
@SuppressWarnings("unchecked")
private Constructor<T> findSuitableConstructor(Class<T> configClass, Object... objects) {
log.debug(String.format("trying to find a constructor for %s matching the arguments of build()", configClass.getName()));
Constructor[] constructors = configClass.getDeclaredConstructors();
for (Constructor<T> constructor : constructors) {
if (constructorIsMatching(constructor, objects)) {
return constructor;
}
} | throw new NoConstructorFoundException(errorMessageSetup.getErrorMessage(NoConstructorFoundException.class)); |
bmatthias/config-builder | src/main/java/com/tngtech/configbuilder/util/FieldValueExtractor.java | // Path: src/main/java/com/tngtech/configbuilder/annotation/valueextractor/ValueExtractorProcessor.java
// public interface ValueExtractorProcessor {
// public Object getValue(Annotation annotation, ConfigBuilderFactory configBuilderFactory);
// }
//
// Path: src/main/java/com/tngtech/configbuilder/configuration/BuilderConfiguration.java
// public class BuilderConfiguration {
//
// private Properties properties;
// private CommandLine commandLine;
// private Object importedConfiguration;
// private Class<? extends Annotation>[] annotationOrder = new Class[]{CommandLineValue.class, PropertyValue.class, EnvironmentVariableValue.class, SystemPropertyValue.class, ImportedValue.class, DefaultValue.class};
//
// public BuilderConfiguration() {
// properties = new Properties();
// commandLine = null;
// importedConfiguration = null;
// }
//
// public CommandLine getCommandLine() {
// return commandLine;
// }
//
// public Properties getProperties() {
// return properties;
// }
//
// public Object getImportedConfiguration() {
// return importedConfiguration;
// }
//
// public void setProperties(Properties properties) {
// this.properties = properties;
// }
//
// public void setCommandLine(CommandLine commandLine) {
// this.commandLine = commandLine;
// }
//
// public void setImportedConfiguration(Object importedConfiguration) {
// this.importedConfiguration = importedConfiguration;
// }
//
// public void setAnnotationOrder(Class<? extends Annotation>[] annotationOrder) {
// this.annotationOrder = annotationOrder;
// }
//
// public Class<? extends Annotation>[] getAnnotationOrder() {
// return annotationOrder;
// }
// }
| import com.tngtech.configbuilder.annotation.configuration.LoadingOrder;
import com.tngtech.configbuilder.annotation.valueextractor.ValueExtractorProcessor;
import com.tngtech.configbuilder.annotation.valueextractor.ValueExtractorAnnotation;
import com.tngtech.configbuilder.configuration.BuilderConfiguration;
import org.apache.log4j.Logger;
import java.lang.annotation.Annotation;
import java.lang.reflect.Field; | package com.tngtech.configbuilder.util;
public class FieldValueExtractor {
private final static Logger log = Logger.getLogger(FieldValueExtractor.class);
private final AnnotationHelper annotationHelper;
private final ConfigBuilderFactory configBuilderFactory;
public FieldValueExtractor(ConfigBuilderFactory configBuilderFactory) {
this.configBuilderFactory = configBuilderFactory;
this.annotationHelper = configBuilderFactory.getInstance(AnnotationHelper.class);
}
| // Path: src/main/java/com/tngtech/configbuilder/annotation/valueextractor/ValueExtractorProcessor.java
// public interface ValueExtractorProcessor {
// public Object getValue(Annotation annotation, ConfigBuilderFactory configBuilderFactory);
// }
//
// Path: src/main/java/com/tngtech/configbuilder/configuration/BuilderConfiguration.java
// public class BuilderConfiguration {
//
// private Properties properties;
// private CommandLine commandLine;
// private Object importedConfiguration;
// private Class<? extends Annotation>[] annotationOrder = new Class[]{CommandLineValue.class, PropertyValue.class, EnvironmentVariableValue.class, SystemPropertyValue.class, ImportedValue.class, DefaultValue.class};
//
// public BuilderConfiguration() {
// properties = new Properties();
// commandLine = null;
// importedConfiguration = null;
// }
//
// public CommandLine getCommandLine() {
// return commandLine;
// }
//
// public Properties getProperties() {
// return properties;
// }
//
// public Object getImportedConfiguration() {
// return importedConfiguration;
// }
//
// public void setProperties(Properties properties) {
// this.properties = properties;
// }
//
// public void setCommandLine(CommandLine commandLine) {
// this.commandLine = commandLine;
// }
//
// public void setImportedConfiguration(Object importedConfiguration) {
// this.importedConfiguration = importedConfiguration;
// }
//
// public void setAnnotationOrder(Class<? extends Annotation>[] annotationOrder) {
// this.annotationOrder = annotationOrder;
// }
//
// public Class<? extends Annotation>[] getAnnotationOrder() {
// return annotationOrder;
// }
// }
// Path: src/main/java/com/tngtech/configbuilder/util/FieldValueExtractor.java
import com.tngtech.configbuilder.annotation.configuration.LoadingOrder;
import com.tngtech.configbuilder.annotation.valueextractor.ValueExtractorProcessor;
import com.tngtech.configbuilder.annotation.valueextractor.ValueExtractorAnnotation;
import com.tngtech.configbuilder.configuration.BuilderConfiguration;
import org.apache.log4j.Logger;
import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
package com.tngtech.configbuilder.util;
public class FieldValueExtractor {
private final static Logger log = Logger.getLogger(FieldValueExtractor.class);
private final AnnotationHelper annotationHelper;
private final ConfigBuilderFactory configBuilderFactory;
public FieldValueExtractor(ConfigBuilderFactory configBuilderFactory) {
this.configBuilderFactory = configBuilderFactory;
this.annotationHelper = configBuilderFactory.getInstance(AnnotationHelper.class);
}
| public Object extractValue(Field field, BuilderConfiguration builderConfiguration) { |
bmatthias/config-builder | src/main/java/com/tngtech/configbuilder/util/FieldValueExtractor.java | // Path: src/main/java/com/tngtech/configbuilder/annotation/valueextractor/ValueExtractorProcessor.java
// public interface ValueExtractorProcessor {
// public Object getValue(Annotation annotation, ConfigBuilderFactory configBuilderFactory);
// }
//
// Path: src/main/java/com/tngtech/configbuilder/configuration/BuilderConfiguration.java
// public class BuilderConfiguration {
//
// private Properties properties;
// private CommandLine commandLine;
// private Object importedConfiguration;
// private Class<? extends Annotation>[] annotationOrder = new Class[]{CommandLineValue.class, PropertyValue.class, EnvironmentVariableValue.class, SystemPropertyValue.class, ImportedValue.class, DefaultValue.class};
//
// public BuilderConfiguration() {
// properties = new Properties();
// commandLine = null;
// importedConfiguration = null;
// }
//
// public CommandLine getCommandLine() {
// return commandLine;
// }
//
// public Properties getProperties() {
// return properties;
// }
//
// public Object getImportedConfiguration() {
// return importedConfiguration;
// }
//
// public void setProperties(Properties properties) {
// this.properties = properties;
// }
//
// public void setCommandLine(CommandLine commandLine) {
// this.commandLine = commandLine;
// }
//
// public void setImportedConfiguration(Object importedConfiguration) {
// this.importedConfiguration = importedConfiguration;
// }
//
// public void setAnnotationOrder(Class<? extends Annotation>[] annotationOrder) {
// this.annotationOrder = annotationOrder;
// }
//
// public Class<? extends Annotation>[] getAnnotationOrder() {
// return annotationOrder;
// }
// }
| import com.tngtech.configbuilder.annotation.configuration.LoadingOrder;
import com.tngtech.configbuilder.annotation.valueextractor.ValueExtractorProcessor;
import com.tngtech.configbuilder.annotation.valueextractor.ValueExtractorAnnotation;
import com.tngtech.configbuilder.configuration.BuilderConfiguration;
import org.apache.log4j.Logger;
import java.lang.annotation.Annotation;
import java.lang.reflect.Field; | package com.tngtech.configbuilder.util;
public class FieldValueExtractor {
private final static Logger log = Logger.getLogger(FieldValueExtractor.class);
private final AnnotationHelper annotationHelper;
private final ConfigBuilderFactory configBuilderFactory;
public FieldValueExtractor(ConfigBuilderFactory configBuilderFactory) {
this.configBuilderFactory = configBuilderFactory;
this.annotationHelper = configBuilderFactory.getInstance(AnnotationHelper.class);
}
public Object extractValue(Field field, BuilderConfiguration builderConfiguration) {
Object value = null;
Class<? extends Annotation>[] annotationOrderOfField = field.isAnnotationPresent(LoadingOrder.class) ? field.getAnnotation(LoadingOrder.class).value() : builderConfiguration.getAnnotationOrder(); | // Path: src/main/java/com/tngtech/configbuilder/annotation/valueextractor/ValueExtractorProcessor.java
// public interface ValueExtractorProcessor {
// public Object getValue(Annotation annotation, ConfigBuilderFactory configBuilderFactory);
// }
//
// Path: src/main/java/com/tngtech/configbuilder/configuration/BuilderConfiguration.java
// public class BuilderConfiguration {
//
// private Properties properties;
// private CommandLine commandLine;
// private Object importedConfiguration;
// private Class<? extends Annotation>[] annotationOrder = new Class[]{CommandLineValue.class, PropertyValue.class, EnvironmentVariableValue.class, SystemPropertyValue.class, ImportedValue.class, DefaultValue.class};
//
// public BuilderConfiguration() {
// properties = new Properties();
// commandLine = null;
// importedConfiguration = null;
// }
//
// public CommandLine getCommandLine() {
// return commandLine;
// }
//
// public Properties getProperties() {
// return properties;
// }
//
// public Object getImportedConfiguration() {
// return importedConfiguration;
// }
//
// public void setProperties(Properties properties) {
// this.properties = properties;
// }
//
// public void setCommandLine(CommandLine commandLine) {
// this.commandLine = commandLine;
// }
//
// public void setImportedConfiguration(Object importedConfiguration) {
// this.importedConfiguration = importedConfiguration;
// }
//
// public void setAnnotationOrder(Class<? extends Annotation>[] annotationOrder) {
// this.annotationOrder = annotationOrder;
// }
//
// public Class<? extends Annotation>[] getAnnotationOrder() {
// return annotationOrder;
// }
// }
// Path: src/main/java/com/tngtech/configbuilder/util/FieldValueExtractor.java
import com.tngtech.configbuilder.annotation.configuration.LoadingOrder;
import com.tngtech.configbuilder.annotation.valueextractor.ValueExtractorProcessor;
import com.tngtech.configbuilder.annotation.valueextractor.ValueExtractorAnnotation;
import com.tngtech.configbuilder.configuration.BuilderConfiguration;
import org.apache.log4j.Logger;
import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
package com.tngtech.configbuilder.util;
public class FieldValueExtractor {
private final static Logger log = Logger.getLogger(FieldValueExtractor.class);
private final AnnotationHelper annotationHelper;
private final ConfigBuilderFactory configBuilderFactory;
public FieldValueExtractor(ConfigBuilderFactory configBuilderFactory) {
this.configBuilderFactory = configBuilderFactory;
this.annotationHelper = configBuilderFactory.getInstance(AnnotationHelper.class);
}
public Object extractValue(Field field, BuilderConfiguration builderConfiguration) {
Object value = null;
Class<? extends Annotation>[] annotationOrderOfField = field.isAnnotationPresent(LoadingOrder.class) ? field.getAnnotation(LoadingOrder.class).value() : builderConfiguration.getAnnotationOrder(); | Class<? extends ValueExtractorProcessor> processor; |
bmatthias/config-builder | src/test/java/com/tngtech/configbuilder/annotation/valueextractor/EnvironmentVariableProcessorTest.java | // Path: src/main/java/com/tngtech/configbuilder/configuration/BuilderConfiguration.java
// public class BuilderConfiguration {
//
// private Properties properties;
// private CommandLine commandLine;
// private Object importedConfiguration;
// private Class<? extends Annotation>[] annotationOrder = new Class[]{CommandLineValue.class, PropertyValue.class, EnvironmentVariableValue.class, SystemPropertyValue.class, ImportedValue.class, DefaultValue.class};
//
// public BuilderConfiguration() {
// properties = new Properties();
// commandLine = null;
// importedConfiguration = null;
// }
//
// public CommandLine getCommandLine() {
// return commandLine;
// }
//
// public Properties getProperties() {
// return properties;
// }
//
// public Object getImportedConfiguration() {
// return importedConfiguration;
// }
//
// public void setProperties(Properties properties) {
// this.properties = properties;
// }
//
// public void setCommandLine(CommandLine commandLine) {
// this.commandLine = commandLine;
// }
//
// public void setImportedConfiguration(Object importedConfiguration) {
// this.importedConfiguration = importedConfiguration;
// }
//
// public void setAnnotationOrder(Class<? extends Annotation>[] annotationOrder) {
// this.annotationOrder = annotationOrder;
// }
//
// public Class<? extends Annotation>[] getAnnotationOrder() {
// return annotationOrder;
// }
// }
//
// Path: src/main/java/com/tngtech/configbuilder/util/ConfigBuilderFactory.java
// public class ConfigBuilderFactory {
//
// private Map<Class,Object> singletonMap = Maps.newHashMap();
//
// public <T> void initialize() {
//
// //Order is IMPORTANT!
//
// //configuration
// singletonMap.put(ErrorMessageSetup.class, new ErrorMessageSetup());
// singletonMap.put(BuilderConfiguration.class, new BuilderConfiguration());
//
// //util
// singletonMap.put(AnnotationHelper.class, new AnnotationHelper());
// singletonMap.put(GenericsAndCastingHelper.class, new GenericsAndCastingHelper());
// singletonMap.put(FieldValueExtractor.class, new FieldValueExtractor(this));
// singletonMap.put(FieldValueTransformer.class, new FieldValueTransformer(this));
// singletonMap.put(PropertyLoaderConfigurator.class, new PropertyLoaderConfigurator(this));
// singletonMap.put(ConstructionHelper.class, new ConstructionHelper<T>(this));
// singletonMap.put(FieldSetter.class, new FieldSetter<T>(this));
// singletonMap.put(ConfigValidator.class, new ConfigValidator<T>(this));
// singletonMap.put(CommandLineHelper.class, new CommandLineHelper(this));
//
// //AnnotationProcessors
// singletonMap.put(SystemPropertyProcessor.class, new SystemPropertyProcessor());
// singletonMap.put(PropertyValueProcessor.class, new PropertyValueProcessor());
// singletonMap.put(EnvironmentVariableProcessor.class, new EnvironmentVariableProcessor());
// singletonMap.put(CommandLineValueProcessor.class, new CommandLineValueProcessor());
// singletonMap.put(PropertySuffixProcessor.class, new PropertySuffixProcessor());
// singletonMap.put(PropertyLocationsProcessor.class, new PropertyLocationsProcessor());
// singletonMap.put(PropertyExtensionProcessor.class, new PropertyExtensionProcessor());
// singletonMap.put(PropertiesFilesProcessor.class, new PropertiesFilesProcessor());
// singletonMap.put(DefaultValueProcessor.class, new DefaultValueProcessor());
//
// //ValueTransformers
// singletonMap.put(StringOrPrimitiveToPrimitiveTransformer.class, new StringOrPrimitiveToPrimitiveTransformer());
// singletonMap.put(CollectionToArrayListTransformer.class, new CollectionToArrayListTransformer());
// singletonMap.put(CollectionToHashSetTransformer.class, new CollectionToHashSetTransformer());
// singletonMap.put(CharacterSeparatedStringToStringListTransformer.class, new CharacterSeparatedStringToStringListTransformer());
// singletonMap.put(CharacterSeparatedStringToStringSetTransformer.class, new CharacterSeparatedStringToStringSetTransformer());
// singletonMap.put(StringCollectionToCommaSeparatedStringTransformer.class, new StringCollectionToCommaSeparatedStringTransformer());
// singletonMap.put(StringToPathTransformer.class, new StringToPathTransformer());
//
// //other
// singletonMap.put(ValidatorFactory.class, Validation.buildDefaultValidatorFactory());
// }
//
// public <K> K getInstance(Class<K> clazz) {
// if(singletonMap.get(clazz) != null) {
// return (K)singletonMap.get(clazz);
// }
// else {
// return createInstance(clazz);
// }
// }
//
// //TODO: exception message
// public <K> K createInstance(Class<K> clazz) {
// try {
// return clazz.newInstance();
// } catch (IllegalAccessException e) {
// ErrorMessageSetup errorMessageSetup = (ErrorMessageSetup)singletonMap.get(ErrorMessageSetup.class);
// throw new FactoryInstantiationException(errorMessageSetup.getErrorMessage(FactoryInstantiationException.class, clazz.toString()));
// } catch (InstantiationException e) {
// return createInstanceOfInnerClass(clazz);
// }
// }
//
// //TODO: exception message
// private <K> K createInstanceOfInnerClass(Class<K> clazz) {
// Class superClass = clazz.getDeclaringClass();
// try {
// Object superInstance = superClass.newInstance();
// Constructor<K> constructor = clazz.getConstructor(superClass);
// return constructor.newInstance(superInstance);
// } catch (Exception e) {
// ErrorMessageSetup errorMessageSetup = (ErrorMessageSetup)singletonMap.get(ErrorMessageSetup.class);
// throw new FactoryInstantiationException(errorMessageSetup.getErrorMessage(FactoryInstantiationException.class, clazz.toString()));
// }
// }
// }
| import com.tngtech.configbuilder.configuration.BuilderConfiguration;
import com.tngtech.configbuilder.util.ConfigBuilderFactory;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.when; | package com.tngtech.configbuilder.annotation.valueextractor;
@RunWith(MockitoJUnitRunner.class)
public class EnvironmentVariableProcessorTest {
private EnvironmentVariableProcessor environmentVariableProcessor;
@Mock
private EnvironmentVariableValue environmentVariableValue;
@Mock | // Path: src/main/java/com/tngtech/configbuilder/configuration/BuilderConfiguration.java
// public class BuilderConfiguration {
//
// private Properties properties;
// private CommandLine commandLine;
// private Object importedConfiguration;
// private Class<? extends Annotation>[] annotationOrder = new Class[]{CommandLineValue.class, PropertyValue.class, EnvironmentVariableValue.class, SystemPropertyValue.class, ImportedValue.class, DefaultValue.class};
//
// public BuilderConfiguration() {
// properties = new Properties();
// commandLine = null;
// importedConfiguration = null;
// }
//
// public CommandLine getCommandLine() {
// return commandLine;
// }
//
// public Properties getProperties() {
// return properties;
// }
//
// public Object getImportedConfiguration() {
// return importedConfiguration;
// }
//
// public void setProperties(Properties properties) {
// this.properties = properties;
// }
//
// public void setCommandLine(CommandLine commandLine) {
// this.commandLine = commandLine;
// }
//
// public void setImportedConfiguration(Object importedConfiguration) {
// this.importedConfiguration = importedConfiguration;
// }
//
// public void setAnnotationOrder(Class<? extends Annotation>[] annotationOrder) {
// this.annotationOrder = annotationOrder;
// }
//
// public Class<? extends Annotation>[] getAnnotationOrder() {
// return annotationOrder;
// }
// }
//
// Path: src/main/java/com/tngtech/configbuilder/util/ConfigBuilderFactory.java
// public class ConfigBuilderFactory {
//
// private Map<Class,Object> singletonMap = Maps.newHashMap();
//
// public <T> void initialize() {
//
// //Order is IMPORTANT!
//
// //configuration
// singletonMap.put(ErrorMessageSetup.class, new ErrorMessageSetup());
// singletonMap.put(BuilderConfiguration.class, new BuilderConfiguration());
//
// //util
// singletonMap.put(AnnotationHelper.class, new AnnotationHelper());
// singletonMap.put(GenericsAndCastingHelper.class, new GenericsAndCastingHelper());
// singletonMap.put(FieldValueExtractor.class, new FieldValueExtractor(this));
// singletonMap.put(FieldValueTransformer.class, new FieldValueTransformer(this));
// singletonMap.put(PropertyLoaderConfigurator.class, new PropertyLoaderConfigurator(this));
// singletonMap.put(ConstructionHelper.class, new ConstructionHelper<T>(this));
// singletonMap.put(FieldSetter.class, new FieldSetter<T>(this));
// singletonMap.put(ConfigValidator.class, new ConfigValidator<T>(this));
// singletonMap.put(CommandLineHelper.class, new CommandLineHelper(this));
//
// //AnnotationProcessors
// singletonMap.put(SystemPropertyProcessor.class, new SystemPropertyProcessor());
// singletonMap.put(PropertyValueProcessor.class, new PropertyValueProcessor());
// singletonMap.put(EnvironmentVariableProcessor.class, new EnvironmentVariableProcessor());
// singletonMap.put(CommandLineValueProcessor.class, new CommandLineValueProcessor());
// singletonMap.put(PropertySuffixProcessor.class, new PropertySuffixProcessor());
// singletonMap.put(PropertyLocationsProcessor.class, new PropertyLocationsProcessor());
// singletonMap.put(PropertyExtensionProcessor.class, new PropertyExtensionProcessor());
// singletonMap.put(PropertiesFilesProcessor.class, new PropertiesFilesProcessor());
// singletonMap.put(DefaultValueProcessor.class, new DefaultValueProcessor());
//
// //ValueTransformers
// singletonMap.put(StringOrPrimitiveToPrimitiveTransformer.class, new StringOrPrimitiveToPrimitiveTransformer());
// singletonMap.put(CollectionToArrayListTransformer.class, new CollectionToArrayListTransformer());
// singletonMap.put(CollectionToHashSetTransformer.class, new CollectionToHashSetTransformer());
// singletonMap.put(CharacterSeparatedStringToStringListTransformer.class, new CharacterSeparatedStringToStringListTransformer());
// singletonMap.put(CharacterSeparatedStringToStringSetTransformer.class, new CharacterSeparatedStringToStringSetTransformer());
// singletonMap.put(StringCollectionToCommaSeparatedStringTransformer.class, new StringCollectionToCommaSeparatedStringTransformer());
// singletonMap.put(StringToPathTransformer.class, new StringToPathTransformer());
//
// //other
// singletonMap.put(ValidatorFactory.class, Validation.buildDefaultValidatorFactory());
// }
//
// public <K> K getInstance(Class<K> clazz) {
// if(singletonMap.get(clazz) != null) {
// return (K)singletonMap.get(clazz);
// }
// else {
// return createInstance(clazz);
// }
// }
//
// //TODO: exception message
// public <K> K createInstance(Class<K> clazz) {
// try {
// return clazz.newInstance();
// } catch (IllegalAccessException e) {
// ErrorMessageSetup errorMessageSetup = (ErrorMessageSetup)singletonMap.get(ErrorMessageSetup.class);
// throw new FactoryInstantiationException(errorMessageSetup.getErrorMessage(FactoryInstantiationException.class, clazz.toString()));
// } catch (InstantiationException e) {
// return createInstanceOfInnerClass(clazz);
// }
// }
//
// //TODO: exception message
// private <K> K createInstanceOfInnerClass(Class<K> clazz) {
// Class superClass = clazz.getDeclaringClass();
// try {
// Object superInstance = superClass.newInstance();
// Constructor<K> constructor = clazz.getConstructor(superClass);
// return constructor.newInstance(superInstance);
// } catch (Exception e) {
// ErrorMessageSetup errorMessageSetup = (ErrorMessageSetup)singletonMap.get(ErrorMessageSetup.class);
// throw new FactoryInstantiationException(errorMessageSetup.getErrorMessage(FactoryInstantiationException.class, clazz.toString()));
// }
// }
// }
// Path: src/test/java/com/tngtech/configbuilder/annotation/valueextractor/EnvironmentVariableProcessorTest.java
import com.tngtech.configbuilder.configuration.BuilderConfiguration;
import com.tngtech.configbuilder.util.ConfigBuilderFactory;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.when;
package com.tngtech.configbuilder.annotation.valueextractor;
@RunWith(MockitoJUnitRunner.class)
public class EnvironmentVariableProcessorTest {
private EnvironmentVariableProcessor environmentVariableProcessor;
@Mock
private EnvironmentVariableValue environmentVariableValue;
@Mock | private BuilderConfiguration builderConfiguration; |
bmatthias/config-builder | src/test/java/com/tngtech/configbuilder/annotation/valueextractor/EnvironmentVariableProcessorTest.java | // Path: src/main/java/com/tngtech/configbuilder/configuration/BuilderConfiguration.java
// public class BuilderConfiguration {
//
// private Properties properties;
// private CommandLine commandLine;
// private Object importedConfiguration;
// private Class<? extends Annotation>[] annotationOrder = new Class[]{CommandLineValue.class, PropertyValue.class, EnvironmentVariableValue.class, SystemPropertyValue.class, ImportedValue.class, DefaultValue.class};
//
// public BuilderConfiguration() {
// properties = new Properties();
// commandLine = null;
// importedConfiguration = null;
// }
//
// public CommandLine getCommandLine() {
// return commandLine;
// }
//
// public Properties getProperties() {
// return properties;
// }
//
// public Object getImportedConfiguration() {
// return importedConfiguration;
// }
//
// public void setProperties(Properties properties) {
// this.properties = properties;
// }
//
// public void setCommandLine(CommandLine commandLine) {
// this.commandLine = commandLine;
// }
//
// public void setImportedConfiguration(Object importedConfiguration) {
// this.importedConfiguration = importedConfiguration;
// }
//
// public void setAnnotationOrder(Class<? extends Annotation>[] annotationOrder) {
// this.annotationOrder = annotationOrder;
// }
//
// public Class<? extends Annotation>[] getAnnotationOrder() {
// return annotationOrder;
// }
// }
//
// Path: src/main/java/com/tngtech/configbuilder/util/ConfigBuilderFactory.java
// public class ConfigBuilderFactory {
//
// private Map<Class,Object> singletonMap = Maps.newHashMap();
//
// public <T> void initialize() {
//
// //Order is IMPORTANT!
//
// //configuration
// singletonMap.put(ErrorMessageSetup.class, new ErrorMessageSetup());
// singletonMap.put(BuilderConfiguration.class, new BuilderConfiguration());
//
// //util
// singletonMap.put(AnnotationHelper.class, new AnnotationHelper());
// singletonMap.put(GenericsAndCastingHelper.class, new GenericsAndCastingHelper());
// singletonMap.put(FieldValueExtractor.class, new FieldValueExtractor(this));
// singletonMap.put(FieldValueTransformer.class, new FieldValueTransformer(this));
// singletonMap.put(PropertyLoaderConfigurator.class, new PropertyLoaderConfigurator(this));
// singletonMap.put(ConstructionHelper.class, new ConstructionHelper<T>(this));
// singletonMap.put(FieldSetter.class, new FieldSetter<T>(this));
// singletonMap.put(ConfigValidator.class, new ConfigValidator<T>(this));
// singletonMap.put(CommandLineHelper.class, new CommandLineHelper(this));
//
// //AnnotationProcessors
// singletonMap.put(SystemPropertyProcessor.class, new SystemPropertyProcessor());
// singletonMap.put(PropertyValueProcessor.class, new PropertyValueProcessor());
// singletonMap.put(EnvironmentVariableProcessor.class, new EnvironmentVariableProcessor());
// singletonMap.put(CommandLineValueProcessor.class, new CommandLineValueProcessor());
// singletonMap.put(PropertySuffixProcessor.class, new PropertySuffixProcessor());
// singletonMap.put(PropertyLocationsProcessor.class, new PropertyLocationsProcessor());
// singletonMap.put(PropertyExtensionProcessor.class, new PropertyExtensionProcessor());
// singletonMap.put(PropertiesFilesProcessor.class, new PropertiesFilesProcessor());
// singletonMap.put(DefaultValueProcessor.class, new DefaultValueProcessor());
//
// //ValueTransformers
// singletonMap.put(StringOrPrimitiveToPrimitiveTransformer.class, new StringOrPrimitiveToPrimitiveTransformer());
// singletonMap.put(CollectionToArrayListTransformer.class, new CollectionToArrayListTransformer());
// singletonMap.put(CollectionToHashSetTransformer.class, new CollectionToHashSetTransformer());
// singletonMap.put(CharacterSeparatedStringToStringListTransformer.class, new CharacterSeparatedStringToStringListTransformer());
// singletonMap.put(CharacterSeparatedStringToStringSetTransformer.class, new CharacterSeparatedStringToStringSetTransformer());
// singletonMap.put(StringCollectionToCommaSeparatedStringTransformer.class, new StringCollectionToCommaSeparatedStringTransformer());
// singletonMap.put(StringToPathTransformer.class, new StringToPathTransformer());
//
// //other
// singletonMap.put(ValidatorFactory.class, Validation.buildDefaultValidatorFactory());
// }
//
// public <K> K getInstance(Class<K> clazz) {
// if(singletonMap.get(clazz) != null) {
// return (K)singletonMap.get(clazz);
// }
// else {
// return createInstance(clazz);
// }
// }
//
// //TODO: exception message
// public <K> K createInstance(Class<K> clazz) {
// try {
// return clazz.newInstance();
// } catch (IllegalAccessException e) {
// ErrorMessageSetup errorMessageSetup = (ErrorMessageSetup)singletonMap.get(ErrorMessageSetup.class);
// throw new FactoryInstantiationException(errorMessageSetup.getErrorMessage(FactoryInstantiationException.class, clazz.toString()));
// } catch (InstantiationException e) {
// return createInstanceOfInnerClass(clazz);
// }
// }
//
// //TODO: exception message
// private <K> K createInstanceOfInnerClass(Class<K> clazz) {
// Class superClass = clazz.getDeclaringClass();
// try {
// Object superInstance = superClass.newInstance();
// Constructor<K> constructor = clazz.getConstructor(superClass);
// return constructor.newInstance(superInstance);
// } catch (Exception e) {
// ErrorMessageSetup errorMessageSetup = (ErrorMessageSetup)singletonMap.get(ErrorMessageSetup.class);
// throw new FactoryInstantiationException(errorMessageSetup.getErrorMessage(FactoryInstantiationException.class, clazz.toString()));
// }
// }
// }
| import com.tngtech.configbuilder.configuration.BuilderConfiguration;
import com.tngtech.configbuilder.util.ConfigBuilderFactory;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.when; | package com.tngtech.configbuilder.annotation.valueextractor;
@RunWith(MockitoJUnitRunner.class)
public class EnvironmentVariableProcessorTest {
private EnvironmentVariableProcessor environmentVariableProcessor;
@Mock
private EnvironmentVariableValue environmentVariableValue;
@Mock
private BuilderConfiguration builderConfiguration;
@Mock | // Path: src/main/java/com/tngtech/configbuilder/configuration/BuilderConfiguration.java
// public class BuilderConfiguration {
//
// private Properties properties;
// private CommandLine commandLine;
// private Object importedConfiguration;
// private Class<? extends Annotation>[] annotationOrder = new Class[]{CommandLineValue.class, PropertyValue.class, EnvironmentVariableValue.class, SystemPropertyValue.class, ImportedValue.class, DefaultValue.class};
//
// public BuilderConfiguration() {
// properties = new Properties();
// commandLine = null;
// importedConfiguration = null;
// }
//
// public CommandLine getCommandLine() {
// return commandLine;
// }
//
// public Properties getProperties() {
// return properties;
// }
//
// public Object getImportedConfiguration() {
// return importedConfiguration;
// }
//
// public void setProperties(Properties properties) {
// this.properties = properties;
// }
//
// public void setCommandLine(CommandLine commandLine) {
// this.commandLine = commandLine;
// }
//
// public void setImportedConfiguration(Object importedConfiguration) {
// this.importedConfiguration = importedConfiguration;
// }
//
// public void setAnnotationOrder(Class<? extends Annotation>[] annotationOrder) {
// this.annotationOrder = annotationOrder;
// }
//
// public Class<? extends Annotation>[] getAnnotationOrder() {
// return annotationOrder;
// }
// }
//
// Path: src/main/java/com/tngtech/configbuilder/util/ConfigBuilderFactory.java
// public class ConfigBuilderFactory {
//
// private Map<Class,Object> singletonMap = Maps.newHashMap();
//
// public <T> void initialize() {
//
// //Order is IMPORTANT!
//
// //configuration
// singletonMap.put(ErrorMessageSetup.class, new ErrorMessageSetup());
// singletonMap.put(BuilderConfiguration.class, new BuilderConfiguration());
//
// //util
// singletonMap.put(AnnotationHelper.class, new AnnotationHelper());
// singletonMap.put(GenericsAndCastingHelper.class, new GenericsAndCastingHelper());
// singletonMap.put(FieldValueExtractor.class, new FieldValueExtractor(this));
// singletonMap.put(FieldValueTransformer.class, new FieldValueTransformer(this));
// singletonMap.put(PropertyLoaderConfigurator.class, new PropertyLoaderConfigurator(this));
// singletonMap.put(ConstructionHelper.class, new ConstructionHelper<T>(this));
// singletonMap.put(FieldSetter.class, new FieldSetter<T>(this));
// singletonMap.put(ConfigValidator.class, new ConfigValidator<T>(this));
// singletonMap.put(CommandLineHelper.class, new CommandLineHelper(this));
//
// //AnnotationProcessors
// singletonMap.put(SystemPropertyProcessor.class, new SystemPropertyProcessor());
// singletonMap.put(PropertyValueProcessor.class, new PropertyValueProcessor());
// singletonMap.put(EnvironmentVariableProcessor.class, new EnvironmentVariableProcessor());
// singletonMap.put(CommandLineValueProcessor.class, new CommandLineValueProcessor());
// singletonMap.put(PropertySuffixProcessor.class, new PropertySuffixProcessor());
// singletonMap.put(PropertyLocationsProcessor.class, new PropertyLocationsProcessor());
// singletonMap.put(PropertyExtensionProcessor.class, new PropertyExtensionProcessor());
// singletonMap.put(PropertiesFilesProcessor.class, new PropertiesFilesProcessor());
// singletonMap.put(DefaultValueProcessor.class, new DefaultValueProcessor());
//
// //ValueTransformers
// singletonMap.put(StringOrPrimitiveToPrimitiveTransformer.class, new StringOrPrimitiveToPrimitiveTransformer());
// singletonMap.put(CollectionToArrayListTransformer.class, new CollectionToArrayListTransformer());
// singletonMap.put(CollectionToHashSetTransformer.class, new CollectionToHashSetTransformer());
// singletonMap.put(CharacterSeparatedStringToStringListTransformer.class, new CharacterSeparatedStringToStringListTransformer());
// singletonMap.put(CharacterSeparatedStringToStringSetTransformer.class, new CharacterSeparatedStringToStringSetTransformer());
// singletonMap.put(StringCollectionToCommaSeparatedStringTransformer.class, new StringCollectionToCommaSeparatedStringTransformer());
// singletonMap.put(StringToPathTransformer.class, new StringToPathTransformer());
//
// //other
// singletonMap.put(ValidatorFactory.class, Validation.buildDefaultValidatorFactory());
// }
//
// public <K> K getInstance(Class<K> clazz) {
// if(singletonMap.get(clazz) != null) {
// return (K)singletonMap.get(clazz);
// }
// else {
// return createInstance(clazz);
// }
// }
//
// //TODO: exception message
// public <K> K createInstance(Class<K> clazz) {
// try {
// return clazz.newInstance();
// } catch (IllegalAccessException e) {
// ErrorMessageSetup errorMessageSetup = (ErrorMessageSetup)singletonMap.get(ErrorMessageSetup.class);
// throw new FactoryInstantiationException(errorMessageSetup.getErrorMessage(FactoryInstantiationException.class, clazz.toString()));
// } catch (InstantiationException e) {
// return createInstanceOfInnerClass(clazz);
// }
// }
//
// //TODO: exception message
// private <K> K createInstanceOfInnerClass(Class<K> clazz) {
// Class superClass = clazz.getDeclaringClass();
// try {
// Object superInstance = superClass.newInstance();
// Constructor<K> constructor = clazz.getConstructor(superClass);
// return constructor.newInstance(superInstance);
// } catch (Exception e) {
// ErrorMessageSetup errorMessageSetup = (ErrorMessageSetup)singletonMap.get(ErrorMessageSetup.class);
// throw new FactoryInstantiationException(errorMessageSetup.getErrorMessage(FactoryInstantiationException.class, clazz.toString()));
// }
// }
// }
// Path: src/test/java/com/tngtech/configbuilder/annotation/valueextractor/EnvironmentVariableProcessorTest.java
import com.tngtech.configbuilder.configuration.BuilderConfiguration;
import com.tngtech.configbuilder.util.ConfigBuilderFactory;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.when;
package com.tngtech.configbuilder.annotation.valueextractor;
@RunWith(MockitoJUnitRunner.class)
public class EnvironmentVariableProcessorTest {
private EnvironmentVariableProcessor environmentVariableProcessor;
@Mock
private EnvironmentVariableValue environmentVariableValue;
@Mock
private BuilderConfiguration builderConfiguration;
@Mock | private ConfigBuilderFactory configBuilderFactory; |
bmatthias/config-builder | src/test/java/com/tngtech/configbuilder/ConfigBuilderExceptionTest.java | // Path: src/main/java/com/tngtech/configbuilder/exception/ConfigBuilderException.java
// public class ConfigBuilderException extends RuntimeException {
//
// public ConfigBuilderException(String message, Throwable e) {
// super(message, e);
// }
// }
//
// Path: src/main/java/com/tngtech/configbuilder/exception/NoConstructorFoundException.java
// public class NoConstructorFoundException extends RuntimeException {
// public NoConstructorFoundException(String message) {
// super(message);
// }
// }
//
// Path: src/main/java/com/tngtech/configbuilder/exception/PrimitiveParsingException.java
// public class PrimitiveParsingException extends RuntimeException {
// public PrimitiveParsingException(String errorMessage) {
// super(errorMessage);
// }
// }
//
// Path: src/test/java/com/tngtech/configbuilder/testclasses/TestConfigThrowsIllegalArgumentException.java
// public class TestConfigThrowsIllegalArgumentException {
//
// @DefaultValue("stringValue")
// private Field integer;
// }
//
// Path: src/test/java/com/tngtech/configbuilder/testclasses/TestConfigThrowsPrimitiveParsingException.java
// public class TestConfigThrowsPrimitiveParsingException {
//
// @DefaultValue("stringValue")
// private int integer;
// }
//
// Path: src/test/java/com/tngtech/configbuilder/testclasses/TestConfigThrowsInvocationTargetExceptionException.java
// @PropertyExtension("testproperties")
// @PropertySuffixes(extraSuffixes = {"test"})
// @PropertyLocations(resourcesForClasses = {PropertyLoader.class})
// @PropertiesFiles("demoapp-configuration")
// @LoadingOrder(value = {CommandLineValue.class, PropertyValue.class, DefaultValue.class})
// public class TestConfigThrowsInvocationTargetExceptionException {
//
// private int number;
//
// private TestConfigThrowsInvocationTargetExceptionException() {
// throw new RuntimeException();
// }
// }
//
// Path: src/test/java/com/tngtech/configbuilder/testclasses/TestConfigWithoutDefaultConstructor.java
// @PropertyExtension("testproperties")
// @PropertySuffixes(extraSuffixes = {"test"})
// @PropertyLocations(resourcesForClasses = {PropertyLoader.class})
// @PropertiesFiles("demoapp-configuration")
// @LoadingOrder(value = {CommandLineValue.class, PropertyValue.class, DefaultValue.class})
// public class TestConfigWithoutDefaultConstructor {
//
// private int number;
//
// public TestConfigWithoutDefaultConstructor(Integer i) {
// this.number = i;
// }
//
//
// public int getNumber() {
// return number;
// }
// }
| import com.tngtech.configbuilder.exception.ConfigBuilderException;
import com.tngtech.configbuilder.exception.NoConstructorFoundException;
import com.tngtech.configbuilder.exception.PrimitiveParsingException;
import com.tngtech.configbuilder.testclasses.TestConfigThrowsIllegalArgumentException;
import com.tngtech.configbuilder.testclasses.TestConfigThrowsPrimitiveParsingException;
import com.tngtech.configbuilder.testclasses.TestConfigThrowsInvocationTargetExceptionException;
import com.tngtech.configbuilder.testclasses.TestConfigWithoutDefaultConstructor;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import java.util.Arrays;
import java.util.Collection; | package com.tngtech.configbuilder;
@RunWith(Parameterized.class)
public class ConfigBuilderExceptionTest {
private Class configClass;
private Class<? extends Throwable> exceptionClass;
private String message;
@Rule
public ExpectedException expectedException = ExpectedException.none();
@Before
public void setUp() {
}
@Parameterized.Parameters
public static Collection configs() {
return Arrays.asList(new Object[][]{ | // Path: src/main/java/com/tngtech/configbuilder/exception/ConfigBuilderException.java
// public class ConfigBuilderException extends RuntimeException {
//
// public ConfigBuilderException(String message, Throwable e) {
// super(message, e);
// }
// }
//
// Path: src/main/java/com/tngtech/configbuilder/exception/NoConstructorFoundException.java
// public class NoConstructorFoundException extends RuntimeException {
// public NoConstructorFoundException(String message) {
// super(message);
// }
// }
//
// Path: src/main/java/com/tngtech/configbuilder/exception/PrimitiveParsingException.java
// public class PrimitiveParsingException extends RuntimeException {
// public PrimitiveParsingException(String errorMessage) {
// super(errorMessage);
// }
// }
//
// Path: src/test/java/com/tngtech/configbuilder/testclasses/TestConfigThrowsIllegalArgumentException.java
// public class TestConfigThrowsIllegalArgumentException {
//
// @DefaultValue("stringValue")
// private Field integer;
// }
//
// Path: src/test/java/com/tngtech/configbuilder/testclasses/TestConfigThrowsPrimitiveParsingException.java
// public class TestConfigThrowsPrimitiveParsingException {
//
// @DefaultValue("stringValue")
// private int integer;
// }
//
// Path: src/test/java/com/tngtech/configbuilder/testclasses/TestConfigThrowsInvocationTargetExceptionException.java
// @PropertyExtension("testproperties")
// @PropertySuffixes(extraSuffixes = {"test"})
// @PropertyLocations(resourcesForClasses = {PropertyLoader.class})
// @PropertiesFiles("demoapp-configuration")
// @LoadingOrder(value = {CommandLineValue.class, PropertyValue.class, DefaultValue.class})
// public class TestConfigThrowsInvocationTargetExceptionException {
//
// private int number;
//
// private TestConfigThrowsInvocationTargetExceptionException() {
// throw new RuntimeException();
// }
// }
//
// Path: src/test/java/com/tngtech/configbuilder/testclasses/TestConfigWithoutDefaultConstructor.java
// @PropertyExtension("testproperties")
// @PropertySuffixes(extraSuffixes = {"test"})
// @PropertyLocations(resourcesForClasses = {PropertyLoader.class})
// @PropertiesFiles("demoapp-configuration")
// @LoadingOrder(value = {CommandLineValue.class, PropertyValue.class, DefaultValue.class})
// public class TestConfigWithoutDefaultConstructor {
//
// private int number;
//
// public TestConfigWithoutDefaultConstructor(Integer i) {
// this.number = i;
// }
//
//
// public int getNumber() {
// return number;
// }
// }
// Path: src/test/java/com/tngtech/configbuilder/ConfigBuilderExceptionTest.java
import com.tngtech.configbuilder.exception.ConfigBuilderException;
import com.tngtech.configbuilder.exception.NoConstructorFoundException;
import com.tngtech.configbuilder.exception.PrimitiveParsingException;
import com.tngtech.configbuilder.testclasses.TestConfigThrowsIllegalArgumentException;
import com.tngtech.configbuilder.testclasses.TestConfigThrowsPrimitiveParsingException;
import com.tngtech.configbuilder.testclasses.TestConfigThrowsInvocationTargetExceptionException;
import com.tngtech.configbuilder.testclasses.TestConfigWithoutDefaultConstructor;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import java.util.Arrays;
import java.util.Collection;
package com.tngtech.configbuilder;
@RunWith(Parameterized.class)
public class ConfigBuilderExceptionTest {
private Class configClass;
private Class<? extends Throwable> exceptionClass;
private String message;
@Rule
public ExpectedException expectedException = ExpectedException.none();
@Before
public void setUp() {
}
@Parameterized.Parameters
public static Collection configs() {
return Arrays.asList(new Object[][]{ | {TestConfigWithoutDefaultConstructor.class, NoConstructorFoundException.class, "build()"}, |
bmatthias/config-builder | src/test/java/com/tngtech/configbuilder/ConfigBuilderExceptionTest.java | // Path: src/main/java/com/tngtech/configbuilder/exception/ConfigBuilderException.java
// public class ConfigBuilderException extends RuntimeException {
//
// public ConfigBuilderException(String message, Throwable e) {
// super(message, e);
// }
// }
//
// Path: src/main/java/com/tngtech/configbuilder/exception/NoConstructorFoundException.java
// public class NoConstructorFoundException extends RuntimeException {
// public NoConstructorFoundException(String message) {
// super(message);
// }
// }
//
// Path: src/main/java/com/tngtech/configbuilder/exception/PrimitiveParsingException.java
// public class PrimitiveParsingException extends RuntimeException {
// public PrimitiveParsingException(String errorMessage) {
// super(errorMessage);
// }
// }
//
// Path: src/test/java/com/tngtech/configbuilder/testclasses/TestConfigThrowsIllegalArgumentException.java
// public class TestConfigThrowsIllegalArgumentException {
//
// @DefaultValue("stringValue")
// private Field integer;
// }
//
// Path: src/test/java/com/tngtech/configbuilder/testclasses/TestConfigThrowsPrimitiveParsingException.java
// public class TestConfigThrowsPrimitiveParsingException {
//
// @DefaultValue("stringValue")
// private int integer;
// }
//
// Path: src/test/java/com/tngtech/configbuilder/testclasses/TestConfigThrowsInvocationTargetExceptionException.java
// @PropertyExtension("testproperties")
// @PropertySuffixes(extraSuffixes = {"test"})
// @PropertyLocations(resourcesForClasses = {PropertyLoader.class})
// @PropertiesFiles("demoapp-configuration")
// @LoadingOrder(value = {CommandLineValue.class, PropertyValue.class, DefaultValue.class})
// public class TestConfigThrowsInvocationTargetExceptionException {
//
// private int number;
//
// private TestConfigThrowsInvocationTargetExceptionException() {
// throw new RuntimeException();
// }
// }
//
// Path: src/test/java/com/tngtech/configbuilder/testclasses/TestConfigWithoutDefaultConstructor.java
// @PropertyExtension("testproperties")
// @PropertySuffixes(extraSuffixes = {"test"})
// @PropertyLocations(resourcesForClasses = {PropertyLoader.class})
// @PropertiesFiles("demoapp-configuration")
// @LoadingOrder(value = {CommandLineValue.class, PropertyValue.class, DefaultValue.class})
// public class TestConfigWithoutDefaultConstructor {
//
// private int number;
//
// public TestConfigWithoutDefaultConstructor(Integer i) {
// this.number = i;
// }
//
//
// public int getNumber() {
// return number;
// }
// }
| import com.tngtech.configbuilder.exception.ConfigBuilderException;
import com.tngtech.configbuilder.exception.NoConstructorFoundException;
import com.tngtech.configbuilder.exception.PrimitiveParsingException;
import com.tngtech.configbuilder.testclasses.TestConfigThrowsIllegalArgumentException;
import com.tngtech.configbuilder.testclasses.TestConfigThrowsPrimitiveParsingException;
import com.tngtech.configbuilder.testclasses.TestConfigThrowsInvocationTargetExceptionException;
import com.tngtech.configbuilder.testclasses.TestConfigWithoutDefaultConstructor;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import java.util.Arrays;
import java.util.Collection; | package com.tngtech.configbuilder;
@RunWith(Parameterized.class)
public class ConfigBuilderExceptionTest {
private Class configClass;
private Class<? extends Throwable> exceptionClass;
private String message;
@Rule
public ExpectedException expectedException = ExpectedException.none();
@Before
public void setUp() {
}
@Parameterized.Parameters
public static Collection configs() {
return Arrays.asList(new Object[][]{ | // Path: src/main/java/com/tngtech/configbuilder/exception/ConfigBuilderException.java
// public class ConfigBuilderException extends RuntimeException {
//
// public ConfigBuilderException(String message, Throwable e) {
// super(message, e);
// }
// }
//
// Path: src/main/java/com/tngtech/configbuilder/exception/NoConstructorFoundException.java
// public class NoConstructorFoundException extends RuntimeException {
// public NoConstructorFoundException(String message) {
// super(message);
// }
// }
//
// Path: src/main/java/com/tngtech/configbuilder/exception/PrimitiveParsingException.java
// public class PrimitiveParsingException extends RuntimeException {
// public PrimitiveParsingException(String errorMessage) {
// super(errorMessage);
// }
// }
//
// Path: src/test/java/com/tngtech/configbuilder/testclasses/TestConfigThrowsIllegalArgumentException.java
// public class TestConfigThrowsIllegalArgumentException {
//
// @DefaultValue("stringValue")
// private Field integer;
// }
//
// Path: src/test/java/com/tngtech/configbuilder/testclasses/TestConfigThrowsPrimitiveParsingException.java
// public class TestConfigThrowsPrimitiveParsingException {
//
// @DefaultValue("stringValue")
// private int integer;
// }
//
// Path: src/test/java/com/tngtech/configbuilder/testclasses/TestConfigThrowsInvocationTargetExceptionException.java
// @PropertyExtension("testproperties")
// @PropertySuffixes(extraSuffixes = {"test"})
// @PropertyLocations(resourcesForClasses = {PropertyLoader.class})
// @PropertiesFiles("demoapp-configuration")
// @LoadingOrder(value = {CommandLineValue.class, PropertyValue.class, DefaultValue.class})
// public class TestConfigThrowsInvocationTargetExceptionException {
//
// private int number;
//
// private TestConfigThrowsInvocationTargetExceptionException() {
// throw new RuntimeException();
// }
// }
//
// Path: src/test/java/com/tngtech/configbuilder/testclasses/TestConfigWithoutDefaultConstructor.java
// @PropertyExtension("testproperties")
// @PropertySuffixes(extraSuffixes = {"test"})
// @PropertyLocations(resourcesForClasses = {PropertyLoader.class})
// @PropertiesFiles("demoapp-configuration")
// @LoadingOrder(value = {CommandLineValue.class, PropertyValue.class, DefaultValue.class})
// public class TestConfigWithoutDefaultConstructor {
//
// private int number;
//
// public TestConfigWithoutDefaultConstructor(Integer i) {
// this.number = i;
// }
//
//
// public int getNumber() {
// return number;
// }
// }
// Path: src/test/java/com/tngtech/configbuilder/ConfigBuilderExceptionTest.java
import com.tngtech.configbuilder.exception.ConfigBuilderException;
import com.tngtech.configbuilder.exception.NoConstructorFoundException;
import com.tngtech.configbuilder.exception.PrimitiveParsingException;
import com.tngtech.configbuilder.testclasses.TestConfigThrowsIllegalArgumentException;
import com.tngtech.configbuilder.testclasses.TestConfigThrowsPrimitiveParsingException;
import com.tngtech.configbuilder.testclasses.TestConfigThrowsInvocationTargetExceptionException;
import com.tngtech.configbuilder.testclasses.TestConfigWithoutDefaultConstructor;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import java.util.Arrays;
import java.util.Collection;
package com.tngtech.configbuilder;
@RunWith(Parameterized.class)
public class ConfigBuilderExceptionTest {
private Class configClass;
private Class<? extends Throwable> exceptionClass;
private String message;
@Rule
public ExpectedException expectedException = ExpectedException.none();
@Before
public void setUp() {
}
@Parameterized.Parameters
public static Collection configs() {
return Arrays.asList(new Object[][]{ | {TestConfigWithoutDefaultConstructor.class, NoConstructorFoundException.class, "build()"}, |
bmatthias/config-builder | src/test/java/com/tngtech/configbuilder/ConfigBuilderExceptionTest.java | // Path: src/main/java/com/tngtech/configbuilder/exception/ConfigBuilderException.java
// public class ConfigBuilderException extends RuntimeException {
//
// public ConfigBuilderException(String message, Throwable e) {
// super(message, e);
// }
// }
//
// Path: src/main/java/com/tngtech/configbuilder/exception/NoConstructorFoundException.java
// public class NoConstructorFoundException extends RuntimeException {
// public NoConstructorFoundException(String message) {
// super(message);
// }
// }
//
// Path: src/main/java/com/tngtech/configbuilder/exception/PrimitiveParsingException.java
// public class PrimitiveParsingException extends RuntimeException {
// public PrimitiveParsingException(String errorMessage) {
// super(errorMessage);
// }
// }
//
// Path: src/test/java/com/tngtech/configbuilder/testclasses/TestConfigThrowsIllegalArgumentException.java
// public class TestConfigThrowsIllegalArgumentException {
//
// @DefaultValue("stringValue")
// private Field integer;
// }
//
// Path: src/test/java/com/tngtech/configbuilder/testclasses/TestConfigThrowsPrimitiveParsingException.java
// public class TestConfigThrowsPrimitiveParsingException {
//
// @DefaultValue("stringValue")
// private int integer;
// }
//
// Path: src/test/java/com/tngtech/configbuilder/testclasses/TestConfigThrowsInvocationTargetExceptionException.java
// @PropertyExtension("testproperties")
// @PropertySuffixes(extraSuffixes = {"test"})
// @PropertyLocations(resourcesForClasses = {PropertyLoader.class})
// @PropertiesFiles("demoapp-configuration")
// @LoadingOrder(value = {CommandLineValue.class, PropertyValue.class, DefaultValue.class})
// public class TestConfigThrowsInvocationTargetExceptionException {
//
// private int number;
//
// private TestConfigThrowsInvocationTargetExceptionException() {
// throw new RuntimeException();
// }
// }
//
// Path: src/test/java/com/tngtech/configbuilder/testclasses/TestConfigWithoutDefaultConstructor.java
// @PropertyExtension("testproperties")
// @PropertySuffixes(extraSuffixes = {"test"})
// @PropertyLocations(resourcesForClasses = {PropertyLoader.class})
// @PropertiesFiles("demoapp-configuration")
// @LoadingOrder(value = {CommandLineValue.class, PropertyValue.class, DefaultValue.class})
// public class TestConfigWithoutDefaultConstructor {
//
// private int number;
//
// public TestConfigWithoutDefaultConstructor(Integer i) {
// this.number = i;
// }
//
//
// public int getNumber() {
// return number;
// }
// }
| import com.tngtech.configbuilder.exception.ConfigBuilderException;
import com.tngtech.configbuilder.exception.NoConstructorFoundException;
import com.tngtech.configbuilder.exception.PrimitiveParsingException;
import com.tngtech.configbuilder.testclasses.TestConfigThrowsIllegalArgumentException;
import com.tngtech.configbuilder.testclasses.TestConfigThrowsPrimitiveParsingException;
import com.tngtech.configbuilder.testclasses.TestConfigThrowsInvocationTargetExceptionException;
import com.tngtech.configbuilder.testclasses.TestConfigWithoutDefaultConstructor;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import java.util.Arrays;
import java.util.Collection; | package com.tngtech.configbuilder;
@RunWith(Parameterized.class)
public class ConfigBuilderExceptionTest {
private Class configClass;
private Class<? extends Throwable> exceptionClass;
private String message;
@Rule
public ExpectedException expectedException = ExpectedException.none();
@Before
public void setUp() {
}
@Parameterized.Parameters
public static Collection configs() {
return Arrays.asList(new Object[][]{
{TestConfigWithoutDefaultConstructor.class, NoConstructorFoundException.class, "build()"}, | // Path: src/main/java/com/tngtech/configbuilder/exception/ConfigBuilderException.java
// public class ConfigBuilderException extends RuntimeException {
//
// public ConfigBuilderException(String message, Throwable e) {
// super(message, e);
// }
// }
//
// Path: src/main/java/com/tngtech/configbuilder/exception/NoConstructorFoundException.java
// public class NoConstructorFoundException extends RuntimeException {
// public NoConstructorFoundException(String message) {
// super(message);
// }
// }
//
// Path: src/main/java/com/tngtech/configbuilder/exception/PrimitiveParsingException.java
// public class PrimitiveParsingException extends RuntimeException {
// public PrimitiveParsingException(String errorMessage) {
// super(errorMessage);
// }
// }
//
// Path: src/test/java/com/tngtech/configbuilder/testclasses/TestConfigThrowsIllegalArgumentException.java
// public class TestConfigThrowsIllegalArgumentException {
//
// @DefaultValue("stringValue")
// private Field integer;
// }
//
// Path: src/test/java/com/tngtech/configbuilder/testclasses/TestConfigThrowsPrimitiveParsingException.java
// public class TestConfigThrowsPrimitiveParsingException {
//
// @DefaultValue("stringValue")
// private int integer;
// }
//
// Path: src/test/java/com/tngtech/configbuilder/testclasses/TestConfigThrowsInvocationTargetExceptionException.java
// @PropertyExtension("testproperties")
// @PropertySuffixes(extraSuffixes = {"test"})
// @PropertyLocations(resourcesForClasses = {PropertyLoader.class})
// @PropertiesFiles("demoapp-configuration")
// @LoadingOrder(value = {CommandLineValue.class, PropertyValue.class, DefaultValue.class})
// public class TestConfigThrowsInvocationTargetExceptionException {
//
// private int number;
//
// private TestConfigThrowsInvocationTargetExceptionException() {
// throw new RuntimeException();
// }
// }
//
// Path: src/test/java/com/tngtech/configbuilder/testclasses/TestConfigWithoutDefaultConstructor.java
// @PropertyExtension("testproperties")
// @PropertySuffixes(extraSuffixes = {"test"})
// @PropertyLocations(resourcesForClasses = {PropertyLoader.class})
// @PropertiesFiles("demoapp-configuration")
// @LoadingOrder(value = {CommandLineValue.class, PropertyValue.class, DefaultValue.class})
// public class TestConfigWithoutDefaultConstructor {
//
// private int number;
//
// public TestConfigWithoutDefaultConstructor(Integer i) {
// this.number = i;
// }
//
//
// public int getNumber() {
// return number;
// }
// }
// Path: src/test/java/com/tngtech/configbuilder/ConfigBuilderExceptionTest.java
import com.tngtech.configbuilder.exception.ConfigBuilderException;
import com.tngtech.configbuilder.exception.NoConstructorFoundException;
import com.tngtech.configbuilder.exception.PrimitiveParsingException;
import com.tngtech.configbuilder.testclasses.TestConfigThrowsIllegalArgumentException;
import com.tngtech.configbuilder.testclasses.TestConfigThrowsPrimitiveParsingException;
import com.tngtech.configbuilder.testclasses.TestConfigThrowsInvocationTargetExceptionException;
import com.tngtech.configbuilder.testclasses.TestConfigWithoutDefaultConstructor;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import java.util.Arrays;
import java.util.Collection;
package com.tngtech.configbuilder;
@RunWith(Parameterized.class)
public class ConfigBuilderExceptionTest {
private Class configClass;
private Class<? extends Throwable> exceptionClass;
private String message;
@Rule
public ExpectedException expectedException = ExpectedException.none();
@Before
public void setUp() {
}
@Parameterized.Parameters
public static Collection configs() {
return Arrays.asList(new Object[][]{
{TestConfigWithoutDefaultConstructor.class, NoConstructorFoundException.class, "build()"}, | {TestConfigThrowsInvocationTargetExceptionException.class, ConfigBuilderException.class, "InvocationTargetException"}, |
bmatthias/config-builder | src/test/java/com/tngtech/configbuilder/ConfigBuilderExceptionTest.java | // Path: src/main/java/com/tngtech/configbuilder/exception/ConfigBuilderException.java
// public class ConfigBuilderException extends RuntimeException {
//
// public ConfigBuilderException(String message, Throwable e) {
// super(message, e);
// }
// }
//
// Path: src/main/java/com/tngtech/configbuilder/exception/NoConstructorFoundException.java
// public class NoConstructorFoundException extends RuntimeException {
// public NoConstructorFoundException(String message) {
// super(message);
// }
// }
//
// Path: src/main/java/com/tngtech/configbuilder/exception/PrimitiveParsingException.java
// public class PrimitiveParsingException extends RuntimeException {
// public PrimitiveParsingException(String errorMessage) {
// super(errorMessage);
// }
// }
//
// Path: src/test/java/com/tngtech/configbuilder/testclasses/TestConfigThrowsIllegalArgumentException.java
// public class TestConfigThrowsIllegalArgumentException {
//
// @DefaultValue("stringValue")
// private Field integer;
// }
//
// Path: src/test/java/com/tngtech/configbuilder/testclasses/TestConfigThrowsPrimitiveParsingException.java
// public class TestConfigThrowsPrimitiveParsingException {
//
// @DefaultValue("stringValue")
// private int integer;
// }
//
// Path: src/test/java/com/tngtech/configbuilder/testclasses/TestConfigThrowsInvocationTargetExceptionException.java
// @PropertyExtension("testproperties")
// @PropertySuffixes(extraSuffixes = {"test"})
// @PropertyLocations(resourcesForClasses = {PropertyLoader.class})
// @PropertiesFiles("demoapp-configuration")
// @LoadingOrder(value = {CommandLineValue.class, PropertyValue.class, DefaultValue.class})
// public class TestConfigThrowsInvocationTargetExceptionException {
//
// private int number;
//
// private TestConfigThrowsInvocationTargetExceptionException() {
// throw new RuntimeException();
// }
// }
//
// Path: src/test/java/com/tngtech/configbuilder/testclasses/TestConfigWithoutDefaultConstructor.java
// @PropertyExtension("testproperties")
// @PropertySuffixes(extraSuffixes = {"test"})
// @PropertyLocations(resourcesForClasses = {PropertyLoader.class})
// @PropertiesFiles("demoapp-configuration")
// @LoadingOrder(value = {CommandLineValue.class, PropertyValue.class, DefaultValue.class})
// public class TestConfigWithoutDefaultConstructor {
//
// private int number;
//
// public TestConfigWithoutDefaultConstructor(Integer i) {
// this.number = i;
// }
//
//
// public int getNumber() {
// return number;
// }
// }
| import com.tngtech.configbuilder.exception.ConfigBuilderException;
import com.tngtech.configbuilder.exception.NoConstructorFoundException;
import com.tngtech.configbuilder.exception.PrimitiveParsingException;
import com.tngtech.configbuilder.testclasses.TestConfigThrowsIllegalArgumentException;
import com.tngtech.configbuilder.testclasses.TestConfigThrowsPrimitiveParsingException;
import com.tngtech.configbuilder.testclasses.TestConfigThrowsInvocationTargetExceptionException;
import com.tngtech.configbuilder.testclasses.TestConfigWithoutDefaultConstructor;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import java.util.Arrays;
import java.util.Collection; | package com.tngtech.configbuilder;
@RunWith(Parameterized.class)
public class ConfigBuilderExceptionTest {
private Class configClass;
private Class<? extends Throwable> exceptionClass;
private String message;
@Rule
public ExpectedException expectedException = ExpectedException.none();
@Before
public void setUp() {
}
@Parameterized.Parameters
public static Collection configs() {
return Arrays.asList(new Object[][]{
{TestConfigWithoutDefaultConstructor.class, NoConstructorFoundException.class, "build()"}, | // Path: src/main/java/com/tngtech/configbuilder/exception/ConfigBuilderException.java
// public class ConfigBuilderException extends RuntimeException {
//
// public ConfigBuilderException(String message, Throwable e) {
// super(message, e);
// }
// }
//
// Path: src/main/java/com/tngtech/configbuilder/exception/NoConstructorFoundException.java
// public class NoConstructorFoundException extends RuntimeException {
// public NoConstructorFoundException(String message) {
// super(message);
// }
// }
//
// Path: src/main/java/com/tngtech/configbuilder/exception/PrimitiveParsingException.java
// public class PrimitiveParsingException extends RuntimeException {
// public PrimitiveParsingException(String errorMessage) {
// super(errorMessage);
// }
// }
//
// Path: src/test/java/com/tngtech/configbuilder/testclasses/TestConfigThrowsIllegalArgumentException.java
// public class TestConfigThrowsIllegalArgumentException {
//
// @DefaultValue("stringValue")
// private Field integer;
// }
//
// Path: src/test/java/com/tngtech/configbuilder/testclasses/TestConfigThrowsPrimitiveParsingException.java
// public class TestConfigThrowsPrimitiveParsingException {
//
// @DefaultValue("stringValue")
// private int integer;
// }
//
// Path: src/test/java/com/tngtech/configbuilder/testclasses/TestConfigThrowsInvocationTargetExceptionException.java
// @PropertyExtension("testproperties")
// @PropertySuffixes(extraSuffixes = {"test"})
// @PropertyLocations(resourcesForClasses = {PropertyLoader.class})
// @PropertiesFiles("demoapp-configuration")
// @LoadingOrder(value = {CommandLineValue.class, PropertyValue.class, DefaultValue.class})
// public class TestConfigThrowsInvocationTargetExceptionException {
//
// private int number;
//
// private TestConfigThrowsInvocationTargetExceptionException() {
// throw new RuntimeException();
// }
// }
//
// Path: src/test/java/com/tngtech/configbuilder/testclasses/TestConfigWithoutDefaultConstructor.java
// @PropertyExtension("testproperties")
// @PropertySuffixes(extraSuffixes = {"test"})
// @PropertyLocations(resourcesForClasses = {PropertyLoader.class})
// @PropertiesFiles("demoapp-configuration")
// @LoadingOrder(value = {CommandLineValue.class, PropertyValue.class, DefaultValue.class})
// public class TestConfigWithoutDefaultConstructor {
//
// private int number;
//
// public TestConfigWithoutDefaultConstructor(Integer i) {
// this.number = i;
// }
//
//
// public int getNumber() {
// return number;
// }
// }
// Path: src/test/java/com/tngtech/configbuilder/ConfigBuilderExceptionTest.java
import com.tngtech.configbuilder.exception.ConfigBuilderException;
import com.tngtech.configbuilder.exception.NoConstructorFoundException;
import com.tngtech.configbuilder.exception.PrimitiveParsingException;
import com.tngtech.configbuilder.testclasses.TestConfigThrowsIllegalArgumentException;
import com.tngtech.configbuilder.testclasses.TestConfigThrowsPrimitiveParsingException;
import com.tngtech.configbuilder.testclasses.TestConfigThrowsInvocationTargetExceptionException;
import com.tngtech.configbuilder.testclasses.TestConfigWithoutDefaultConstructor;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import java.util.Arrays;
import java.util.Collection;
package com.tngtech.configbuilder;
@RunWith(Parameterized.class)
public class ConfigBuilderExceptionTest {
private Class configClass;
private Class<? extends Throwable> exceptionClass;
private String message;
@Rule
public ExpectedException expectedException = ExpectedException.none();
@Before
public void setUp() {
}
@Parameterized.Parameters
public static Collection configs() {
return Arrays.asList(new Object[][]{
{TestConfigWithoutDefaultConstructor.class, NoConstructorFoundException.class, "build()"}, | {TestConfigThrowsInvocationTargetExceptionException.class, ConfigBuilderException.class, "InvocationTargetException"}, |
bmatthias/config-builder | src/test/java/com/tngtech/configbuilder/ConfigBuilderExceptionTest.java | // Path: src/main/java/com/tngtech/configbuilder/exception/ConfigBuilderException.java
// public class ConfigBuilderException extends RuntimeException {
//
// public ConfigBuilderException(String message, Throwable e) {
// super(message, e);
// }
// }
//
// Path: src/main/java/com/tngtech/configbuilder/exception/NoConstructorFoundException.java
// public class NoConstructorFoundException extends RuntimeException {
// public NoConstructorFoundException(String message) {
// super(message);
// }
// }
//
// Path: src/main/java/com/tngtech/configbuilder/exception/PrimitiveParsingException.java
// public class PrimitiveParsingException extends RuntimeException {
// public PrimitiveParsingException(String errorMessage) {
// super(errorMessage);
// }
// }
//
// Path: src/test/java/com/tngtech/configbuilder/testclasses/TestConfigThrowsIllegalArgumentException.java
// public class TestConfigThrowsIllegalArgumentException {
//
// @DefaultValue("stringValue")
// private Field integer;
// }
//
// Path: src/test/java/com/tngtech/configbuilder/testclasses/TestConfigThrowsPrimitiveParsingException.java
// public class TestConfigThrowsPrimitiveParsingException {
//
// @DefaultValue("stringValue")
// private int integer;
// }
//
// Path: src/test/java/com/tngtech/configbuilder/testclasses/TestConfigThrowsInvocationTargetExceptionException.java
// @PropertyExtension("testproperties")
// @PropertySuffixes(extraSuffixes = {"test"})
// @PropertyLocations(resourcesForClasses = {PropertyLoader.class})
// @PropertiesFiles("demoapp-configuration")
// @LoadingOrder(value = {CommandLineValue.class, PropertyValue.class, DefaultValue.class})
// public class TestConfigThrowsInvocationTargetExceptionException {
//
// private int number;
//
// private TestConfigThrowsInvocationTargetExceptionException() {
// throw new RuntimeException();
// }
// }
//
// Path: src/test/java/com/tngtech/configbuilder/testclasses/TestConfigWithoutDefaultConstructor.java
// @PropertyExtension("testproperties")
// @PropertySuffixes(extraSuffixes = {"test"})
// @PropertyLocations(resourcesForClasses = {PropertyLoader.class})
// @PropertiesFiles("demoapp-configuration")
// @LoadingOrder(value = {CommandLineValue.class, PropertyValue.class, DefaultValue.class})
// public class TestConfigWithoutDefaultConstructor {
//
// private int number;
//
// public TestConfigWithoutDefaultConstructor(Integer i) {
// this.number = i;
// }
//
//
// public int getNumber() {
// return number;
// }
// }
| import com.tngtech.configbuilder.exception.ConfigBuilderException;
import com.tngtech.configbuilder.exception.NoConstructorFoundException;
import com.tngtech.configbuilder.exception.PrimitiveParsingException;
import com.tngtech.configbuilder.testclasses.TestConfigThrowsIllegalArgumentException;
import com.tngtech.configbuilder.testclasses.TestConfigThrowsPrimitiveParsingException;
import com.tngtech.configbuilder.testclasses.TestConfigThrowsInvocationTargetExceptionException;
import com.tngtech.configbuilder.testclasses.TestConfigWithoutDefaultConstructor;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import java.util.Arrays;
import java.util.Collection; | package com.tngtech.configbuilder;
@RunWith(Parameterized.class)
public class ConfigBuilderExceptionTest {
private Class configClass;
private Class<? extends Throwable> exceptionClass;
private String message;
@Rule
public ExpectedException expectedException = ExpectedException.none();
@Before
public void setUp() {
}
@Parameterized.Parameters
public static Collection configs() {
return Arrays.asList(new Object[][]{
{TestConfigWithoutDefaultConstructor.class, NoConstructorFoundException.class, "build()"},
{TestConfigThrowsInvocationTargetExceptionException.class, ConfigBuilderException.class, "InvocationTargetException"}, | // Path: src/main/java/com/tngtech/configbuilder/exception/ConfigBuilderException.java
// public class ConfigBuilderException extends RuntimeException {
//
// public ConfigBuilderException(String message, Throwable e) {
// super(message, e);
// }
// }
//
// Path: src/main/java/com/tngtech/configbuilder/exception/NoConstructorFoundException.java
// public class NoConstructorFoundException extends RuntimeException {
// public NoConstructorFoundException(String message) {
// super(message);
// }
// }
//
// Path: src/main/java/com/tngtech/configbuilder/exception/PrimitiveParsingException.java
// public class PrimitiveParsingException extends RuntimeException {
// public PrimitiveParsingException(String errorMessage) {
// super(errorMessage);
// }
// }
//
// Path: src/test/java/com/tngtech/configbuilder/testclasses/TestConfigThrowsIllegalArgumentException.java
// public class TestConfigThrowsIllegalArgumentException {
//
// @DefaultValue("stringValue")
// private Field integer;
// }
//
// Path: src/test/java/com/tngtech/configbuilder/testclasses/TestConfigThrowsPrimitiveParsingException.java
// public class TestConfigThrowsPrimitiveParsingException {
//
// @DefaultValue("stringValue")
// private int integer;
// }
//
// Path: src/test/java/com/tngtech/configbuilder/testclasses/TestConfigThrowsInvocationTargetExceptionException.java
// @PropertyExtension("testproperties")
// @PropertySuffixes(extraSuffixes = {"test"})
// @PropertyLocations(resourcesForClasses = {PropertyLoader.class})
// @PropertiesFiles("demoapp-configuration")
// @LoadingOrder(value = {CommandLineValue.class, PropertyValue.class, DefaultValue.class})
// public class TestConfigThrowsInvocationTargetExceptionException {
//
// private int number;
//
// private TestConfigThrowsInvocationTargetExceptionException() {
// throw new RuntimeException();
// }
// }
//
// Path: src/test/java/com/tngtech/configbuilder/testclasses/TestConfigWithoutDefaultConstructor.java
// @PropertyExtension("testproperties")
// @PropertySuffixes(extraSuffixes = {"test"})
// @PropertyLocations(resourcesForClasses = {PropertyLoader.class})
// @PropertiesFiles("demoapp-configuration")
// @LoadingOrder(value = {CommandLineValue.class, PropertyValue.class, DefaultValue.class})
// public class TestConfigWithoutDefaultConstructor {
//
// private int number;
//
// public TestConfigWithoutDefaultConstructor(Integer i) {
// this.number = i;
// }
//
//
// public int getNumber() {
// return number;
// }
// }
// Path: src/test/java/com/tngtech/configbuilder/ConfigBuilderExceptionTest.java
import com.tngtech.configbuilder.exception.ConfigBuilderException;
import com.tngtech.configbuilder.exception.NoConstructorFoundException;
import com.tngtech.configbuilder.exception.PrimitiveParsingException;
import com.tngtech.configbuilder.testclasses.TestConfigThrowsIllegalArgumentException;
import com.tngtech.configbuilder.testclasses.TestConfigThrowsPrimitiveParsingException;
import com.tngtech.configbuilder.testclasses.TestConfigThrowsInvocationTargetExceptionException;
import com.tngtech.configbuilder.testclasses.TestConfigWithoutDefaultConstructor;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import java.util.Arrays;
import java.util.Collection;
package com.tngtech.configbuilder;
@RunWith(Parameterized.class)
public class ConfigBuilderExceptionTest {
private Class configClass;
private Class<? extends Throwable> exceptionClass;
private String message;
@Rule
public ExpectedException expectedException = ExpectedException.none();
@Before
public void setUp() {
}
@Parameterized.Parameters
public static Collection configs() {
return Arrays.asList(new Object[][]{
{TestConfigWithoutDefaultConstructor.class, NoConstructorFoundException.class, "build()"},
{TestConfigThrowsInvocationTargetExceptionException.class, ConfigBuilderException.class, "InvocationTargetException"}, | {TestConfigThrowsPrimitiveParsingException.class, PrimitiveParsingException.class, "stringValue"}, |
bmatthias/config-builder | src/test/java/com/tngtech/configbuilder/ConfigBuilderExceptionTest.java | // Path: src/main/java/com/tngtech/configbuilder/exception/ConfigBuilderException.java
// public class ConfigBuilderException extends RuntimeException {
//
// public ConfigBuilderException(String message, Throwable e) {
// super(message, e);
// }
// }
//
// Path: src/main/java/com/tngtech/configbuilder/exception/NoConstructorFoundException.java
// public class NoConstructorFoundException extends RuntimeException {
// public NoConstructorFoundException(String message) {
// super(message);
// }
// }
//
// Path: src/main/java/com/tngtech/configbuilder/exception/PrimitiveParsingException.java
// public class PrimitiveParsingException extends RuntimeException {
// public PrimitiveParsingException(String errorMessage) {
// super(errorMessage);
// }
// }
//
// Path: src/test/java/com/tngtech/configbuilder/testclasses/TestConfigThrowsIllegalArgumentException.java
// public class TestConfigThrowsIllegalArgumentException {
//
// @DefaultValue("stringValue")
// private Field integer;
// }
//
// Path: src/test/java/com/tngtech/configbuilder/testclasses/TestConfigThrowsPrimitiveParsingException.java
// public class TestConfigThrowsPrimitiveParsingException {
//
// @DefaultValue("stringValue")
// private int integer;
// }
//
// Path: src/test/java/com/tngtech/configbuilder/testclasses/TestConfigThrowsInvocationTargetExceptionException.java
// @PropertyExtension("testproperties")
// @PropertySuffixes(extraSuffixes = {"test"})
// @PropertyLocations(resourcesForClasses = {PropertyLoader.class})
// @PropertiesFiles("demoapp-configuration")
// @LoadingOrder(value = {CommandLineValue.class, PropertyValue.class, DefaultValue.class})
// public class TestConfigThrowsInvocationTargetExceptionException {
//
// private int number;
//
// private TestConfigThrowsInvocationTargetExceptionException() {
// throw new RuntimeException();
// }
// }
//
// Path: src/test/java/com/tngtech/configbuilder/testclasses/TestConfigWithoutDefaultConstructor.java
// @PropertyExtension("testproperties")
// @PropertySuffixes(extraSuffixes = {"test"})
// @PropertyLocations(resourcesForClasses = {PropertyLoader.class})
// @PropertiesFiles("demoapp-configuration")
// @LoadingOrder(value = {CommandLineValue.class, PropertyValue.class, DefaultValue.class})
// public class TestConfigWithoutDefaultConstructor {
//
// private int number;
//
// public TestConfigWithoutDefaultConstructor(Integer i) {
// this.number = i;
// }
//
//
// public int getNumber() {
// return number;
// }
// }
| import com.tngtech.configbuilder.exception.ConfigBuilderException;
import com.tngtech.configbuilder.exception.NoConstructorFoundException;
import com.tngtech.configbuilder.exception.PrimitiveParsingException;
import com.tngtech.configbuilder.testclasses.TestConfigThrowsIllegalArgumentException;
import com.tngtech.configbuilder.testclasses.TestConfigThrowsPrimitiveParsingException;
import com.tngtech.configbuilder.testclasses.TestConfigThrowsInvocationTargetExceptionException;
import com.tngtech.configbuilder.testclasses.TestConfigWithoutDefaultConstructor;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import java.util.Arrays;
import java.util.Collection; | package com.tngtech.configbuilder;
@RunWith(Parameterized.class)
public class ConfigBuilderExceptionTest {
private Class configClass;
private Class<? extends Throwable> exceptionClass;
private String message;
@Rule
public ExpectedException expectedException = ExpectedException.none();
@Before
public void setUp() {
}
@Parameterized.Parameters
public static Collection configs() {
return Arrays.asList(new Object[][]{
{TestConfigWithoutDefaultConstructor.class, NoConstructorFoundException.class, "build()"},
{TestConfigThrowsInvocationTargetExceptionException.class, ConfigBuilderException.class, "InvocationTargetException"}, | // Path: src/main/java/com/tngtech/configbuilder/exception/ConfigBuilderException.java
// public class ConfigBuilderException extends RuntimeException {
//
// public ConfigBuilderException(String message, Throwable e) {
// super(message, e);
// }
// }
//
// Path: src/main/java/com/tngtech/configbuilder/exception/NoConstructorFoundException.java
// public class NoConstructorFoundException extends RuntimeException {
// public NoConstructorFoundException(String message) {
// super(message);
// }
// }
//
// Path: src/main/java/com/tngtech/configbuilder/exception/PrimitiveParsingException.java
// public class PrimitiveParsingException extends RuntimeException {
// public PrimitiveParsingException(String errorMessage) {
// super(errorMessage);
// }
// }
//
// Path: src/test/java/com/tngtech/configbuilder/testclasses/TestConfigThrowsIllegalArgumentException.java
// public class TestConfigThrowsIllegalArgumentException {
//
// @DefaultValue("stringValue")
// private Field integer;
// }
//
// Path: src/test/java/com/tngtech/configbuilder/testclasses/TestConfigThrowsPrimitiveParsingException.java
// public class TestConfigThrowsPrimitiveParsingException {
//
// @DefaultValue("stringValue")
// private int integer;
// }
//
// Path: src/test/java/com/tngtech/configbuilder/testclasses/TestConfigThrowsInvocationTargetExceptionException.java
// @PropertyExtension("testproperties")
// @PropertySuffixes(extraSuffixes = {"test"})
// @PropertyLocations(resourcesForClasses = {PropertyLoader.class})
// @PropertiesFiles("demoapp-configuration")
// @LoadingOrder(value = {CommandLineValue.class, PropertyValue.class, DefaultValue.class})
// public class TestConfigThrowsInvocationTargetExceptionException {
//
// private int number;
//
// private TestConfigThrowsInvocationTargetExceptionException() {
// throw new RuntimeException();
// }
// }
//
// Path: src/test/java/com/tngtech/configbuilder/testclasses/TestConfigWithoutDefaultConstructor.java
// @PropertyExtension("testproperties")
// @PropertySuffixes(extraSuffixes = {"test"})
// @PropertyLocations(resourcesForClasses = {PropertyLoader.class})
// @PropertiesFiles("demoapp-configuration")
// @LoadingOrder(value = {CommandLineValue.class, PropertyValue.class, DefaultValue.class})
// public class TestConfigWithoutDefaultConstructor {
//
// private int number;
//
// public TestConfigWithoutDefaultConstructor(Integer i) {
// this.number = i;
// }
//
//
// public int getNumber() {
// return number;
// }
// }
// Path: src/test/java/com/tngtech/configbuilder/ConfigBuilderExceptionTest.java
import com.tngtech.configbuilder.exception.ConfigBuilderException;
import com.tngtech.configbuilder.exception.NoConstructorFoundException;
import com.tngtech.configbuilder.exception.PrimitiveParsingException;
import com.tngtech.configbuilder.testclasses.TestConfigThrowsIllegalArgumentException;
import com.tngtech.configbuilder.testclasses.TestConfigThrowsPrimitiveParsingException;
import com.tngtech.configbuilder.testclasses.TestConfigThrowsInvocationTargetExceptionException;
import com.tngtech.configbuilder.testclasses.TestConfigWithoutDefaultConstructor;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import java.util.Arrays;
import java.util.Collection;
package com.tngtech.configbuilder;
@RunWith(Parameterized.class)
public class ConfigBuilderExceptionTest {
private Class configClass;
private Class<? extends Throwable> exceptionClass;
private String message;
@Rule
public ExpectedException expectedException = ExpectedException.none();
@Before
public void setUp() {
}
@Parameterized.Parameters
public static Collection configs() {
return Arrays.asList(new Object[][]{
{TestConfigWithoutDefaultConstructor.class, NoConstructorFoundException.class, "build()"},
{TestConfigThrowsInvocationTargetExceptionException.class, ConfigBuilderException.class, "InvocationTargetException"}, | {TestConfigThrowsPrimitiveParsingException.class, PrimitiveParsingException.class, "stringValue"}, |
bmatthias/config-builder | src/test/java/com/tngtech/configbuilder/ConfigBuilderExceptionTest.java | // Path: src/main/java/com/tngtech/configbuilder/exception/ConfigBuilderException.java
// public class ConfigBuilderException extends RuntimeException {
//
// public ConfigBuilderException(String message, Throwable e) {
// super(message, e);
// }
// }
//
// Path: src/main/java/com/tngtech/configbuilder/exception/NoConstructorFoundException.java
// public class NoConstructorFoundException extends RuntimeException {
// public NoConstructorFoundException(String message) {
// super(message);
// }
// }
//
// Path: src/main/java/com/tngtech/configbuilder/exception/PrimitiveParsingException.java
// public class PrimitiveParsingException extends RuntimeException {
// public PrimitiveParsingException(String errorMessage) {
// super(errorMessage);
// }
// }
//
// Path: src/test/java/com/tngtech/configbuilder/testclasses/TestConfigThrowsIllegalArgumentException.java
// public class TestConfigThrowsIllegalArgumentException {
//
// @DefaultValue("stringValue")
// private Field integer;
// }
//
// Path: src/test/java/com/tngtech/configbuilder/testclasses/TestConfigThrowsPrimitiveParsingException.java
// public class TestConfigThrowsPrimitiveParsingException {
//
// @DefaultValue("stringValue")
// private int integer;
// }
//
// Path: src/test/java/com/tngtech/configbuilder/testclasses/TestConfigThrowsInvocationTargetExceptionException.java
// @PropertyExtension("testproperties")
// @PropertySuffixes(extraSuffixes = {"test"})
// @PropertyLocations(resourcesForClasses = {PropertyLoader.class})
// @PropertiesFiles("demoapp-configuration")
// @LoadingOrder(value = {CommandLineValue.class, PropertyValue.class, DefaultValue.class})
// public class TestConfigThrowsInvocationTargetExceptionException {
//
// private int number;
//
// private TestConfigThrowsInvocationTargetExceptionException() {
// throw new RuntimeException();
// }
// }
//
// Path: src/test/java/com/tngtech/configbuilder/testclasses/TestConfigWithoutDefaultConstructor.java
// @PropertyExtension("testproperties")
// @PropertySuffixes(extraSuffixes = {"test"})
// @PropertyLocations(resourcesForClasses = {PropertyLoader.class})
// @PropertiesFiles("demoapp-configuration")
// @LoadingOrder(value = {CommandLineValue.class, PropertyValue.class, DefaultValue.class})
// public class TestConfigWithoutDefaultConstructor {
//
// private int number;
//
// public TestConfigWithoutDefaultConstructor(Integer i) {
// this.number = i;
// }
//
//
// public int getNumber() {
// return number;
// }
// }
| import com.tngtech.configbuilder.exception.ConfigBuilderException;
import com.tngtech.configbuilder.exception.NoConstructorFoundException;
import com.tngtech.configbuilder.exception.PrimitiveParsingException;
import com.tngtech.configbuilder.testclasses.TestConfigThrowsIllegalArgumentException;
import com.tngtech.configbuilder.testclasses.TestConfigThrowsPrimitiveParsingException;
import com.tngtech.configbuilder.testclasses.TestConfigThrowsInvocationTargetExceptionException;
import com.tngtech.configbuilder.testclasses.TestConfigWithoutDefaultConstructor;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import java.util.Arrays;
import java.util.Collection; | package com.tngtech.configbuilder;
@RunWith(Parameterized.class)
public class ConfigBuilderExceptionTest {
private Class configClass;
private Class<? extends Throwable> exceptionClass;
private String message;
@Rule
public ExpectedException expectedException = ExpectedException.none();
@Before
public void setUp() {
}
@Parameterized.Parameters
public static Collection configs() {
return Arrays.asList(new Object[][]{
{TestConfigWithoutDefaultConstructor.class, NoConstructorFoundException.class, "build()"},
{TestConfigThrowsInvocationTargetExceptionException.class, ConfigBuilderException.class, "InvocationTargetException"},
{TestConfigThrowsPrimitiveParsingException.class, PrimitiveParsingException.class, "stringValue"}, | // Path: src/main/java/com/tngtech/configbuilder/exception/ConfigBuilderException.java
// public class ConfigBuilderException extends RuntimeException {
//
// public ConfigBuilderException(String message, Throwable e) {
// super(message, e);
// }
// }
//
// Path: src/main/java/com/tngtech/configbuilder/exception/NoConstructorFoundException.java
// public class NoConstructorFoundException extends RuntimeException {
// public NoConstructorFoundException(String message) {
// super(message);
// }
// }
//
// Path: src/main/java/com/tngtech/configbuilder/exception/PrimitiveParsingException.java
// public class PrimitiveParsingException extends RuntimeException {
// public PrimitiveParsingException(String errorMessage) {
// super(errorMessage);
// }
// }
//
// Path: src/test/java/com/tngtech/configbuilder/testclasses/TestConfigThrowsIllegalArgumentException.java
// public class TestConfigThrowsIllegalArgumentException {
//
// @DefaultValue("stringValue")
// private Field integer;
// }
//
// Path: src/test/java/com/tngtech/configbuilder/testclasses/TestConfigThrowsPrimitiveParsingException.java
// public class TestConfigThrowsPrimitiveParsingException {
//
// @DefaultValue("stringValue")
// private int integer;
// }
//
// Path: src/test/java/com/tngtech/configbuilder/testclasses/TestConfigThrowsInvocationTargetExceptionException.java
// @PropertyExtension("testproperties")
// @PropertySuffixes(extraSuffixes = {"test"})
// @PropertyLocations(resourcesForClasses = {PropertyLoader.class})
// @PropertiesFiles("demoapp-configuration")
// @LoadingOrder(value = {CommandLineValue.class, PropertyValue.class, DefaultValue.class})
// public class TestConfigThrowsInvocationTargetExceptionException {
//
// private int number;
//
// private TestConfigThrowsInvocationTargetExceptionException() {
// throw new RuntimeException();
// }
// }
//
// Path: src/test/java/com/tngtech/configbuilder/testclasses/TestConfigWithoutDefaultConstructor.java
// @PropertyExtension("testproperties")
// @PropertySuffixes(extraSuffixes = {"test"})
// @PropertyLocations(resourcesForClasses = {PropertyLoader.class})
// @PropertiesFiles("demoapp-configuration")
// @LoadingOrder(value = {CommandLineValue.class, PropertyValue.class, DefaultValue.class})
// public class TestConfigWithoutDefaultConstructor {
//
// private int number;
//
// public TestConfigWithoutDefaultConstructor(Integer i) {
// this.number = i;
// }
//
//
// public int getNumber() {
// return number;
// }
// }
// Path: src/test/java/com/tngtech/configbuilder/ConfigBuilderExceptionTest.java
import com.tngtech.configbuilder.exception.ConfigBuilderException;
import com.tngtech.configbuilder.exception.NoConstructorFoundException;
import com.tngtech.configbuilder.exception.PrimitiveParsingException;
import com.tngtech.configbuilder.testclasses.TestConfigThrowsIllegalArgumentException;
import com.tngtech.configbuilder.testclasses.TestConfigThrowsPrimitiveParsingException;
import com.tngtech.configbuilder.testclasses.TestConfigThrowsInvocationTargetExceptionException;
import com.tngtech.configbuilder.testclasses.TestConfigWithoutDefaultConstructor;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import java.util.Arrays;
import java.util.Collection;
package com.tngtech.configbuilder;
@RunWith(Parameterized.class)
public class ConfigBuilderExceptionTest {
private Class configClass;
private Class<? extends Throwable> exceptionClass;
private String message;
@Rule
public ExpectedException expectedException = ExpectedException.none();
@Before
public void setUp() {
}
@Parameterized.Parameters
public static Collection configs() {
return Arrays.asList(new Object[][]{
{TestConfigWithoutDefaultConstructor.class, NoConstructorFoundException.class, "build()"},
{TestConfigThrowsInvocationTargetExceptionException.class, ConfigBuilderException.class, "InvocationTargetException"},
{TestConfigThrowsPrimitiveParsingException.class, PrimitiveParsingException.class, "stringValue"}, | {TestConfigThrowsIllegalArgumentException.class, ConfigBuilderException.class, "Field"} |
bmatthias/config-builder | src/test/java/com/tngtech/configbuilder/testclasses/TestConfig.java | // Path: src/main/java/com/tngtech/configbuilder/annotation/valuetransformer/CharacterSeparatedStringToStringListTransformer.java
// public class CharacterSeparatedStringToStringListTransformer extends ValueTransformer<String, ArrayList<String>> {
//
// @Override
// public ArrayList<String> transform(String argument) {
//
// ArrayList<String> collection = Lists.newArrayList();
// for (String value : argument.split((String)additionalOptions[0])) {
// collection.add(value);
// }
// return collection;
// }
// }
//
// Path: src/main/java/com/tngtech/configbuilder/annotation/valuetransformer/ValueTransformer.java
// public abstract class ValueTransformer<SourceClass, TargetClass> {
//
// protected Type targetType;
// protected FieldValueTransformer fieldValueTransformer;
// protected GenericsAndCastingHelper genericsAndCastingHelper;
// protected ErrorMessageSetup errorMessageSetup;
// protected Object[] additionalOptions;
//
// public abstract TargetClass transform(SourceClass argument);
//
// public void initialize(FieldValueTransformer fieldValueTransformer, ConfigBuilderFactory configBuilderFactory, Object... additionalOptions) {
// this.fieldValueTransformer = fieldValueTransformer;
// this.genericsAndCastingHelper = configBuilderFactory.getInstance(GenericsAndCastingHelper.class);
// this.errorMessageSetup = configBuilderFactory.getInstance(ErrorMessageSetup.class);
// this.additionalOptions = additionalOptions;
// }
//
// public boolean isMatching(Object sourceValue, Type targetType) {
// if(sourceValue == null) {
// return false;
// }
// Class<?> sourceClass = genericsAndCastingHelper.getWrapperClassIfPrimitive(sourceValue.getClass());
// Class<?> targetClass = genericsAndCastingHelper.getWrapperClassIfPrimitive(genericsAndCastingHelper.castTypeToClass(targetType));
// Class<?> transformerSourceClass = getTransformerSourceClass();
// Class<?> transformerTargetClass = getTransformerTargetClass();
// if(transformerSourceClass.isAssignableFrom(sourceClass) && targetClass.isAssignableFrom(transformerTargetClass)) {
// return true;
// }
// return false;
// }
//
// public Class<?> getTransformerSourceClass() {
// Type typeOfInterface = this.getClass().getGenericSuperclass();
// Type[] genericTypes = ((ParameterizedType) typeOfInterface).getActualTypeArguments();
// return genericsAndCastingHelper.castTypeToClass(genericTypes[0]);
// }
//
// public Class<?> getTransformerTargetClass() {
// Type typeOfInterface = this.getClass().getGenericSuperclass();
// Type[] genericTypes = ((ParameterizedType) typeOfInterface).getActualTypeArguments();
// return genericsAndCastingHelper.castTypeToClass(genericTypes[1]);
// }
//
// public void setTargetType(Type targetType) {
// this.targetType = targetType;
// }
//
// public boolean isContentTransformer() {
// return getTransformerTargetClass().isAssignableFrom(getTransformerSourceClass());
// }
// }
| import com.google.common.collect.Lists;
import com.tngtech.configbuilder.annotation.configuration.LoadingOrder;
import com.tngtech.configbuilder.annotation.configuration.Separator;
import com.tngtech.configbuilder.annotation.propertyloaderconfiguration.PropertiesFiles;
import com.tngtech.configbuilder.annotation.propertyloaderconfiguration.PropertyExtension;
import com.tngtech.configbuilder.annotation.propertyloaderconfiguration.PropertyLocations;
import com.tngtech.configbuilder.annotation.propertyloaderconfiguration.PropertySuffixes;
import com.tngtech.configbuilder.annotation.validation.Validation;
import com.tngtech.configbuilder.annotation.valueextractor.*;
import com.tngtech.configbuilder.annotation.valuetransformer.CharacterSeparatedStringToStringListTransformer;
import com.tngtech.configbuilder.annotation.valuetransformer.ValueTransformer;
import com.tngtech.configbuilder.annotation.valuetransformer.ValueTransformers;
import com.tngtech.propertyloader.PropertyLoader;
import java.nio.file.Path;
import java.util.*; | package com.tngtech.configbuilder.testclasses;
@PropertyExtension("testproperties")
@PropertySuffixes(extraSuffixes = {"test"})
@PropertyLocations(resourcesForClasses = {PropertyLoader.class})
@PropertiesFiles("demoapp-configuration")
public class TestConfig {
public TestConfig() {
}
| // Path: src/main/java/com/tngtech/configbuilder/annotation/valuetransformer/CharacterSeparatedStringToStringListTransformer.java
// public class CharacterSeparatedStringToStringListTransformer extends ValueTransformer<String, ArrayList<String>> {
//
// @Override
// public ArrayList<String> transform(String argument) {
//
// ArrayList<String> collection = Lists.newArrayList();
// for (String value : argument.split((String)additionalOptions[0])) {
// collection.add(value);
// }
// return collection;
// }
// }
//
// Path: src/main/java/com/tngtech/configbuilder/annotation/valuetransformer/ValueTransformer.java
// public abstract class ValueTransformer<SourceClass, TargetClass> {
//
// protected Type targetType;
// protected FieldValueTransformer fieldValueTransformer;
// protected GenericsAndCastingHelper genericsAndCastingHelper;
// protected ErrorMessageSetup errorMessageSetup;
// protected Object[] additionalOptions;
//
// public abstract TargetClass transform(SourceClass argument);
//
// public void initialize(FieldValueTransformer fieldValueTransformer, ConfigBuilderFactory configBuilderFactory, Object... additionalOptions) {
// this.fieldValueTransformer = fieldValueTransformer;
// this.genericsAndCastingHelper = configBuilderFactory.getInstance(GenericsAndCastingHelper.class);
// this.errorMessageSetup = configBuilderFactory.getInstance(ErrorMessageSetup.class);
// this.additionalOptions = additionalOptions;
// }
//
// public boolean isMatching(Object sourceValue, Type targetType) {
// if(sourceValue == null) {
// return false;
// }
// Class<?> sourceClass = genericsAndCastingHelper.getWrapperClassIfPrimitive(sourceValue.getClass());
// Class<?> targetClass = genericsAndCastingHelper.getWrapperClassIfPrimitive(genericsAndCastingHelper.castTypeToClass(targetType));
// Class<?> transformerSourceClass = getTransformerSourceClass();
// Class<?> transformerTargetClass = getTransformerTargetClass();
// if(transformerSourceClass.isAssignableFrom(sourceClass) && targetClass.isAssignableFrom(transformerTargetClass)) {
// return true;
// }
// return false;
// }
//
// public Class<?> getTransformerSourceClass() {
// Type typeOfInterface = this.getClass().getGenericSuperclass();
// Type[] genericTypes = ((ParameterizedType) typeOfInterface).getActualTypeArguments();
// return genericsAndCastingHelper.castTypeToClass(genericTypes[0]);
// }
//
// public Class<?> getTransformerTargetClass() {
// Type typeOfInterface = this.getClass().getGenericSuperclass();
// Type[] genericTypes = ((ParameterizedType) typeOfInterface).getActualTypeArguments();
// return genericsAndCastingHelper.castTypeToClass(genericTypes[1]);
// }
//
// public void setTargetType(Type targetType) {
// this.targetType = targetType;
// }
//
// public boolean isContentTransformer() {
// return getTransformerTargetClass().isAssignableFrom(getTransformerSourceClass());
// }
// }
// Path: src/test/java/com/tngtech/configbuilder/testclasses/TestConfig.java
import com.google.common.collect.Lists;
import com.tngtech.configbuilder.annotation.configuration.LoadingOrder;
import com.tngtech.configbuilder.annotation.configuration.Separator;
import com.tngtech.configbuilder.annotation.propertyloaderconfiguration.PropertiesFiles;
import com.tngtech.configbuilder.annotation.propertyloaderconfiguration.PropertyExtension;
import com.tngtech.configbuilder.annotation.propertyloaderconfiguration.PropertyLocations;
import com.tngtech.configbuilder.annotation.propertyloaderconfiguration.PropertySuffixes;
import com.tngtech.configbuilder.annotation.validation.Validation;
import com.tngtech.configbuilder.annotation.valueextractor.*;
import com.tngtech.configbuilder.annotation.valuetransformer.CharacterSeparatedStringToStringListTransformer;
import com.tngtech.configbuilder.annotation.valuetransformer.ValueTransformer;
import com.tngtech.configbuilder.annotation.valuetransformer.ValueTransformers;
import com.tngtech.propertyloader.PropertyLoader;
import java.nio.file.Path;
import java.util.*;
package com.tngtech.configbuilder.testclasses;
@PropertyExtension("testproperties")
@PropertySuffixes(extraSuffixes = {"test"})
@PropertyLocations(resourcesForClasses = {PropertyLoader.class})
@PropertiesFiles("demoapp-configuration")
public class TestConfig {
public TestConfig() {
}
| public class TestConfigFactory extends ValueTransformer<String,TestConfig> { |
bmatthias/config-builder | src/test/java/com/tngtech/configbuilder/testclasses/TestConfig.java | // Path: src/main/java/com/tngtech/configbuilder/annotation/valuetransformer/CharacterSeparatedStringToStringListTransformer.java
// public class CharacterSeparatedStringToStringListTransformer extends ValueTransformer<String, ArrayList<String>> {
//
// @Override
// public ArrayList<String> transform(String argument) {
//
// ArrayList<String> collection = Lists.newArrayList();
// for (String value : argument.split((String)additionalOptions[0])) {
// collection.add(value);
// }
// return collection;
// }
// }
//
// Path: src/main/java/com/tngtech/configbuilder/annotation/valuetransformer/ValueTransformer.java
// public abstract class ValueTransformer<SourceClass, TargetClass> {
//
// protected Type targetType;
// protected FieldValueTransformer fieldValueTransformer;
// protected GenericsAndCastingHelper genericsAndCastingHelper;
// protected ErrorMessageSetup errorMessageSetup;
// protected Object[] additionalOptions;
//
// public abstract TargetClass transform(SourceClass argument);
//
// public void initialize(FieldValueTransformer fieldValueTransformer, ConfigBuilderFactory configBuilderFactory, Object... additionalOptions) {
// this.fieldValueTransformer = fieldValueTransformer;
// this.genericsAndCastingHelper = configBuilderFactory.getInstance(GenericsAndCastingHelper.class);
// this.errorMessageSetup = configBuilderFactory.getInstance(ErrorMessageSetup.class);
// this.additionalOptions = additionalOptions;
// }
//
// public boolean isMatching(Object sourceValue, Type targetType) {
// if(sourceValue == null) {
// return false;
// }
// Class<?> sourceClass = genericsAndCastingHelper.getWrapperClassIfPrimitive(sourceValue.getClass());
// Class<?> targetClass = genericsAndCastingHelper.getWrapperClassIfPrimitive(genericsAndCastingHelper.castTypeToClass(targetType));
// Class<?> transformerSourceClass = getTransformerSourceClass();
// Class<?> transformerTargetClass = getTransformerTargetClass();
// if(transformerSourceClass.isAssignableFrom(sourceClass) && targetClass.isAssignableFrom(transformerTargetClass)) {
// return true;
// }
// return false;
// }
//
// public Class<?> getTransformerSourceClass() {
// Type typeOfInterface = this.getClass().getGenericSuperclass();
// Type[] genericTypes = ((ParameterizedType) typeOfInterface).getActualTypeArguments();
// return genericsAndCastingHelper.castTypeToClass(genericTypes[0]);
// }
//
// public Class<?> getTransformerTargetClass() {
// Type typeOfInterface = this.getClass().getGenericSuperclass();
// Type[] genericTypes = ((ParameterizedType) typeOfInterface).getActualTypeArguments();
// return genericsAndCastingHelper.castTypeToClass(genericTypes[1]);
// }
//
// public void setTargetType(Type targetType) {
// this.targetType = targetType;
// }
//
// public boolean isContentTransformer() {
// return getTransformerTargetClass().isAssignableFrom(getTransformerSourceClass());
// }
// }
| import com.google.common.collect.Lists;
import com.tngtech.configbuilder.annotation.configuration.LoadingOrder;
import com.tngtech.configbuilder.annotation.configuration.Separator;
import com.tngtech.configbuilder.annotation.propertyloaderconfiguration.PropertiesFiles;
import com.tngtech.configbuilder.annotation.propertyloaderconfiguration.PropertyExtension;
import com.tngtech.configbuilder.annotation.propertyloaderconfiguration.PropertyLocations;
import com.tngtech.configbuilder.annotation.propertyloaderconfiguration.PropertySuffixes;
import com.tngtech.configbuilder.annotation.validation.Validation;
import com.tngtech.configbuilder.annotation.valueextractor.*;
import com.tngtech.configbuilder.annotation.valuetransformer.CharacterSeparatedStringToStringListTransformer;
import com.tngtech.configbuilder.annotation.valuetransformer.ValueTransformer;
import com.tngtech.configbuilder.annotation.valuetransformer.ValueTransformers;
import com.tngtech.propertyloader.PropertyLoader;
import java.nio.file.Path;
import java.util.*; | testConfig.setSomeString(input);
return testConfig;
}
}
public static class ListElementIncrementer extends ValueTransformer<ArrayList<Integer>,ArrayList<Integer>> {
public ArrayList<Integer> transform(ArrayList<Integer> input) {
ArrayList<Integer> result = Lists.newArrayList();
for(Integer element : input) {
result.add(element + 1);
}
return result;
}
}
@DefaultValue("3")
@ImportedValue("someNumber")
private int someNumber;
@PropertyValue("keyThatDoesNotExist")
private int shouldBeZero;
@PropertyValue("a")
private String someString;
@CommandLineValue(shortOpt = "u", longOpt = "user")
private boolean aBoolean;
@LoadingOrder(value = {CommandLineValue.class})
@CommandLineValue(shortOpt = "c", longOpt = "collection", hasArg = true, description = "command line option description") | // Path: src/main/java/com/tngtech/configbuilder/annotation/valuetransformer/CharacterSeparatedStringToStringListTransformer.java
// public class CharacterSeparatedStringToStringListTransformer extends ValueTransformer<String, ArrayList<String>> {
//
// @Override
// public ArrayList<String> transform(String argument) {
//
// ArrayList<String> collection = Lists.newArrayList();
// for (String value : argument.split((String)additionalOptions[0])) {
// collection.add(value);
// }
// return collection;
// }
// }
//
// Path: src/main/java/com/tngtech/configbuilder/annotation/valuetransformer/ValueTransformer.java
// public abstract class ValueTransformer<SourceClass, TargetClass> {
//
// protected Type targetType;
// protected FieldValueTransformer fieldValueTransformer;
// protected GenericsAndCastingHelper genericsAndCastingHelper;
// protected ErrorMessageSetup errorMessageSetup;
// protected Object[] additionalOptions;
//
// public abstract TargetClass transform(SourceClass argument);
//
// public void initialize(FieldValueTransformer fieldValueTransformer, ConfigBuilderFactory configBuilderFactory, Object... additionalOptions) {
// this.fieldValueTransformer = fieldValueTransformer;
// this.genericsAndCastingHelper = configBuilderFactory.getInstance(GenericsAndCastingHelper.class);
// this.errorMessageSetup = configBuilderFactory.getInstance(ErrorMessageSetup.class);
// this.additionalOptions = additionalOptions;
// }
//
// public boolean isMatching(Object sourceValue, Type targetType) {
// if(sourceValue == null) {
// return false;
// }
// Class<?> sourceClass = genericsAndCastingHelper.getWrapperClassIfPrimitive(sourceValue.getClass());
// Class<?> targetClass = genericsAndCastingHelper.getWrapperClassIfPrimitive(genericsAndCastingHelper.castTypeToClass(targetType));
// Class<?> transformerSourceClass = getTransformerSourceClass();
// Class<?> transformerTargetClass = getTransformerTargetClass();
// if(transformerSourceClass.isAssignableFrom(sourceClass) && targetClass.isAssignableFrom(transformerTargetClass)) {
// return true;
// }
// return false;
// }
//
// public Class<?> getTransformerSourceClass() {
// Type typeOfInterface = this.getClass().getGenericSuperclass();
// Type[] genericTypes = ((ParameterizedType) typeOfInterface).getActualTypeArguments();
// return genericsAndCastingHelper.castTypeToClass(genericTypes[0]);
// }
//
// public Class<?> getTransformerTargetClass() {
// Type typeOfInterface = this.getClass().getGenericSuperclass();
// Type[] genericTypes = ((ParameterizedType) typeOfInterface).getActualTypeArguments();
// return genericsAndCastingHelper.castTypeToClass(genericTypes[1]);
// }
//
// public void setTargetType(Type targetType) {
// this.targetType = targetType;
// }
//
// public boolean isContentTransformer() {
// return getTransformerTargetClass().isAssignableFrom(getTransformerSourceClass());
// }
// }
// Path: src/test/java/com/tngtech/configbuilder/testclasses/TestConfig.java
import com.google.common.collect.Lists;
import com.tngtech.configbuilder.annotation.configuration.LoadingOrder;
import com.tngtech.configbuilder.annotation.configuration.Separator;
import com.tngtech.configbuilder.annotation.propertyloaderconfiguration.PropertiesFiles;
import com.tngtech.configbuilder.annotation.propertyloaderconfiguration.PropertyExtension;
import com.tngtech.configbuilder.annotation.propertyloaderconfiguration.PropertyLocations;
import com.tngtech.configbuilder.annotation.propertyloaderconfiguration.PropertySuffixes;
import com.tngtech.configbuilder.annotation.validation.Validation;
import com.tngtech.configbuilder.annotation.valueextractor.*;
import com.tngtech.configbuilder.annotation.valuetransformer.CharacterSeparatedStringToStringListTransformer;
import com.tngtech.configbuilder.annotation.valuetransformer.ValueTransformer;
import com.tngtech.configbuilder.annotation.valuetransformer.ValueTransformers;
import com.tngtech.propertyloader.PropertyLoader;
import java.nio.file.Path;
import java.util.*;
testConfig.setSomeString(input);
return testConfig;
}
}
public static class ListElementIncrementer extends ValueTransformer<ArrayList<Integer>,ArrayList<Integer>> {
public ArrayList<Integer> transform(ArrayList<Integer> input) {
ArrayList<Integer> result = Lists.newArrayList();
for(Integer element : input) {
result.add(element + 1);
}
return result;
}
}
@DefaultValue("3")
@ImportedValue("someNumber")
private int someNumber;
@PropertyValue("keyThatDoesNotExist")
private int shouldBeZero;
@PropertyValue("a")
private String someString;
@CommandLineValue(shortOpt = "u", longOpt = "user")
private boolean aBoolean;
@LoadingOrder(value = {CommandLineValue.class})
@CommandLineValue(shortOpt = "c", longOpt = "collection", hasArg = true, description = "command line option description") | @ValueTransformers({CharacterSeparatedStringToStringListTransformer.class}) |
bmatthias/config-builder | src/main/java/com/tngtech/configbuilder/util/PropertyLoaderConfigurator.java | // Path: src/main/java/com/tngtech/configbuilder/annotation/propertyloaderconfiguration/PropertyLoaderConfigurationProcessor.java
// public interface PropertyLoaderConfigurationProcessor {
// public void configurePropertyLoader(Annotation annotation, PropertyLoader propertyLoader);
// }
| import com.tngtech.configbuilder.annotation.propertyloaderconfiguration.PropertyLoaderConfigurationProcessor;
import com.tngtech.configbuilder.annotation.propertyloaderconfiguration.PropertyLoaderConfigurationAnnotation;
import com.tngtech.propertyloader.PropertyLoader;
import java.lang.annotation.Annotation; | package com.tngtech.configbuilder.util;
public class PropertyLoaderConfigurator {
private AnnotationHelper annotationHelper;
private ConfigBuilderFactory configBuilderFactory;
public PropertyLoaderConfigurator(ConfigBuilderFactory configBuilderFactory) {
this.annotationHelper = configBuilderFactory.getInstance(AnnotationHelper.class);
this.configBuilderFactory = configBuilderFactory;
}
public PropertyLoader configurePropertyLoader(Class<?> configClass) {
PropertyLoader propertyLoader = configBuilderFactory.createInstance(PropertyLoader.class).withDefaultConfig();
for (Annotation annotation : annotationHelper.getAnnotationsAnnotatedWith(configClass.getDeclaredAnnotations(), PropertyLoaderConfigurationAnnotation.class)) { | // Path: src/main/java/com/tngtech/configbuilder/annotation/propertyloaderconfiguration/PropertyLoaderConfigurationProcessor.java
// public interface PropertyLoaderConfigurationProcessor {
// public void configurePropertyLoader(Annotation annotation, PropertyLoader propertyLoader);
// }
// Path: src/main/java/com/tngtech/configbuilder/util/PropertyLoaderConfigurator.java
import com.tngtech.configbuilder.annotation.propertyloaderconfiguration.PropertyLoaderConfigurationProcessor;
import com.tngtech.configbuilder.annotation.propertyloaderconfiguration.PropertyLoaderConfigurationAnnotation;
import com.tngtech.propertyloader.PropertyLoader;
import java.lang.annotation.Annotation;
package com.tngtech.configbuilder.util;
public class PropertyLoaderConfigurator {
private AnnotationHelper annotationHelper;
private ConfigBuilderFactory configBuilderFactory;
public PropertyLoaderConfigurator(ConfigBuilderFactory configBuilderFactory) {
this.annotationHelper = configBuilderFactory.getInstance(AnnotationHelper.class);
this.configBuilderFactory = configBuilderFactory;
}
public PropertyLoader configurePropertyLoader(Class<?> configClass) {
PropertyLoader propertyLoader = configBuilderFactory.createInstance(PropertyLoader.class).withDefaultConfig();
for (Annotation annotation : annotationHelper.getAnnotationsAnnotatedWith(configClass.getDeclaredAnnotations(), PropertyLoaderConfigurationAnnotation.class)) { | Class<? extends PropertyLoaderConfigurationProcessor> processorClass = annotation.annotationType().getAnnotation(PropertyLoaderConfigurationAnnotation.class).value(); |
bmatthias/config-builder | src/test/java/com/tngtech/configbuilder/annotation/valueextractor/PropertyValueProcessorTest.java | // Path: src/main/java/com/tngtech/configbuilder/configuration/BuilderConfiguration.java
// public class BuilderConfiguration {
//
// private Properties properties;
// private CommandLine commandLine;
// private Object importedConfiguration;
// private Class<? extends Annotation>[] annotationOrder = new Class[]{CommandLineValue.class, PropertyValue.class, EnvironmentVariableValue.class, SystemPropertyValue.class, ImportedValue.class, DefaultValue.class};
//
// public BuilderConfiguration() {
// properties = new Properties();
// commandLine = null;
// importedConfiguration = null;
// }
//
// public CommandLine getCommandLine() {
// return commandLine;
// }
//
// public Properties getProperties() {
// return properties;
// }
//
// public Object getImportedConfiguration() {
// return importedConfiguration;
// }
//
// public void setProperties(Properties properties) {
// this.properties = properties;
// }
//
// public void setCommandLine(CommandLine commandLine) {
// this.commandLine = commandLine;
// }
//
// public void setImportedConfiguration(Object importedConfiguration) {
// this.importedConfiguration = importedConfiguration;
// }
//
// public void setAnnotationOrder(Class<? extends Annotation>[] annotationOrder) {
// this.annotationOrder = annotationOrder;
// }
//
// public Class<? extends Annotation>[] getAnnotationOrder() {
// return annotationOrder;
// }
// }
//
// Path: src/main/java/com/tngtech/configbuilder/util/ConfigBuilderFactory.java
// public class ConfigBuilderFactory {
//
// private Map<Class,Object> singletonMap = Maps.newHashMap();
//
// public <T> void initialize() {
//
// //Order is IMPORTANT!
//
// //configuration
// singletonMap.put(ErrorMessageSetup.class, new ErrorMessageSetup());
// singletonMap.put(BuilderConfiguration.class, new BuilderConfiguration());
//
// //util
// singletonMap.put(AnnotationHelper.class, new AnnotationHelper());
// singletonMap.put(GenericsAndCastingHelper.class, new GenericsAndCastingHelper());
// singletonMap.put(FieldValueExtractor.class, new FieldValueExtractor(this));
// singletonMap.put(FieldValueTransformer.class, new FieldValueTransformer(this));
// singletonMap.put(PropertyLoaderConfigurator.class, new PropertyLoaderConfigurator(this));
// singletonMap.put(ConstructionHelper.class, new ConstructionHelper<T>(this));
// singletonMap.put(FieldSetter.class, new FieldSetter<T>(this));
// singletonMap.put(ConfigValidator.class, new ConfigValidator<T>(this));
// singletonMap.put(CommandLineHelper.class, new CommandLineHelper(this));
//
// //AnnotationProcessors
// singletonMap.put(SystemPropertyProcessor.class, new SystemPropertyProcessor());
// singletonMap.put(PropertyValueProcessor.class, new PropertyValueProcessor());
// singletonMap.put(EnvironmentVariableProcessor.class, new EnvironmentVariableProcessor());
// singletonMap.put(CommandLineValueProcessor.class, new CommandLineValueProcessor());
// singletonMap.put(PropertySuffixProcessor.class, new PropertySuffixProcessor());
// singletonMap.put(PropertyLocationsProcessor.class, new PropertyLocationsProcessor());
// singletonMap.put(PropertyExtensionProcessor.class, new PropertyExtensionProcessor());
// singletonMap.put(PropertiesFilesProcessor.class, new PropertiesFilesProcessor());
// singletonMap.put(DefaultValueProcessor.class, new DefaultValueProcessor());
//
// //ValueTransformers
// singletonMap.put(StringOrPrimitiveToPrimitiveTransformer.class, new StringOrPrimitiveToPrimitiveTransformer());
// singletonMap.put(CollectionToArrayListTransformer.class, new CollectionToArrayListTransformer());
// singletonMap.put(CollectionToHashSetTransformer.class, new CollectionToHashSetTransformer());
// singletonMap.put(CharacterSeparatedStringToStringListTransformer.class, new CharacterSeparatedStringToStringListTransformer());
// singletonMap.put(CharacterSeparatedStringToStringSetTransformer.class, new CharacterSeparatedStringToStringSetTransformer());
// singletonMap.put(StringCollectionToCommaSeparatedStringTransformer.class, new StringCollectionToCommaSeparatedStringTransformer());
// singletonMap.put(StringToPathTransformer.class, new StringToPathTransformer());
//
// //other
// singletonMap.put(ValidatorFactory.class, Validation.buildDefaultValidatorFactory());
// }
//
// public <K> K getInstance(Class<K> clazz) {
// if(singletonMap.get(clazz) != null) {
// return (K)singletonMap.get(clazz);
// }
// else {
// return createInstance(clazz);
// }
// }
//
// //TODO: exception message
// public <K> K createInstance(Class<K> clazz) {
// try {
// return clazz.newInstance();
// } catch (IllegalAccessException e) {
// ErrorMessageSetup errorMessageSetup = (ErrorMessageSetup)singletonMap.get(ErrorMessageSetup.class);
// throw new FactoryInstantiationException(errorMessageSetup.getErrorMessage(FactoryInstantiationException.class, clazz.toString()));
// } catch (InstantiationException e) {
// return createInstanceOfInnerClass(clazz);
// }
// }
//
// //TODO: exception message
// private <K> K createInstanceOfInnerClass(Class<K> clazz) {
// Class superClass = clazz.getDeclaringClass();
// try {
// Object superInstance = superClass.newInstance();
// Constructor<K> constructor = clazz.getConstructor(superClass);
// return constructor.newInstance(superInstance);
// } catch (Exception e) {
// ErrorMessageSetup errorMessageSetup = (ErrorMessageSetup)singletonMap.get(ErrorMessageSetup.class);
// throw new FactoryInstantiationException(errorMessageSetup.getErrorMessage(FactoryInstantiationException.class, clazz.toString()));
// }
// }
// }
| import com.tngtech.configbuilder.configuration.BuilderConfiguration;
import com.tngtech.configbuilder.util.ConfigBuilderFactory;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import java.util.Properties;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.when; | package com.tngtech.configbuilder.annotation.valueextractor;
@RunWith(MockitoJUnitRunner.class)
public class PropertyValueProcessorTest {
private PropertyValueProcessor propertyValueProcessor;
@Mock | // Path: src/main/java/com/tngtech/configbuilder/configuration/BuilderConfiguration.java
// public class BuilderConfiguration {
//
// private Properties properties;
// private CommandLine commandLine;
// private Object importedConfiguration;
// private Class<? extends Annotation>[] annotationOrder = new Class[]{CommandLineValue.class, PropertyValue.class, EnvironmentVariableValue.class, SystemPropertyValue.class, ImportedValue.class, DefaultValue.class};
//
// public BuilderConfiguration() {
// properties = new Properties();
// commandLine = null;
// importedConfiguration = null;
// }
//
// public CommandLine getCommandLine() {
// return commandLine;
// }
//
// public Properties getProperties() {
// return properties;
// }
//
// public Object getImportedConfiguration() {
// return importedConfiguration;
// }
//
// public void setProperties(Properties properties) {
// this.properties = properties;
// }
//
// public void setCommandLine(CommandLine commandLine) {
// this.commandLine = commandLine;
// }
//
// public void setImportedConfiguration(Object importedConfiguration) {
// this.importedConfiguration = importedConfiguration;
// }
//
// public void setAnnotationOrder(Class<? extends Annotation>[] annotationOrder) {
// this.annotationOrder = annotationOrder;
// }
//
// public Class<? extends Annotation>[] getAnnotationOrder() {
// return annotationOrder;
// }
// }
//
// Path: src/main/java/com/tngtech/configbuilder/util/ConfigBuilderFactory.java
// public class ConfigBuilderFactory {
//
// private Map<Class,Object> singletonMap = Maps.newHashMap();
//
// public <T> void initialize() {
//
// //Order is IMPORTANT!
//
// //configuration
// singletonMap.put(ErrorMessageSetup.class, new ErrorMessageSetup());
// singletonMap.put(BuilderConfiguration.class, new BuilderConfiguration());
//
// //util
// singletonMap.put(AnnotationHelper.class, new AnnotationHelper());
// singletonMap.put(GenericsAndCastingHelper.class, new GenericsAndCastingHelper());
// singletonMap.put(FieldValueExtractor.class, new FieldValueExtractor(this));
// singletonMap.put(FieldValueTransformer.class, new FieldValueTransformer(this));
// singletonMap.put(PropertyLoaderConfigurator.class, new PropertyLoaderConfigurator(this));
// singletonMap.put(ConstructionHelper.class, new ConstructionHelper<T>(this));
// singletonMap.put(FieldSetter.class, new FieldSetter<T>(this));
// singletonMap.put(ConfigValidator.class, new ConfigValidator<T>(this));
// singletonMap.put(CommandLineHelper.class, new CommandLineHelper(this));
//
// //AnnotationProcessors
// singletonMap.put(SystemPropertyProcessor.class, new SystemPropertyProcessor());
// singletonMap.put(PropertyValueProcessor.class, new PropertyValueProcessor());
// singletonMap.put(EnvironmentVariableProcessor.class, new EnvironmentVariableProcessor());
// singletonMap.put(CommandLineValueProcessor.class, new CommandLineValueProcessor());
// singletonMap.put(PropertySuffixProcessor.class, new PropertySuffixProcessor());
// singletonMap.put(PropertyLocationsProcessor.class, new PropertyLocationsProcessor());
// singletonMap.put(PropertyExtensionProcessor.class, new PropertyExtensionProcessor());
// singletonMap.put(PropertiesFilesProcessor.class, new PropertiesFilesProcessor());
// singletonMap.put(DefaultValueProcessor.class, new DefaultValueProcessor());
//
// //ValueTransformers
// singletonMap.put(StringOrPrimitiveToPrimitiveTransformer.class, new StringOrPrimitiveToPrimitiveTransformer());
// singletonMap.put(CollectionToArrayListTransformer.class, new CollectionToArrayListTransformer());
// singletonMap.put(CollectionToHashSetTransformer.class, new CollectionToHashSetTransformer());
// singletonMap.put(CharacterSeparatedStringToStringListTransformer.class, new CharacterSeparatedStringToStringListTransformer());
// singletonMap.put(CharacterSeparatedStringToStringSetTransformer.class, new CharacterSeparatedStringToStringSetTransformer());
// singletonMap.put(StringCollectionToCommaSeparatedStringTransformer.class, new StringCollectionToCommaSeparatedStringTransformer());
// singletonMap.put(StringToPathTransformer.class, new StringToPathTransformer());
//
// //other
// singletonMap.put(ValidatorFactory.class, Validation.buildDefaultValidatorFactory());
// }
//
// public <K> K getInstance(Class<K> clazz) {
// if(singletonMap.get(clazz) != null) {
// return (K)singletonMap.get(clazz);
// }
// else {
// return createInstance(clazz);
// }
// }
//
// //TODO: exception message
// public <K> K createInstance(Class<K> clazz) {
// try {
// return clazz.newInstance();
// } catch (IllegalAccessException e) {
// ErrorMessageSetup errorMessageSetup = (ErrorMessageSetup)singletonMap.get(ErrorMessageSetup.class);
// throw new FactoryInstantiationException(errorMessageSetup.getErrorMessage(FactoryInstantiationException.class, clazz.toString()));
// } catch (InstantiationException e) {
// return createInstanceOfInnerClass(clazz);
// }
// }
//
// //TODO: exception message
// private <K> K createInstanceOfInnerClass(Class<K> clazz) {
// Class superClass = clazz.getDeclaringClass();
// try {
// Object superInstance = superClass.newInstance();
// Constructor<K> constructor = clazz.getConstructor(superClass);
// return constructor.newInstance(superInstance);
// } catch (Exception e) {
// ErrorMessageSetup errorMessageSetup = (ErrorMessageSetup)singletonMap.get(ErrorMessageSetup.class);
// throw new FactoryInstantiationException(errorMessageSetup.getErrorMessage(FactoryInstantiationException.class, clazz.toString()));
// }
// }
// }
// Path: src/test/java/com/tngtech/configbuilder/annotation/valueextractor/PropertyValueProcessorTest.java
import com.tngtech.configbuilder.configuration.BuilderConfiguration;
import com.tngtech.configbuilder.util.ConfigBuilderFactory;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import java.util.Properties;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.when;
package com.tngtech.configbuilder.annotation.valueextractor;
@RunWith(MockitoJUnitRunner.class)
public class PropertyValueProcessorTest {
private PropertyValueProcessor propertyValueProcessor;
@Mock | private BuilderConfiguration builderConfiguration; |
bmatthias/config-builder | src/test/java/com/tngtech/configbuilder/annotation/valueextractor/PropertyValueProcessorTest.java | // Path: src/main/java/com/tngtech/configbuilder/configuration/BuilderConfiguration.java
// public class BuilderConfiguration {
//
// private Properties properties;
// private CommandLine commandLine;
// private Object importedConfiguration;
// private Class<? extends Annotation>[] annotationOrder = new Class[]{CommandLineValue.class, PropertyValue.class, EnvironmentVariableValue.class, SystemPropertyValue.class, ImportedValue.class, DefaultValue.class};
//
// public BuilderConfiguration() {
// properties = new Properties();
// commandLine = null;
// importedConfiguration = null;
// }
//
// public CommandLine getCommandLine() {
// return commandLine;
// }
//
// public Properties getProperties() {
// return properties;
// }
//
// public Object getImportedConfiguration() {
// return importedConfiguration;
// }
//
// public void setProperties(Properties properties) {
// this.properties = properties;
// }
//
// public void setCommandLine(CommandLine commandLine) {
// this.commandLine = commandLine;
// }
//
// public void setImportedConfiguration(Object importedConfiguration) {
// this.importedConfiguration = importedConfiguration;
// }
//
// public void setAnnotationOrder(Class<? extends Annotation>[] annotationOrder) {
// this.annotationOrder = annotationOrder;
// }
//
// public Class<? extends Annotation>[] getAnnotationOrder() {
// return annotationOrder;
// }
// }
//
// Path: src/main/java/com/tngtech/configbuilder/util/ConfigBuilderFactory.java
// public class ConfigBuilderFactory {
//
// private Map<Class,Object> singletonMap = Maps.newHashMap();
//
// public <T> void initialize() {
//
// //Order is IMPORTANT!
//
// //configuration
// singletonMap.put(ErrorMessageSetup.class, new ErrorMessageSetup());
// singletonMap.put(BuilderConfiguration.class, new BuilderConfiguration());
//
// //util
// singletonMap.put(AnnotationHelper.class, new AnnotationHelper());
// singletonMap.put(GenericsAndCastingHelper.class, new GenericsAndCastingHelper());
// singletonMap.put(FieldValueExtractor.class, new FieldValueExtractor(this));
// singletonMap.put(FieldValueTransformer.class, new FieldValueTransformer(this));
// singletonMap.put(PropertyLoaderConfigurator.class, new PropertyLoaderConfigurator(this));
// singletonMap.put(ConstructionHelper.class, new ConstructionHelper<T>(this));
// singletonMap.put(FieldSetter.class, new FieldSetter<T>(this));
// singletonMap.put(ConfigValidator.class, new ConfigValidator<T>(this));
// singletonMap.put(CommandLineHelper.class, new CommandLineHelper(this));
//
// //AnnotationProcessors
// singletonMap.put(SystemPropertyProcessor.class, new SystemPropertyProcessor());
// singletonMap.put(PropertyValueProcessor.class, new PropertyValueProcessor());
// singletonMap.put(EnvironmentVariableProcessor.class, new EnvironmentVariableProcessor());
// singletonMap.put(CommandLineValueProcessor.class, new CommandLineValueProcessor());
// singletonMap.put(PropertySuffixProcessor.class, new PropertySuffixProcessor());
// singletonMap.put(PropertyLocationsProcessor.class, new PropertyLocationsProcessor());
// singletonMap.put(PropertyExtensionProcessor.class, new PropertyExtensionProcessor());
// singletonMap.put(PropertiesFilesProcessor.class, new PropertiesFilesProcessor());
// singletonMap.put(DefaultValueProcessor.class, new DefaultValueProcessor());
//
// //ValueTransformers
// singletonMap.put(StringOrPrimitiveToPrimitiveTransformer.class, new StringOrPrimitiveToPrimitiveTransformer());
// singletonMap.put(CollectionToArrayListTransformer.class, new CollectionToArrayListTransformer());
// singletonMap.put(CollectionToHashSetTransformer.class, new CollectionToHashSetTransformer());
// singletonMap.put(CharacterSeparatedStringToStringListTransformer.class, new CharacterSeparatedStringToStringListTransformer());
// singletonMap.put(CharacterSeparatedStringToStringSetTransformer.class, new CharacterSeparatedStringToStringSetTransformer());
// singletonMap.put(StringCollectionToCommaSeparatedStringTransformer.class, new StringCollectionToCommaSeparatedStringTransformer());
// singletonMap.put(StringToPathTransformer.class, new StringToPathTransformer());
//
// //other
// singletonMap.put(ValidatorFactory.class, Validation.buildDefaultValidatorFactory());
// }
//
// public <K> K getInstance(Class<K> clazz) {
// if(singletonMap.get(clazz) != null) {
// return (K)singletonMap.get(clazz);
// }
// else {
// return createInstance(clazz);
// }
// }
//
// //TODO: exception message
// public <K> K createInstance(Class<K> clazz) {
// try {
// return clazz.newInstance();
// } catch (IllegalAccessException e) {
// ErrorMessageSetup errorMessageSetup = (ErrorMessageSetup)singletonMap.get(ErrorMessageSetup.class);
// throw new FactoryInstantiationException(errorMessageSetup.getErrorMessage(FactoryInstantiationException.class, clazz.toString()));
// } catch (InstantiationException e) {
// return createInstanceOfInnerClass(clazz);
// }
// }
//
// //TODO: exception message
// private <K> K createInstanceOfInnerClass(Class<K> clazz) {
// Class superClass = clazz.getDeclaringClass();
// try {
// Object superInstance = superClass.newInstance();
// Constructor<K> constructor = clazz.getConstructor(superClass);
// return constructor.newInstance(superInstance);
// } catch (Exception e) {
// ErrorMessageSetup errorMessageSetup = (ErrorMessageSetup)singletonMap.get(ErrorMessageSetup.class);
// throw new FactoryInstantiationException(errorMessageSetup.getErrorMessage(FactoryInstantiationException.class, clazz.toString()));
// }
// }
// }
| import com.tngtech.configbuilder.configuration.BuilderConfiguration;
import com.tngtech.configbuilder.util.ConfigBuilderFactory;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import java.util.Properties;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.when; | package com.tngtech.configbuilder.annotation.valueextractor;
@RunWith(MockitoJUnitRunner.class)
public class PropertyValueProcessorTest {
private PropertyValueProcessor propertyValueProcessor;
@Mock
private BuilderConfiguration builderConfiguration;
@Mock | // Path: src/main/java/com/tngtech/configbuilder/configuration/BuilderConfiguration.java
// public class BuilderConfiguration {
//
// private Properties properties;
// private CommandLine commandLine;
// private Object importedConfiguration;
// private Class<? extends Annotation>[] annotationOrder = new Class[]{CommandLineValue.class, PropertyValue.class, EnvironmentVariableValue.class, SystemPropertyValue.class, ImportedValue.class, DefaultValue.class};
//
// public BuilderConfiguration() {
// properties = new Properties();
// commandLine = null;
// importedConfiguration = null;
// }
//
// public CommandLine getCommandLine() {
// return commandLine;
// }
//
// public Properties getProperties() {
// return properties;
// }
//
// public Object getImportedConfiguration() {
// return importedConfiguration;
// }
//
// public void setProperties(Properties properties) {
// this.properties = properties;
// }
//
// public void setCommandLine(CommandLine commandLine) {
// this.commandLine = commandLine;
// }
//
// public void setImportedConfiguration(Object importedConfiguration) {
// this.importedConfiguration = importedConfiguration;
// }
//
// public void setAnnotationOrder(Class<? extends Annotation>[] annotationOrder) {
// this.annotationOrder = annotationOrder;
// }
//
// public Class<? extends Annotation>[] getAnnotationOrder() {
// return annotationOrder;
// }
// }
//
// Path: src/main/java/com/tngtech/configbuilder/util/ConfigBuilderFactory.java
// public class ConfigBuilderFactory {
//
// private Map<Class,Object> singletonMap = Maps.newHashMap();
//
// public <T> void initialize() {
//
// //Order is IMPORTANT!
//
// //configuration
// singletonMap.put(ErrorMessageSetup.class, new ErrorMessageSetup());
// singletonMap.put(BuilderConfiguration.class, new BuilderConfiguration());
//
// //util
// singletonMap.put(AnnotationHelper.class, new AnnotationHelper());
// singletonMap.put(GenericsAndCastingHelper.class, new GenericsAndCastingHelper());
// singletonMap.put(FieldValueExtractor.class, new FieldValueExtractor(this));
// singletonMap.put(FieldValueTransformer.class, new FieldValueTransformer(this));
// singletonMap.put(PropertyLoaderConfigurator.class, new PropertyLoaderConfigurator(this));
// singletonMap.put(ConstructionHelper.class, new ConstructionHelper<T>(this));
// singletonMap.put(FieldSetter.class, new FieldSetter<T>(this));
// singletonMap.put(ConfigValidator.class, new ConfigValidator<T>(this));
// singletonMap.put(CommandLineHelper.class, new CommandLineHelper(this));
//
// //AnnotationProcessors
// singletonMap.put(SystemPropertyProcessor.class, new SystemPropertyProcessor());
// singletonMap.put(PropertyValueProcessor.class, new PropertyValueProcessor());
// singletonMap.put(EnvironmentVariableProcessor.class, new EnvironmentVariableProcessor());
// singletonMap.put(CommandLineValueProcessor.class, new CommandLineValueProcessor());
// singletonMap.put(PropertySuffixProcessor.class, new PropertySuffixProcessor());
// singletonMap.put(PropertyLocationsProcessor.class, new PropertyLocationsProcessor());
// singletonMap.put(PropertyExtensionProcessor.class, new PropertyExtensionProcessor());
// singletonMap.put(PropertiesFilesProcessor.class, new PropertiesFilesProcessor());
// singletonMap.put(DefaultValueProcessor.class, new DefaultValueProcessor());
//
// //ValueTransformers
// singletonMap.put(StringOrPrimitiveToPrimitiveTransformer.class, new StringOrPrimitiveToPrimitiveTransformer());
// singletonMap.put(CollectionToArrayListTransformer.class, new CollectionToArrayListTransformer());
// singletonMap.put(CollectionToHashSetTransformer.class, new CollectionToHashSetTransformer());
// singletonMap.put(CharacterSeparatedStringToStringListTransformer.class, new CharacterSeparatedStringToStringListTransformer());
// singletonMap.put(CharacterSeparatedStringToStringSetTransformer.class, new CharacterSeparatedStringToStringSetTransformer());
// singletonMap.put(StringCollectionToCommaSeparatedStringTransformer.class, new StringCollectionToCommaSeparatedStringTransformer());
// singletonMap.put(StringToPathTransformer.class, new StringToPathTransformer());
//
// //other
// singletonMap.put(ValidatorFactory.class, Validation.buildDefaultValidatorFactory());
// }
//
// public <K> K getInstance(Class<K> clazz) {
// if(singletonMap.get(clazz) != null) {
// return (K)singletonMap.get(clazz);
// }
// else {
// return createInstance(clazz);
// }
// }
//
// //TODO: exception message
// public <K> K createInstance(Class<K> clazz) {
// try {
// return clazz.newInstance();
// } catch (IllegalAccessException e) {
// ErrorMessageSetup errorMessageSetup = (ErrorMessageSetup)singletonMap.get(ErrorMessageSetup.class);
// throw new FactoryInstantiationException(errorMessageSetup.getErrorMessage(FactoryInstantiationException.class, clazz.toString()));
// } catch (InstantiationException e) {
// return createInstanceOfInnerClass(clazz);
// }
// }
//
// //TODO: exception message
// private <K> K createInstanceOfInnerClass(Class<K> clazz) {
// Class superClass = clazz.getDeclaringClass();
// try {
// Object superInstance = superClass.newInstance();
// Constructor<K> constructor = clazz.getConstructor(superClass);
// return constructor.newInstance(superInstance);
// } catch (Exception e) {
// ErrorMessageSetup errorMessageSetup = (ErrorMessageSetup)singletonMap.get(ErrorMessageSetup.class);
// throw new FactoryInstantiationException(errorMessageSetup.getErrorMessage(FactoryInstantiationException.class, clazz.toString()));
// }
// }
// }
// Path: src/test/java/com/tngtech/configbuilder/annotation/valueextractor/PropertyValueProcessorTest.java
import com.tngtech.configbuilder.configuration.BuilderConfiguration;
import com.tngtech.configbuilder.util.ConfigBuilderFactory;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import java.util.Properties;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.when;
package com.tngtech.configbuilder.annotation.valueextractor;
@RunWith(MockitoJUnitRunner.class)
public class PropertyValueProcessorTest {
private PropertyValueProcessor propertyValueProcessor;
@Mock
private BuilderConfiguration builderConfiguration;
@Mock | private ConfigBuilderFactory configBuilderFactory; |
bmatthias/config-builder | src/test/java/com/tngtech/configbuilder/annotation/valueextractor/CommandLineValueProcessorTest.java | // Path: src/main/java/com/tngtech/configbuilder/configuration/BuilderConfiguration.java
// public class BuilderConfiguration {
//
// private Properties properties;
// private CommandLine commandLine;
// private Object importedConfiguration;
// private Class<? extends Annotation>[] annotationOrder = new Class[]{CommandLineValue.class, PropertyValue.class, EnvironmentVariableValue.class, SystemPropertyValue.class, ImportedValue.class, DefaultValue.class};
//
// public BuilderConfiguration() {
// properties = new Properties();
// commandLine = null;
// importedConfiguration = null;
// }
//
// public CommandLine getCommandLine() {
// return commandLine;
// }
//
// public Properties getProperties() {
// return properties;
// }
//
// public Object getImportedConfiguration() {
// return importedConfiguration;
// }
//
// public void setProperties(Properties properties) {
// this.properties = properties;
// }
//
// public void setCommandLine(CommandLine commandLine) {
// this.commandLine = commandLine;
// }
//
// public void setImportedConfiguration(Object importedConfiguration) {
// this.importedConfiguration = importedConfiguration;
// }
//
// public void setAnnotationOrder(Class<? extends Annotation>[] annotationOrder) {
// this.annotationOrder = annotationOrder;
// }
//
// public Class<? extends Annotation>[] getAnnotationOrder() {
// return annotationOrder;
// }
// }
//
// Path: src/main/java/com/tngtech/configbuilder/util/ConfigBuilderFactory.java
// public class ConfigBuilderFactory {
//
// private Map<Class,Object> singletonMap = Maps.newHashMap();
//
// public <T> void initialize() {
//
// //Order is IMPORTANT!
//
// //configuration
// singletonMap.put(ErrorMessageSetup.class, new ErrorMessageSetup());
// singletonMap.put(BuilderConfiguration.class, new BuilderConfiguration());
//
// //util
// singletonMap.put(AnnotationHelper.class, new AnnotationHelper());
// singletonMap.put(GenericsAndCastingHelper.class, new GenericsAndCastingHelper());
// singletonMap.put(FieldValueExtractor.class, new FieldValueExtractor(this));
// singletonMap.put(FieldValueTransformer.class, new FieldValueTransformer(this));
// singletonMap.put(PropertyLoaderConfigurator.class, new PropertyLoaderConfigurator(this));
// singletonMap.put(ConstructionHelper.class, new ConstructionHelper<T>(this));
// singletonMap.put(FieldSetter.class, new FieldSetter<T>(this));
// singletonMap.put(ConfigValidator.class, new ConfigValidator<T>(this));
// singletonMap.put(CommandLineHelper.class, new CommandLineHelper(this));
//
// //AnnotationProcessors
// singletonMap.put(SystemPropertyProcessor.class, new SystemPropertyProcessor());
// singletonMap.put(PropertyValueProcessor.class, new PropertyValueProcessor());
// singletonMap.put(EnvironmentVariableProcessor.class, new EnvironmentVariableProcessor());
// singletonMap.put(CommandLineValueProcessor.class, new CommandLineValueProcessor());
// singletonMap.put(PropertySuffixProcessor.class, new PropertySuffixProcessor());
// singletonMap.put(PropertyLocationsProcessor.class, new PropertyLocationsProcessor());
// singletonMap.put(PropertyExtensionProcessor.class, new PropertyExtensionProcessor());
// singletonMap.put(PropertiesFilesProcessor.class, new PropertiesFilesProcessor());
// singletonMap.put(DefaultValueProcessor.class, new DefaultValueProcessor());
//
// //ValueTransformers
// singletonMap.put(StringOrPrimitiveToPrimitiveTransformer.class, new StringOrPrimitiveToPrimitiveTransformer());
// singletonMap.put(CollectionToArrayListTransformer.class, new CollectionToArrayListTransformer());
// singletonMap.put(CollectionToHashSetTransformer.class, new CollectionToHashSetTransformer());
// singletonMap.put(CharacterSeparatedStringToStringListTransformer.class, new CharacterSeparatedStringToStringListTransformer());
// singletonMap.put(CharacterSeparatedStringToStringSetTransformer.class, new CharacterSeparatedStringToStringSetTransformer());
// singletonMap.put(StringCollectionToCommaSeparatedStringTransformer.class, new StringCollectionToCommaSeparatedStringTransformer());
// singletonMap.put(StringToPathTransformer.class, new StringToPathTransformer());
//
// //other
// singletonMap.put(ValidatorFactory.class, Validation.buildDefaultValidatorFactory());
// }
//
// public <K> K getInstance(Class<K> clazz) {
// if(singletonMap.get(clazz) != null) {
// return (K)singletonMap.get(clazz);
// }
// else {
// return createInstance(clazz);
// }
// }
//
// //TODO: exception message
// public <K> K createInstance(Class<K> clazz) {
// try {
// return clazz.newInstance();
// } catch (IllegalAccessException e) {
// ErrorMessageSetup errorMessageSetup = (ErrorMessageSetup)singletonMap.get(ErrorMessageSetup.class);
// throw new FactoryInstantiationException(errorMessageSetup.getErrorMessage(FactoryInstantiationException.class, clazz.toString()));
// } catch (InstantiationException e) {
// return createInstanceOfInnerClass(clazz);
// }
// }
//
// //TODO: exception message
// private <K> K createInstanceOfInnerClass(Class<K> clazz) {
// Class superClass = clazz.getDeclaringClass();
// try {
// Object superInstance = superClass.newInstance();
// Constructor<K> constructor = clazz.getConstructor(superClass);
// return constructor.newInstance(superInstance);
// } catch (Exception e) {
// ErrorMessageSetup errorMessageSetup = (ErrorMessageSetup)singletonMap.get(ErrorMessageSetup.class);
// throw new FactoryInstantiationException(errorMessageSetup.getErrorMessage(FactoryInstantiationException.class, clazz.toString()));
// }
// }
// }
| import com.tngtech.configbuilder.configuration.BuilderConfiguration;
import com.tngtech.configbuilder.util.ConfigBuilderFactory;
import org.apache.commons.cli.CommandLine;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.when; | package com.tngtech.configbuilder.annotation.valueextractor;
@RunWith(MockitoJUnitRunner.class)
public class CommandLineValueProcessorTest {
private CommandLineValueProcessor commandLineValueProcessor;
@Mock | // Path: src/main/java/com/tngtech/configbuilder/configuration/BuilderConfiguration.java
// public class BuilderConfiguration {
//
// private Properties properties;
// private CommandLine commandLine;
// private Object importedConfiguration;
// private Class<? extends Annotation>[] annotationOrder = new Class[]{CommandLineValue.class, PropertyValue.class, EnvironmentVariableValue.class, SystemPropertyValue.class, ImportedValue.class, DefaultValue.class};
//
// public BuilderConfiguration() {
// properties = new Properties();
// commandLine = null;
// importedConfiguration = null;
// }
//
// public CommandLine getCommandLine() {
// return commandLine;
// }
//
// public Properties getProperties() {
// return properties;
// }
//
// public Object getImportedConfiguration() {
// return importedConfiguration;
// }
//
// public void setProperties(Properties properties) {
// this.properties = properties;
// }
//
// public void setCommandLine(CommandLine commandLine) {
// this.commandLine = commandLine;
// }
//
// public void setImportedConfiguration(Object importedConfiguration) {
// this.importedConfiguration = importedConfiguration;
// }
//
// public void setAnnotationOrder(Class<? extends Annotation>[] annotationOrder) {
// this.annotationOrder = annotationOrder;
// }
//
// public Class<? extends Annotation>[] getAnnotationOrder() {
// return annotationOrder;
// }
// }
//
// Path: src/main/java/com/tngtech/configbuilder/util/ConfigBuilderFactory.java
// public class ConfigBuilderFactory {
//
// private Map<Class,Object> singletonMap = Maps.newHashMap();
//
// public <T> void initialize() {
//
// //Order is IMPORTANT!
//
// //configuration
// singletonMap.put(ErrorMessageSetup.class, new ErrorMessageSetup());
// singletonMap.put(BuilderConfiguration.class, new BuilderConfiguration());
//
// //util
// singletonMap.put(AnnotationHelper.class, new AnnotationHelper());
// singletonMap.put(GenericsAndCastingHelper.class, new GenericsAndCastingHelper());
// singletonMap.put(FieldValueExtractor.class, new FieldValueExtractor(this));
// singletonMap.put(FieldValueTransformer.class, new FieldValueTransformer(this));
// singletonMap.put(PropertyLoaderConfigurator.class, new PropertyLoaderConfigurator(this));
// singletonMap.put(ConstructionHelper.class, new ConstructionHelper<T>(this));
// singletonMap.put(FieldSetter.class, new FieldSetter<T>(this));
// singletonMap.put(ConfigValidator.class, new ConfigValidator<T>(this));
// singletonMap.put(CommandLineHelper.class, new CommandLineHelper(this));
//
// //AnnotationProcessors
// singletonMap.put(SystemPropertyProcessor.class, new SystemPropertyProcessor());
// singletonMap.put(PropertyValueProcessor.class, new PropertyValueProcessor());
// singletonMap.put(EnvironmentVariableProcessor.class, new EnvironmentVariableProcessor());
// singletonMap.put(CommandLineValueProcessor.class, new CommandLineValueProcessor());
// singletonMap.put(PropertySuffixProcessor.class, new PropertySuffixProcessor());
// singletonMap.put(PropertyLocationsProcessor.class, new PropertyLocationsProcessor());
// singletonMap.put(PropertyExtensionProcessor.class, new PropertyExtensionProcessor());
// singletonMap.put(PropertiesFilesProcessor.class, new PropertiesFilesProcessor());
// singletonMap.put(DefaultValueProcessor.class, new DefaultValueProcessor());
//
// //ValueTransformers
// singletonMap.put(StringOrPrimitiveToPrimitiveTransformer.class, new StringOrPrimitiveToPrimitiveTransformer());
// singletonMap.put(CollectionToArrayListTransformer.class, new CollectionToArrayListTransformer());
// singletonMap.put(CollectionToHashSetTransformer.class, new CollectionToHashSetTransformer());
// singletonMap.put(CharacterSeparatedStringToStringListTransformer.class, new CharacterSeparatedStringToStringListTransformer());
// singletonMap.put(CharacterSeparatedStringToStringSetTransformer.class, new CharacterSeparatedStringToStringSetTransformer());
// singletonMap.put(StringCollectionToCommaSeparatedStringTransformer.class, new StringCollectionToCommaSeparatedStringTransformer());
// singletonMap.put(StringToPathTransformer.class, new StringToPathTransformer());
//
// //other
// singletonMap.put(ValidatorFactory.class, Validation.buildDefaultValidatorFactory());
// }
//
// public <K> K getInstance(Class<K> clazz) {
// if(singletonMap.get(clazz) != null) {
// return (K)singletonMap.get(clazz);
// }
// else {
// return createInstance(clazz);
// }
// }
//
// //TODO: exception message
// public <K> K createInstance(Class<K> clazz) {
// try {
// return clazz.newInstance();
// } catch (IllegalAccessException e) {
// ErrorMessageSetup errorMessageSetup = (ErrorMessageSetup)singletonMap.get(ErrorMessageSetup.class);
// throw new FactoryInstantiationException(errorMessageSetup.getErrorMessage(FactoryInstantiationException.class, clazz.toString()));
// } catch (InstantiationException e) {
// return createInstanceOfInnerClass(clazz);
// }
// }
//
// //TODO: exception message
// private <K> K createInstanceOfInnerClass(Class<K> clazz) {
// Class superClass = clazz.getDeclaringClass();
// try {
// Object superInstance = superClass.newInstance();
// Constructor<K> constructor = clazz.getConstructor(superClass);
// return constructor.newInstance(superInstance);
// } catch (Exception e) {
// ErrorMessageSetup errorMessageSetup = (ErrorMessageSetup)singletonMap.get(ErrorMessageSetup.class);
// throw new FactoryInstantiationException(errorMessageSetup.getErrorMessage(FactoryInstantiationException.class, clazz.toString()));
// }
// }
// }
// Path: src/test/java/com/tngtech/configbuilder/annotation/valueextractor/CommandLineValueProcessorTest.java
import com.tngtech.configbuilder.configuration.BuilderConfiguration;
import com.tngtech.configbuilder.util.ConfigBuilderFactory;
import org.apache.commons.cli.CommandLine;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.when;
package com.tngtech.configbuilder.annotation.valueextractor;
@RunWith(MockitoJUnitRunner.class)
public class CommandLineValueProcessorTest {
private CommandLineValueProcessor commandLineValueProcessor;
@Mock | private BuilderConfiguration builderConfiguration; |
bmatthias/config-builder | src/test/java/com/tngtech/configbuilder/annotation/valueextractor/CommandLineValueProcessorTest.java | // Path: src/main/java/com/tngtech/configbuilder/configuration/BuilderConfiguration.java
// public class BuilderConfiguration {
//
// private Properties properties;
// private CommandLine commandLine;
// private Object importedConfiguration;
// private Class<? extends Annotation>[] annotationOrder = new Class[]{CommandLineValue.class, PropertyValue.class, EnvironmentVariableValue.class, SystemPropertyValue.class, ImportedValue.class, DefaultValue.class};
//
// public BuilderConfiguration() {
// properties = new Properties();
// commandLine = null;
// importedConfiguration = null;
// }
//
// public CommandLine getCommandLine() {
// return commandLine;
// }
//
// public Properties getProperties() {
// return properties;
// }
//
// public Object getImportedConfiguration() {
// return importedConfiguration;
// }
//
// public void setProperties(Properties properties) {
// this.properties = properties;
// }
//
// public void setCommandLine(CommandLine commandLine) {
// this.commandLine = commandLine;
// }
//
// public void setImportedConfiguration(Object importedConfiguration) {
// this.importedConfiguration = importedConfiguration;
// }
//
// public void setAnnotationOrder(Class<? extends Annotation>[] annotationOrder) {
// this.annotationOrder = annotationOrder;
// }
//
// public Class<? extends Annotation>[] getAnnotationOrder() {
// return annotationOrder;
// }
// }
//
// Path: src/main/java/com/tngtech/configbuilder/util/ConfigBuilderFactory.java
// public class ConfigBuilderFactory {
//
// private Map<Class,Object> singletonMap = Maps.newHashMap();
//
// public <T> void initialize() {
//
// //Order is IMPORTANT!
//
// //configuration
// singletonMap.put(ErrorMessageSetup.class, new ErrorMessageSetup());
// singletonMap.put(BuilderConfiguration.class, new BuilderConfiguration());
//
// //util
// singletonMap.put(AnnotationHelper.class, new AnnotationHelper());
// singletonMap.put(GenericsAndCastingHelper.class, new GenericsAndCastingHelper());
// singletonMap.put(FieldValueExtractor.class, new FieldValueExtractor(this));
// singletonMap.put(FieldValueTransformer.class, new FieldValueTransformer(this));
// singletonMap.put(PropertyLoaderConfigurator.class, new PropertyLoaderConfigurator(this));
// singletonMap.put(ConstructionHelper.class, new ConstructionHelper<T>(this));
// singletonMap.put(FieldSetter.class, new FieldSetter<T>(this));
// singletonMap.put(ConfigValidator.class, new ConfigValidator<T>(this));
// singletonMap.put(CommandLineHelper.class, new CommandLineHelper(this));
//
// //AnnotationProcessors
// singletonMap.put(SystemPropertyProcessor.class, new SystemPropertyProcessor());
// singletonMap.put(PropertyValueProcessor.class, new PropertyValueProcessor());
// singletonMap.put(EnvironmentVariableProcessor.class, new EnvironmentVariableProcessor());
// singletonMap.put(CommandLineValueProcessor.class, new CommandLineValueProcessor());
// singletonMap.put(PropertySuffixProcessor.class, new PropertySuffixProcessor());
// singletonMap.put(PropertyLocationsProcessor.class, new PropertyLocationsProcessor());
// singletonMap.put(PropertyExtensionProcessor.class, new PropertyExtensionProcessor());
// singletonMap.put(PropertiesFilesProcessor.class, new PropertiesFilesProcessor());
// singletonMap.put(DefaultValueProcessor.class, new DefaultValueProcessor());
//
// //ValueTransformers
// singletonMap.put(StringOrPrimitiveToPrimitiveTransformer.class, new StringOrPrimitiveToPrimitiveTransformer());
// singletonMap.put(CollectionToArrayListTransformer.class, new CollectionToArrayListTransformer());
// singletonMap.put(CollectionToHashSetTransformer.class, new CollectionToHashSetTransformer());
// singletonMap.put(CharacterSeparatedStringToStringListTransformer.class, new CharacterSeparatedStringToStringListTransformer());
// singletonMap.put(CharacterSeparatedStringToStringSetTransformer.class, new CharacterSeparatedStringToStringSetTransformer());
// singletonMap.put(StringCollectionToCommaSeparatedStringTransformer.class, new StringCollectionToCommaSeparatedStringTransformer());
// singletonMap.put(StringToPathTransformer.class, new StringToPathTransformer());
//
// //other
// singletonMap.put(ValidatorFactory.class, Validation.buildDefaultValidatorFactory());
// }
//
// public <K> K getInstance(Class<K> clazz) {
// if(singletonMap.get(clazz) != null) {
// return (K)singletonMap.get(clazz);
// }
// else {
// return createInstance(clazz);
// }
// }
//
// //TODO: exception message
// public <K> K createInstance(Class<K> clazz) {
// try {
// return clazz.newInstance();
// } catch (IllegalAccessException e) {
// ErrorMessageSetup errorMessageSetup = (ErrorMessageSetup)singletonMap.get(ErrorMessageSetup.class);
// throw new FactoryInstantiationException(errorMessageSetup.getErrorMessage(FactoryInstantiationException.class, clazz.toString()));
// } catch (InstantiationException e) {
// return createInstanceOfInnerClass(clazz);
// }
// }
//
// //TODO: exception message
// private <K> K createInstanceOfInnerClass(Class<K> clazz) {
// Class superClass = clazz.getDeclaringClass();
// try {
// Object superInstance = superClass.newInstance();
// Constructor<K> constructor = clazz.getConstructor(superClass);
// return constructor.newInstance(superInstance);
// } catch (Exception e) {
// ErrorMessageSetup errorMessageSetup = (ErrorMessageSetup)singletonMap.get(ErrorMessageSetup.class);
// throw new FactoryInstantiationException(errorMessageSetup.getErrorMessage(FactoryInstantiationException.class, clazz.toString()));
// }
// }
// }
| import com.tngtech.configbuilder.configuration.BuilderConfiguration;
import com.tngtech.configbuilder.util.ConfigBuilderFactory;
import org.apache.commons.cli.CommandLine;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.when; | package com.tngtech.configbuilder.annotation.valueextractor;
@RunWith(MockitoJUnitRunner.class)
public class CommandLineValueProcessorTest {
private CommandLineValueProcessor commandLineValueProcessor;
@Mock
private BuilderConfiguration builderConfiguration;
@Mock | // Path: src/main/java/com/tngtech/configbuilder/configuration/BuilderConfiguration.java
// public class BuilderConfiguration {
//
// private Properties properties;
// private CommandLine commandLine;
// private Object importedConfiguration;
// private Class<? extends Annotation>[] annotationOrder = new Class[]{CommandLineValue.class, PropertyValue.class, EnvironmentVariableValue.class, SystemPropertyValue.class, ImportedValue.class, DefaultValue.class};
//
// public BuilderConfiguration() {
// properties = new Properties();
// commandLine = null;
// importedConfiguration = null;
// }
//
// public CommandLine getCommandLine() {
// return commandLine;
// }
//
// public Properties getProperties() {
// return properties;
// }
//
// public Object getImportedConfiguration() {
// return importedConfiguration;
// }
//
// public void setProperties(Properties properties) {
// this.properties = properties;
// }
//
// public void setCommandLine(CommandLine commandLine) {
// this.commandLine = commandLine;
// }
//
// public void setImportedConfiguration(Object importedConfiguration) {
// this.importedConfiguration = importedConfiguration;
// }
//
// public void setAnnotationOrder(Class<? extends Annotation>[] annotationOrder) {
// this.annotationOrder = annotationOrder;
// }
//
// public Class<? extends Annotation>[] getAnnotationOrder() {
// return annotationOrder;
// }
// }
//
// Path: src/main/java/com/tngtech/configbuilder/util/ConfigBuilderFactory.java
// public class ConfigBuilderFactory {
//
// private Map<Class,Object> singletonMap = Maps.newHashMap();
//
// public <T> void initialize() {
//
// //Order is IMPORTANT!
//
// //configuration
// singletonMap.put(ErrorMessageSetup.class, new ErrorMessageSetup());
// singletonMap.put(BuilderConfiguration.class, new BuilderConfiguration());
//
// //util
// singletonMap.put(AnnotationHelper.class, new AnnotationHelper());
// singletonMap.put(GenericsAndCastingHelper.class, new GenericsAndCastingHelper());
// singletonMap.put(FieldValueExtractor.class, new FieldValueExtractor(this));
// singletonMap.put(FieldValueTransformer.class, new FieldValueTransformer(this));
// singletonMap.put(PropertyLoaderConfigurator.class, new PropertyLoaderConfigurator(this));
// singletonMap.put(ConstructionHelper.class, new ConstructionHelper<T>(this));
// singletonMap.put(FieldSetter.class, new FieldSetter<T>(this));
// singletonMap.put(ConfigValidator.class, new ConfigValidator<T>(this));
// singletonMap.put(CommandLineHelper.class, new CommandLineHelper(this));
//
// //AnnotationProcessors
// singletonMap.put(SystemPropertyProcessor.class, new SystemPropertyProcessor());
// singletonMap.put(PropertyValueProcessor.class, new PropertyValueProcessor());
// singletonMap.put(EnvironmentVariableProcessor.class, new EnvironmentVariableProcessor());
// singletonMap.put(CommandLineValueProcessor.class, new CommandLineValueProcessor());
// singletonMap.put(PropertySuffixProcessor.class, new PropertySuffixProcessor());
// singletonMap.put(PropertyLocationsProcessor.class, new PropertyLocationsProcessor());
// singletonMap.put(PropertyExtensionProcessor.class, new PropertyExtensionProcessor());
// singletonMap.put(PropertiesFilesProcessor.class, new PropertiesFilesProcessor());
// singletonMap.put(DefaultValueProcessor.class, new DefaultValueProcessor());
//
// //ValueTransformers
// singletonMap.put(StringOrPrimitiveToPrimitiveTransformer.class, new StringOrPrimitiveToPrimitiveTransformer());
// singletonMap.put(CollectionToArrayListTransformer.class, new CollectionToArrayListTransformer());
// singletonMap.put(CollectionToHashSetTransformer.class, new CollectionToHashSetTransformer());
// singletonMap.put(CharacterSeparatedStringToStringListTransformer.class, new CharacterSeparatedStringToStringListTransformer());
// singletonMap.put(CharacterSeparatedStringToStringSetTransformer.class, new CharacterSeparatedStringToStringSetTransformer());
// singletonMap.put(StringCollectionToCommaSeparatedStringTransformer.class, new StringCollectionToCommaSeparatedStringTransformer());
// singletonMap.put(StringToPathTransformer.class, new StringToPathTransformer());
//
// //other
// singletonMap.put(ValidatorFactory.class, Validation.buildDefaultValidatorFactory());
// }
//
// public <K> K getInstance(Class<K> clazz) {
// if(singletonMap.get(clazz) != null) {
// return (K)singletonMap.get(clazz);
// }
// else {
// return createInstance(clazz);
// }
// }
//
// //TODO: exception message
// public <K> K createInstance(Class<K> clazz) {
// try {
// return clazz.newInstance();
// } catch (IllegalAccessException e) {
// ErrorMessageSetup errorMessageSetup = (ErrorMessageSetup)singletonMap.get(ErrorMessageSetup.class);
// throw new FactoryInstantiationException(errorMessageSetup.getErrorMessage(FactoryInstantiationException.class, clazz.toString()));
// } catch (InstantiationException e) {
// return createInstanceOfInnerClass(clazz);
// }
// }
//
// //TODO: exception message
// private <K> K createInstanceOfInnerClass(Class<K> clazz) {
// Class superClass = clazz.getDeclaringClass();
// try {
// Object superInstance = superClass.newInstance();
// Constructor<K> constructor = clazz.getConstructor(superClass);
// return constructor.newInstance(superInstance);
// } catch (Exception e) {
// ErrorMessageSetup errorMessageSetup = (ErrorMessageSetup)singletonMap.get(ErrorMessageSetup.class);
// throw new FactoryInstantiationException(errorMessageSetup.getErrorMessage(FactoryInstantiationException.class, clazz.toString()));
// }
// }
// }
// Path: src/test/java/com/tngtech/configbuilder/annotation/valueextractor/CommandLineValueProcessorTest.java
import com.tngtech.configbuilder.configuration.BuilderConfiguration;
import com.tngtech.configbuilder.util.ConfigBuilderFactory;
import org.apache.commons.cli.CommandLine;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.when;
package com.tngtech.configbuilder.annotation.valueextractor;
@RunWith(MockitoJUnitRunner.class)
public class CommandLineValueProcessorTest {
private CommandLineValueProcessor commandLineValueProcessor;
@Mock
private BuilderConfiguration builderConfiguration;
@Mock | private ConfigBuilderFactory configBuilderFactory; |
padster/Muse-EEG-Toolkit | eegtoolkit/src/main/java/eeg/useit/today/eegtoolkit/vm/ConnectionStrengthViewModel.java | // Path: eegtoolkit/src/main/java/eeg/useit/today/eegtoolkit/Constants.java
// public class Constants {
// public static final String TAG = "EEGToolkit";
// public static final String RECORDING_PREFIX = "data";
//
// // HACK: Should configure these elsewhere, perhaps attributes to renderers.
// public static final double VOLTAGE_MAX = 1000.0;
// public static final double VOLTAGE_MIN = 700.0;
// }
//
// Path: eegtoolkit/src/main/java/eeg/useit/today/eegtoolkit/common/BaseDataPacketListener.java
// public abstract class BaseDataPacketListener extends MuseDataListener {
// @Override
// public void receiveMuseArtifactPacket(MuseArtifactPacket museArtifactPacket, Muse muse) {
// // NO-OP, artifact packet ignored.
// }
// }
//
// Path: eegtoolkit/src/main/java/eeg/useit/today/eegtoolkit/model/LiveSeries.java
// public interface LiveSeries<T> {
// /** API for callback invoked when a live series has new data. */
// interface Listener<U> {
// void valueAdded(long timestampMicro, U data);
// }
//
// void addListener(Listener<T> listener);
// }
| import android.databinding.BaseObservable;
import android.util.Log;
import com.choosemuse.libmuse.Eeg;
import com.choosemuse.libmuse.Muse;
import com.choosemuse.libmuse.MuseDataListener;
import com.choosemuse.libmuse.MuseDataPacket;
import com.choosemuse.libmuse.MuseDataPacketType;
import java.util.ArrayList;
import java.util.List;
import eeg.useit.today.eegtoolkit.Constants;
import eeg.useit.today.eegtoolkit.common.BaseDataPacketListener;
import eeg.useit.today.eegtoolkit.model.LiveSeries; | package eeg.useit.today.eegtoolkit.vm;
/**
* Represents the most recent connection strength status indicator values for the four sensors,
* normalized to 0 = bad, 1 = perfect.
*/
public class ConnectionStrengthViewModel extends BaseObservable implements LiveSeries<Double[]> {
private List<Listener<Double[]>> listeners = new ArrayList<>();
/** Most recent snapshot of values. */
private Double[] currentValue = new Double[]{0., 0., 0., 0.};
/** Creates the VM by updating from the device's HSI values. */
public ConnectionStrengthViewModel(StreamingDeviceViewModel deviceVM) { | // Path: eegtoolkit/src/main/java/eeg/useit/today/eegtoolkit/Constants.java
// public class Constants {
// public static final String TAG = "EEGToolkit";
// public static final String RECORDING_PREFIX = "data";
//
// // HACK: Should configure these elsewhere, perhaps attributes to renderers.
// public static final double VOLTAGE_MAX = 1000.0;
// public static final double VOLTAGE_MIN = 700.0;
// }
//
// Path: eegtoolkit/src/main/java/eeg/useit/today/eegtoolkit/common/BaseDataPacketListener.java
// public abstract class BaseDataPacketListener extends MuseDataListener {
// @Override
// public void receiveMuseArtifactPacket(MuseArtifactPacket museArtifactPacket, Muse muse) {
// // NO-OP, artifact packet ignored.
// }
// }
//
// Path: eegtoolkit/src/main/java/eeg/useit/today/eegtoolkit/model/LiveSeries.java
// public interface LiveSeries<T> {
// /** API for callback invoked when a live series has new data. */
// interface Listener<U> {
// void valueAdded(long timestampMicro, U data);
// }
//
// void addListener(Listener<T> listener);
// }
// Path: eegtoolkit/src/main/java/eeg/useit/today/eegtoolkit/vm/ConnectionStrengthViewModel.java
import android.databinding.BaseObservable;
import android.util.Log;
import com.choosemuse.libmuse.Eeg;
import com.choosemuse.libmuse.Muse;
import com.choosemuse.libmuse.MuseDataListener;
import com.choosemuse.libmuse.MuseDataPacket;
import com.choosemuse.libmuse.MuseDataPacketType;
import java.util.ArrayList;
import java.util.List;
import eeg.useit.today.eegtoolkit.Constants;
import eeg.useit.today.eegtoolkit.common.BaseDataPacketListener;
import eeg.useit.today.eegtoolkit.model.LiveSeries;
package eeg.useit.today.eegtoolkit.vm;
/**
* Represents the most recent connection strength status indicator values for the four sensors,
* normalized to 0 = bad, 1 = perfect.
*/
public class ConnectionStrengthViewModel extends BaseObservable implements LiveSeries<Double[]> {
private List<Listener<Double[]>> listeners = new ArrayList<>();
/** Most recent snapshot of values. */
private Double[] currentValue = new Double[]{0., 0., 0., 0.};
/** Creates the VM by updating from the device's HSI values. */
public ConnectionStrengthViewModel(StreamingDeviceViewModel deviceVM) { | deviceVM.registerDataListenerWhenConnected(new BaseDataPacketListener() { |
padster/Muse-EEG-Toolkit | eegtoolkit/src/main/java/eeg/useit/today/eegtoolkit/view/graph/GraphGLLine.java | // Path: eegtoolkit/src/main/java/eeg/useit/today/eegtoolkit/Constants.java
// public class Constants {
// public static final String TAG = "EEGToolkit";
// public static final String RECORDING_PREFIX = "data";
//
// // HACK: Should configure these elsewhere, perhaps attributes to renderers.
// public static final double VOLTAGE_MAX = 1000.0;
// public static final double VOLTAGE_MIN = 700.0;
// }
//
// Path: eegtoolkit/src/main/java/eeg/useit/today/eegtoolkit/model/TimeSeriesSnapshot.java
// public class TimeSeriesSnapshot<T> implements Serializable {
// private static final long serialVersionUID = 1228347767823776957L;
//
// public static final TimeSeriesSnapshot EMPTY =
// new TimeSeriesSnapshot<>(new long[]{}, new Object[]{});
//
// /** Values in the timeseries. */
// public final T[] values;
//
// /** Timestamps of when the values were taken. */
// public final long[] timestamps;
//
// /** Number of values (and timestamps) in the snapshot. */
// public final int length;
//
// /** Creates a snapshot from (time, value) arrays. */
// public TimeSeriesSnapshot(long[] timestamps, T[] values) {
// assert timestamps.length == values.length;
// this.timestamps = timestamps;
// this.values = values;
// this.length = timestamps.length;
// }
// }
| import android.content.Context;
import android.opengl.GLES20;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.FloatBuffer;
import eeg.useit.today.eegtoolkit.Constants;
import eeg.useit.today.eegtoolkit.R;
import eeg.useit.today.eegtoolkit.model.TimeSeriesSnapshot; | package eeg.useit.today.eegtoolkit.view.graph;
/**
* All the wrapper code needed to draw a line in GLES 2.0
* Code based off the android guideline at:
* https://developer.android.com/training/graphics/opengl/index.html
*/
public class GraphGLLine {
static final int VERTEX_STRIDE = 12; // 3 floats per vertex * 4 bytes per float.
// RGBA color of the line
private final float[] color;
// How much time history this graph shows
private final int durationSec;
// GLES handle to the shader program.
private final int programHandle;
/**
* Builds a program that can draw a line of a given color.
*/
public GraphGLLine(Context ctx, float[] color, int durationSec) {
this.color = color;
this.durationSec = durationSec;
// Make program, add shaders, and link:
this.programHandle = GLES20.glCreateProgram();
GLES20.glAttachShader(programHandle,
GraphGLRenderer.loadShader(ctx, R.raw.vertex_shader, GLES20.GL_VERTEX_SHADER));
GLES20.glAttachShader(programHandle,
GraphGLRenderer.loadShader(ctx, R.raw.fragment_shader, GLES20.GL_FRAGMENT_SHADER));
GLES20.glLinkProgram(programHandle);
}
/**
* Draw a snapshot of a live graph.
* @param mvpMatrix
* @param snapshot
*/ | // Path: eegtoolkit/src/main/java/eeg/useit/today/eegtoolkit/Constants.java
// public class Constants {
// public static final String TAG = "EEGToolkit";
// public static final String RECORDING_PREFIX = "data";
//
// // HACK: Should configure these elsewhere, perhaps attributes to renderers.
// public static final double VOLTAGE_MAX = 1000.0;
// public static final double VOLTAGE_MIN = 700.0;
// }
//
// Path: eegtoolkit/src/main/java/eeg/useit/today/eegtoolkit/model/TimeSeriesSnapshot.java
// public class TimeSeriesSnapshot<T> implements Serializable {
// private static final long serialVersionUID = 1228347767823776957L;
//
// public static final TimeSeriesSnapshot EMPTY =
// new TimeSeriesSnapshot<>(new long[]{}, new Object[]{});
//
// /** Values in the timeseries. */
// public final T[] values;
//
// /** Timestamps of when the values were taken. */
// public final long[] timestamps;
//
// /** Number of values (and timestamps) in the snapshot. */
// public final int length;
//
// /** Creates a snapshot from (time, value) arrays. */
// public TimeSeriesSnapshot(long[] timestamps, T[] values) {
// assert timestamps.length == values.length;
// this.timestamps = timestamps;
// this.values = values;
// this.length = timestamps.length;
// }
// }
// Path: eegtoolkit/src/main/java/eeg/useit/today/eegtoolkit/view/graph/GraphGLLine.java
import android.content.Context;
import android.opengl.GLES20;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.FloatBuffer;
import eeg.useit.today.eegtoolkit.Constants;
import eeg.useit.today.eegtoolkit.R;
import eeg.useit.today.eegtoolkit.model.TimeSeriesSnapshot;
package eeg.useit.today.eegtoolkit.view.graph;
/**
* All the wrapper code needed to draw a line in GLES 2.0
* Code based off the android guideline at:
* https://developer.android.com/training/graphics/opengl/index.html
*/
public class GraphGLLine {
static final int VERTEX_STRIDE = 12; // 3 floats per vertex * 4 bytes per float.
// RGBA color of the line
private final float[] color;
// How much time history this graph shows
private final int durationSec;
// GLES handle to the shader program.
private final int programHandle;
/**
* Builds a program that can draw a line of a given color.
*/
public GraphGLLine(Context ctx, float[] color, int durationSec) {
this.color = color;
this.durationSec = durationSec;
// Make program, add shaders, and link:
this.programHandle = GLES20.glCreateProgram();
GLES20.glAttachShader(programHandle,
GraphGLRenderer.loadShader(ctx, R.raw.vertex_shader, GLES20.GL_VERTEX_SHADER));
GLES20.glAttachShader(programHandle,
GraphGLRenderer.loadShader(ctx, R.raw.fragment_shader, GLES20.GL_FRAGMENT_SHADER));
GLES20.glLinkProgram(programHandle);
}
/**
* Draw a snapshot of a live graph.
* @param mvpMatrix
* @param snapshot
*/ | public void draw(float[] mvpMatrix, TimeSeriesSnapshot<Double> snapshot) { |
padster/Muse-EEG-Toolkit | eegtoolkit/src/main/java/eeg/useit/today/eegtoolkit/view/graph/GraphGLLine.java | // Path: eegtoolkit/src/main/java/eeg/useit/today/eegtoolkit/Constants.java
// public class Constants {
// public static final String TAG = "EEGToolkit";
// public static final String RECORDING_PREFIX = "data";
//
// // HACK: Should configure these elsewhere, perhaps attributes to renderers.
// public static final double VOLTAGE_MAX = 1000.0;
// public static final double VOLTAGE_MIN = 700.0;
// }
//
// Path: eegtoolkit/src/main/java/eeg/useit/today/eegtoolkit/model/TimeSeriesSnapshot.java
// public class TimeSeriesSnapshot<T> implements Serializable {
// private static final long serialVersionUID = 1228347767823776957L;
//
// public static final TimeSeriesSnapshot EMPTY =
// new TimeSeriesSnapshot<>(new long[]{}, new Object[]{});
//
// /** Values in the timeseries. */
// public final T[] values;
//
// /** Timestamps of when the values were taken. */
// public final long[] timestamps;
//
// /** Number of values (and timestamps) in the snapshot. */
// public final int length;
//
// /** Creates a snapshot from (time, value) arrays. */
// public TimeSeriesSnapshot(long[] timestamps, T[] values) {
// assert timestamps.length == values.length;
// this.timestamps = timestamps;
// this.values = values;
// this.length = timestamps.length;
// }
// }
| import android.content.Context;
import android.opengl.GLES20;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.FloatBuffer;
import eeg.useit.today.eegtoolkit.Constants;
import eeg.useit.today.eegtoolkit.R;
import eeg.useit.today.eegtoolkit.model.TimeSeriesSnapshot; | /**
* Convert the timeseries snapshot into a run of (real, imag, z) bytes.
*/
private FloatBuffer snapshotToBuffer(TimeSeriesSnapshot snapshot) {
float[] asFloats = snapshotToFloat(snapshot);
// Create buffer to store result.
ByteBuffer bb = ByteBuffer.allocateDirect(snapshot.length * VERTEX_STRIDE);
bb.order(ByteOrder.nativeOrder());
// Write to buffer usign floats:
FloatBuffer vertexBuffer = bb.asFloatBuffer();
vertexBuffer.put(asFloats);
vertexBuffer.position(0);
return vertexBuffer;
}
/**
* Convert the timeseries snapshot into a run of (real, imag, z) floats.
*/
private float[] snapshotToFloat(TimeSeriesSnapshot<Double> snapshot) {
int n = snapshot.length;
// Calculate start and end timestamps
long timeEndMicro = snapshot.timestamps[n - 1];
long timeDelta = this.durationSec * 1000000L;
long timeStartMicro = timeEndMicro - timeDelta;
double timeDeltaInv = 1.0 / (double)timeDelta;
// Bounds for the imag axis: | // Path: eegtoolkit/src/main/java/eeg/useit/today/eegtoolkit/Constants.java
// public class Constants {
// public static final String TAG = "EEGToolkit";
// public static final String RECORDING_PREFIX = "data";
//
// // HACK: Should configure these elsewhere, perhaps attributes to renderers.
// public static final double VOLTAGE_MAX = 1000.0;
// public static final double VOLTAGE_MIN = 700.0;
// }
//
// Path: eegtoolkit/src/main/java/eeg/useit/today/eegtoolkit/model/TimeSeriesSnapshot.java
// public class TimeSeriesSnapshot<T> implements Serializable {
// private static final long serialVersionUID = 1228347767823776957L;
//
// public static final TimeSeriesSnapshot EMPTY =
// new TimeSeriesSnapshot<>(new long[]{}, new Object[]{});
//
// /** Values in the timeseries. */
// public final T[] values;
//
// /** Timestamps of when the values were taken. */
// public final long[] timestamps;
//
// /** Number of values (and timestamps) in the snapshot. */
// public final int length;
//
// /** Creates a snapshot from (time, value) arrays. */
// public TimeSeriesSnapshot(long[] timestamps, T[] values) {
// assert timestamps.length == values.length;
// this.timestamps = timestamps;
// this.values = values;
// this.length = timestamps.length;
// }
// }
// Path: eegtoolkit/src/main/java/eeg/useit/today/eegtoolkit/view/graph/GraphGLLine.java
import android.content.Context;
import android.opengl.GLES20;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.FloatBuffer;
import eeg.useit.today.eegtoolkit.Constants;
import eeg.useit.today.eegtoolkit.R;
import eeg.useit.today.eegtoolkit.model.TimeSeriesSnapshot;
/**
* Convert the timeseries snapshot into a run of (real, imag, z) bytes.
*/
private FloatBuffer snapshotToBuffer(TimeSeriesSnapshot snapshot) {
float[] asFloats = snapshotToFloat(snapshot);
// Create buffer to store result.
ByteBuffer bb = ByteBuffer.allocateDirect(snapshot.length * VERTEX_STRIDE);
bb.order(ByteOrder.nativeOrder());
// Write to buffer usign floats:
FloatBuffer vertexBuffer = bb.asFloatBuffer();
vertexBuffer.put(asFloats);
vertexBuffer.position(0);
return vertexBuffer;
}
/**
* Convert the timeseries snapshot into a run of (real, imag, z) floats.
*/
private float[] snapshotToFloat(TimeSeriesSnapshot<Double> snapshot) {
int n = snapshot.length;
// Calculate start and end timestamps
long timeEndMicro = snapshot.timestamps[n - 1];
long timeDelta = this.durationSec * 1000000L;
long timeStartMicro = timeEndMicro - timeDelta;
double timeDeltaInv = 1.0 / (double)timeDelta;
// Bounds for the imag axis: | double voltMax = Constants.VOLTAGE_MAX; |
padster/Muse-EEG-Toolkit | eegtoolkit/src/main/java/eeg/useit/today/eegtoolkit/vm/MuseListViewModel.java | // Path: eegtoolkit/src/main/java/eeg/useit/today/eegtoolkit/Constants.java
// public class Constants {
// public static final String TAG = "EEGToolkit";
// public static final String RECORDING_PREFIX = "data";
//
// // HACK: Should configure these elsewhere, perhaps attributes to renderers.
// public static final double VOLTAGE_MAX = 1000.0;
// public static final double VOLTAGE_MIN = 700.0;
// }
| import android.databinding.BaseObservable;
import android.databinding.Bindable;
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
import com.choosemuse.libmuse.Muse;
import com.choosemuse.libmuse.MuseManagerAndroid;
import java.util.ArrayList;
import java.util.List;
import eeg.useit.today.eegtoolkit.BR;
import eeg.useit.today.eegtoolkit.Constants; | package eeg.useit.today.eegtoolkit.vm;
/**
* ViewModel for the list of muse devices discovered.
*
* Includes scanning for the devices and updating when new ones are found.
*/
public class MuseListViewModel extends BaseObservable {
/**
* Listener for semantic events fired by the viewmodel.
*/
public interface MuseListListener {
void onScanForDevicesFinished();
void onDeviceSelected(Muse muse);
}
/** Whether we're currently scanning for devices. */
private boolean scanning = false;
/** List of Muse devices found. */
private List<Muse> devices = new ArrayList<>();
/** Listener to be sent events. */
private MuseListListener museListListener = null;
/** @return Whether the list is currently scanning for devices. */
@Bindable
public boolean isScanning() {
return this.scanning;
}
/** @return The list of devices that have been found. */
@Bindable
public List<Muse> getDevices() {
return this.devices;
}
/**
* Scan for devices for a given amount of time, and store all devices found in that period.
*
* @param scanLengthSec How long to scan for, in seconds.
*/
public void scan(int scanLengthSec) {
// Start listening for devices... | // Path: eegtoolkit/src/main/java/eeg/useit/today/eegtoolkit/Constants.java
// public class Constants {
// public static final String TAG = "EEGToolkit";
// public static final String RECORDING_PREFIX = "data";
//
// // HACK: Should configure these elsewhere, perhaps attributes to renderers.
// public static final double VOLTAGE_MAX = 1000.0;
// public static final double VOLTAGE_MIN = 700.0;
// }
// Path: eegtoolkit/src/main/java/eeg/useit/today/eegtoolkit/vm/MuseListViewModel.java
import android.databinding.BaseObservable;
import android.databinding.Bindable;
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
import com.choosemuse.libmuse.Muse;
import com.choosemuse.libmuse.MuseManagerAndroid;
import java.util.ArrayList;
import java.util.List;
import eeg.useit.today.eegtoolkit.BR;
import eeg.useit.today.eegtoolkit.Constants;
package eeg.useit.today.eegtoolkit.vm;
/**
* ViewModel for the list of muse devices discovered.
*
* Includes scanning for the devices and updating when new ones are found.
*/
public class MuseListViewModel extends BaseObservable {
/**
* Listener for semantic events fired by the viewmodel.
*/
public interface MuseListListener {
void onScanForDevicesFinished();
void onDeviceSelected(Muse muse);
}
/** Whether we're currently scanning for devices. */
private boolean scanning = false;
/** List of Muse devices found. */
private List<Muse> devices = new ArrayList<>();
/** Listener to be sent events. */
private MuseListListener museListListener = null;
/** @return Whether the list is currently scanning for devices. */
@Bindable
public boolean isScanning() {
return this.scanning;
}
/** @return The list of devices that have been found. */
@Bindable
public List<Muse> getDevices() {
return this.devices;
}
/**
* Scan for devices for a given amount of time, and store all devices found in that period.
*
* @param scanLengthSec How long to scan for, in seconds.
*/
public void scan(int scanLengthSec) {
// Start listening for devices... | Log.i(Constants.TAG, "Starting scan..."); |
padster/Muse-EEG-Toolkit | eegtoolkit/src/main/java/eeg/useit/today/eegtoolkit/vm/RawChannelViewModel.java | // Path: eegtoolkit/src/main/java/eeg/useit/today/eegtoolkit/common/BaseDataPacketListener.java
// public abstract class BaseDataPacketListener extends MuseDataListener {
// @Override
// public void receiveMuseArtifactPacket(MuseArtifactPacket museArtifactPacket, Muse muse) {
// // NO-OP, artifact packet ignored.
// }
// }
//
// Path: eegtoolkit/src/main/java/eeg/useit/today/eegtoolkit/model/TimeSeries.java
// public class TimeSeries<T> extends BaseObservable implements LiveSeries<T> {
// public static <T> TimeSeries<T> fromMaxAgeMS(long maxAgeMS) {
// return new TimeSeries<T>(maxAgeMS, -1);
// }
// public static <T> TimeSeries<T> fromMaxLength(int maxSampleCount) {
// return new TimeSeries<T>(-1, maxSampleCount);
// }
//
// /** Values within the timeseries. */
// private final CircularArray<T> values = new CircularArray<>();
//
// /** Times at which the values were taken. */
// private final CircularArray<Long> timestampsMicro = new CircularArray<>();
//
// /** Values older than this will be removed. */
// private final long maxAgeMicro;
//
// /** Only store this many values. */
// private final int maxSampleCount;
//
// /** Things interested on when this series changes. */
// private final List<Listener<T>> listeners = new ArrayList<>();
//
// /** Create a timeseries, giving it a maximum age (in ms) length to contain. */
// public TimeSeries(long maxAgeMS) {
// this(maxAgeMS, -1);
// }
//
// /** Create a timeseries, giving either maximum age (in ms) or maximum sample count. */
// public TimeSeries(long maxAgeMS, int maxSampleCount) {
// this.maxAgeMicro = maxAgeMS == -1 ? -1 : maxAgeMS * 1000L;
// this.maxSampleCount = maxSampleCount;
// assert this.maxAgeMicro == -1 ^ this.maxSampleCount == -1;
// }
//
// /** @return Whether the time series has any data. */
// public boolean isEmpty() {
// return values.isEmpty();
// }
//
// /** Pushes a value to the end of the array. */
// public void pushValue(long timestampMicro, T value) {
// synchronized (this) {
// timestampsMicro.addLast(timestampMicro);
// values.addLast(value);
// for (Listener<T> listener : listeners) {
// listener.valueAdded(timestampMicro, value);
// }
// notifyChange();
// }
// }
//
// /**
// * Take a snapshot of the current values, first culling any that are too old.
// */
// public TimeSeriesSnapshot<T> getRecentSnapshot(Class<T> clazz) {
// synchronized (this) {
// if (this.isEmpty()) {
// return TimeSeriesSnapshot.EMPTY;
// }
//
// // First, remove all the old values.
// long finalSnapshot = timestampsMicro.getLast();
// if (maxSampleCount == -1) {
// while (timestampsMicro.getFirst() + maxAgeMicro < finalSnapshot) {
// timestampsMicro.popFirst();
// values.popFirst();
// }
// } else {
// while (timestampsMicro.size() > maxSampleCount) {
// timestampsMicro.popFirst();
// values.popFirst();
// }
// }
//
// // Next, snapshot into arrays and return:
// int n = this.values.size();
// long[] timestamps = new long[n];
// T[] values = (T[]) Array.newInstance(clazz, n);
// for (int i = 0; i < n; i++) {
// timestamps[i] = this.timestampsMicro.get(i);
// values[i] = this.values.get(i);
// }
// return new TimeSeriesSnapshot(timestamps, values);
// }
// }
//
// /**
// * Given a live series, and duration, convert into a TimeSeries with history.
// */
// public static <V> TimeSeries<V> fromLiveSeries(LiveSeries<V> liveSeries, long maxAgeMS) {
// final TimeSeries<V> result = TimeSeries.fromMaxAgeMS(maxAgeMS);
// liveSeries.addListener(new LiveSeries.Listener<V>() {
// @Override public void valueAdded(long timestampMicro, V data) {
// result.pushValue(timestampMicro, data);
// }
// });
// return result;
// }
//
// /**
// * Given a live series, and a smaple count, convert into a TimeSeries with history.
// */
// public static <V> TimeSeries<V> fromLiveSeriesWithCount(LiveSeries<V> liveSeries, int maxLength) {
// final TimeSeries<V> result = TimeSeries.fromMaxLength(maxLength);
// liveSeries.addListener(new LiveSeries.Listener<V>() {
// @Override public void valueAdded(long timestampMicro, V data) {
// result.pushValue(timestampMicro, data);
// }
// });
// return result;
// }
//
// @Override
// public void addListener(Listener<T> listener) {
// this.listeners.add(listener);
// }
// }
| import com.choosemuse.libmuse.Eeg;
import com.choosemuse.libmuse.Muse;
import com.choosemuse.libmuse.MuseDataPacket;
import com.choosemuse.libmuse.MuseDataPacketType;
import eeg.useit.today.eegtoolkit.common.BaseDataPacketListener;
import eeg.useit.today.eegtoolkit.model.TimeSeries; | package eeg.useit.today.eegtoolkit.vm;
/**
* Given a device and a raw channel, present that channel's data as a TimeSeries.
*/
public class RawChannelViewModel extends TimeSeries<Double> {
public RawChannelViewModel(
StreamingDeviceViewModel device,
final Eeg channel,
long maxAgeMS,
int maxSampleCount
) {
super(maxAgeMS, maxSampleCount);
// Add listener to streaming device, use new values to update timeseries.
// TODO: Unregister when device stops, or on disposal. | // Path: eegtoolkit/src/main/java/eeg/useit/today/eegtoolkit/common/BaseDataPacketListener.java
// public abstract class BaseDataPacketListener extends MuseDataListener {
// @Override
// public void receiveMuseArtifactPacket(MuseArtifactPacket museArtifactPacket, Muse muse) {
// // NO-OP, artifact packet ignored.
// }
// }
//
// Path: eegtoolkit/src/main/java/eeg/useit/today/eegtoolkit/model/TimeSeries.java
// public class TimeSeries<T> extends BaseObservable implements LiveSeries<T> {
// public static <T> TimeSeries<T> fromMaxAgeMS(long maxAgeMS) {
// return new TimeSeries<T>(maxAgeMS, -1);
// }
// public static <T> TimeSeries<T> fromMaxLength(int maxSampleCount) {
// return new TimeSeries<T>(-1, maxSampleCount);
// }
//
// /** Values within the timeseries. */
// private final CircularArray<T> values = new CircularArray<>();
//
// /** Times at which the values were taken. */
// private final CircularArray<Long> timestampsMicro = new CircularArray<>();
//
// /** Values older than this will be removed. */
// private final long maxAgeMicro;
//
// /** Only store this many values. */
// private final int maxSampleCount;
//
// /** Things interested on when this series changes. */
// private final List<Listener<T>> listeners = new ArrayList<>();
//
// /** Create a timeseries, giving it a maximum age (in ms) length to contain. */
// public TimeSeries(long maxAgeMS) {
// this(maxAgeMS, -1);
// }
//
// /** Create a timeseries, giving either maximum age (in ms) or maximum sample count. */
// public TimeSeries(long maxAgeMS, int maxSampleCount) {
// this.maxAgeMicro = maxAgeMS == -1 ? -1 : maxAgeMS * 1000L;
// this.maxSampleCount = maxSampleCount;
// assert this.maxAgeMicro == -1 ^ this.maxSampleCount == -1;
// }
//
// /** @return Whether the time series has any data. */
// public boolean isEmpty() {
// return values.isEmpty();
// }
//
// /** Pushes a value to the end of the array. */
// public void pushValue(long timestampMicro, T value) {
// synchronized (this) {
// timestampsMicro.addLast(timestampMicro);
// values.addLast(value);
// for (Listener<T> listener : listeners) {
// listener.valueAdded(timestampMicro, value);
// }
// notifyChange();
// }
// }
//
// /**
// * Take a snapshot of the current values, first culling any that are too old.
// */
// public TimeSeriesSnapshot<T> getRecentSnapshot(Class<T> clazz) {
// synchronized (this) {
// if (this.isEmpty()) {
// return TimeSeriesSnapshot.EMPTY;
// }
//
// // First, remove all the old values.
// long finalSnapshot = timestampsMicro.getLast();
// if (maxSampleCount == -1) {
// while (timestampsMicro.getFirst() + maxAgeMicro < finalSnapshot) {
// timestampsMicro.popFirst();
// values.popFirst();
// }
// } else {
// while (timestampsMicro.size() > maxSampleCount) {
// timestampsMicro.popFirst();
// values.popFirst();
// }
// }
//
// // Next, snapshot into arrays and return:
// int n = this.values.size();
// long[] timestamps = new long[n];
// T[] values = (T[]) Array.newInstance(clazz, n);
// for (int i = 0; i < n; i++) {
// timestamps[i] = this.timestampsMicro.get(i);
// values[i] = this.values.get(i);
// }
// return new TimeSeriesSnapshot(timestamps, values);
// }
// }
//
// /**
// * Given a live series, and duration, convert into a TimeSeries with history.
// */
// public static <V> TimeSeries<V> fromLiveSeries(LiveSeries<V> liveSeries, long maxAgeMS) {
// final TimeSeries<V> result = TimeSeries.fromMaxAgeMS(maxAgeMS);
// liveSeries.addListener(new LiveSeries.Listener<V>() {
// @Override public void valueAdded(long timestampMicro, V data) {
// result.pushValue(timestampMicro, data);
// }
// });
// return result;
// }
//
// /**
// * Given a live series, and a smaple count, convert into a TimeSeries with history.
// */
// public static <V> TimeSeries<V> fromLiveSeriesWithCount(LiveSeries<V> liveSeries, int maxLength) {
// final TimeSeries<V> result = TimeSeries.fromMaxLength(maxLength);
// liveSeries.addListener(new LiveSeries.Listener<V>() {
// @Override public void valueAdded(long timestampMicro, V data) {
// result.pushValue(timestampMicro, data);
// }
// });
// return result;
// }
//
// @Override
// public void addListener(Listener<T> listener) {
// this.listeners.add(listener);
// }
// }
// Path: eegtoolkit/src/main/java/eeg/useit/today/eegtoolkit/vm/RawChannelViewModel.java
import com.choosemuse.libmuse.Eeg;
import com.choosemuse.libmuse.Muse;
import com.choosemuse.libmuse.MuseDataPacket;
import com.choosemuse.libmuse.MuseDataPacketType;
import eeg.useit.today.eegtoolkit.common.BaseDataPacketListener;
import eeg.useit.today.eegtoolkit.model.TimeSeries;
package eeg.useit.today.eegtoolkit.vm;
/**
* Given a device and a raw channel, present that channel's data as a TimeSeries.
*/
public class RawChannelViewModel extends TimeSeries<Double> {
public RawChannelViewModel(
StreamingDeviceViewModel device,
final Eeg channel,
long maxAgeMS,
int maxSampleCount
) {
super(maxAgeMS, maxSampleCount);
// Add listener to streaming device, use new values to update timeseries.
// TODO: Unregister when device stops, or on disposal. | device.registerDataListenerWhenConnected(new BaseDataPacketListener() { |
padster/Muse-EEG-Toolkit | eegtoolkit/src/main/java/eeg/useit/today/eegtoolkit/vm/StreamingDeviceViewModel.java | // Path: eegtoolkit/src/main/java/eeg/useit/today/eegtoolkit/Constants.java
// public class Constants {
// public static final String TAG = "EEGToolkit";
// public static final String RECORDING_PREFIX = "data";
//
// // HACK: Should configure these elsewhere, perhaps attributes to renderers.
// public static final double VOLTAGE_MAX = 1000.0;
// public static final double VOLTAGE_MIN = 700.0;
// }
//
// Path: eegtoolkit/src/main/java/eeg/useit/today/eegtoolkit/common/FrequencyBands.java
// public enum Band {
// // Frequency cutoff values taken from Muse documentation:
// // http://developer.choosemuse.com/research-tools/available-data
// DELTA( 1, 4),
// THETA( 4, 8),
// ALPHA(7.5, 13),
// BETA( 13, 30),
// GAMMA( 30, 44);
//
// public double minHz;
// public double maxHz;
//
// Band(double minHz, double maxHz) {
// this.minHz = minHz;
// this.maxHz = maxHz;
// }
// }
//
// Path: eegtoolkit/src/main/java/eeg/useit/today/eegtoolkit/common/FrequencyBands.java
// public enum ValueType {
// // Log of the sum of the Power Spectral Density of the data over the frequency range.
// ABSOLUTE,
// // Relative = divide the absolute linear-scale power in one band
// // over the sum of the absolute linear-scale powers in all bands. [0, 1]
// RELATIVE,
// // Compares current value to range of values seen in short history. [0, 1]
// SCORE,
// }
| import android.databinding.BaseObservable;
import android.databinding.Bindable;
import android.util.Log;
import com.choosemuse.libmuse.ConnectionState;
import com.choosemuse.libmuse.Eeg;
import com.choosemuse.libmuse.Muse;
import com.choosemuse.libmuse.MuseArtifactPacket;
import com.choosemuse.libmuse.MuseConnectionListener;
import com.choosemuse.libmuse.MuseConnectionPacket;
import com.choosemuse.libmuse.MuseDataListener;
import com.choosemuse.libmuse.MuseDataPacket;
import com.choosemuse.libmuse.MuseDataPacketType;
import java.util.ArrayList;
import java.util.List;
import eeg.useit.today.eegtoolkit.Constants;
import eeg.useit.today.eegtoolkit.common.FrequencyBands.Band;
import eeg.useit.today.eegtoolkit.common.FrequencyBands.ValueType; | package eeg.useit.today.eegtoolkit.vm;
/**
* ViewModel for a Muse device that is streaming data.
* Handles all connection logic, and sending live data to listeners
* efficiently once connected.
*/
public class StreamingDeviceViewModel extends BaseObservable {
/** Muse that this device is backed by. */
private Muse muse = null;
/** All things to be run on connection. */
private final List<Runnable> connectionCallbacks = new ArrayList<>();
/** Current status of connection. */
private ConnectionState connectionState = ConnectionState.DISCONNECTED;
/** Set the muse that is backing this device. If needed, try to connect straight away. */
public void setMuse(Muse muse) {
assert this.muse == null;
assert this.connectionState == ConnectionState.DISCONNECTED;
this.muse = muse;
this.connectionState = this.muse.getConnectionState();
if (!this.connectionCallbacks.isEmpty()) {
this.connectToMuse();
}
notifyChange();
}
@Bindable
public ConnectionState getConnectionState() {
return this.connectionState;
}
/** @return Bluetooth device name, or default if not yet connected. */
public String getName() {
return this.muse == null ? "No device" : this.muse.getName();
}
/** @return Bluetooth mac address, or null if not yet connected. */
public String getMacAddress() {
return this.muse == null ? null : this.muse.getMacAddress();
}
/** @return A new live VM for a single time series from a raw data channel. */
public RawChannelViewModel createRawTimeSeries(final Eeg channel, int durationSec) {
int samples = (int)(durationSec * 220.0); // Muse sample rate.
return new RawChannelViewModel(this, channel, -1, samples);
}
/** @return A new live VM for each sensor's frequency value for a given band/type combo. */
public FrequencyBandViewModel createFrequencyLiveValue(Band band, ValueType type) {
return new FrequencyBandViewModel(this, band, type);
}
/** @return A new live VM for the frequency band powers. */
public PSDViewModel createPSDLiveValue() {
return new PSDViewModel(this);
}
/**
* Register a data listener to the device.
* - If already connected, registers it directly.
* - Otherwise, sets it up to register when conncted, and tries to connect if possible.
*/
public void registerDataListenerWhenConnected(
final MuseDataListener listener, final MuseDataPacketType type) { | // Path: eegtoolkit/src/main/java/eeg/useit/today/eegtoolkit/Constants.java
// public class Constants {
// public static final String TAG = "EEGToolkit";
// public static final String RECORDING_PREFIX = "data";
//
// // HACK: Should configure these elsewhere, perhaps attributes to renderers.
// public static final double VOLTAGE_MAX = 1000.0;
// public static final double VOLTAGE_MIN = 700.0;
// }
//
// Path: eegtoolkit/src/main/java/eeg/useit/today/eegtoolkit/common/FrequencyBands.java
// public enum Band {
// // Frequency cutoff values taken from Muse documentation:
// // http://developer.choosemuse.com/research-tools/available-data
// DELTA( 1, 4),
// THETA( 4, 8),
// ALPHA(7.5, 13),
// BETA( 13, 30),
// GAMMA( 30, 44);
//
// public double minHz;
// public double maxHz;
//
// Band(double minHz, double maxHz) {
// this.minHz = minHz;
// this.maxHz = maxHz;
// }
// }
//
// Path: eegtoolkit/src/main/java/eeg/useit/today/eegtoolkit/common/FrequencyBands.java
// public enum ValueType {
// // Log of the sum of the Power Spectral Density of the data over the frequency range.
// ABSOLUTE,
// // Relative = divide the absolute linear-scale power in one band
// // over the sum of the absolute linear-scale powers in all bands. [0, 1]
// RELATIVE,
// // Compares current value to range of values seen in short history. [0, 1]
// SCORE,
// }
// Path: eegtoolkit/src/main/java/eeg/useit/today/eegtoolkit/vm/StreamingDeviceViewModel.java
import android.databinding.BaseObservable;
import android.databinding.Bindable;
import android.util.Log;
import com.choosemuse.libmuse.ConnectionState;
import com.choosemuse.libmuse.Eeg;
import com.choosemuse.libmuse.Muse;
import com.choosemuse.libmuse.MuseArtifactPacket;
import com.choosemuse.libmuse.MuseConnectionListener;
import com.choosemuse.libmuse.MuseConnectionPacket;
import com.choosemuse.libmuse.MuseDataListener;
import com.choosemuse.libmuse.MuseDataPacket;
import com.choosemuse.libmuse.MuseDataPacketType;
import java.util.ArrayList;
import java.util.List;
import eeg.useit.today.eegtoolkit.Constants;
import eeg.useit.today.eegtoolkit.common.FrequencyBands.Band;
import eeg.useit.today.eegtoolkit.common.FrequencyBands.ValueType;
package eeg.useit.today.eegtoolkit.vm;
/**
* ViewModel for a Muse device that is streaming data.
* Handles all connection logic, and sending live data to listeners
* efficiently once connected.
*/
public class StreamingDeviceViewModel extends BaseObservable {
/** Muse that this device is backed by. */
private Muse muse = null;
/** All things to be run on connection. */
private final List<Runnable> connectionCallbacks = new ArrayList<>();
/** Current status of connection. */
private ConnectionState connectionState = ConnectionState.DISCONNECTED;
/** Set the muse that is backing this device. If needed, try to connect straight away. */
public void setMuse(Muse muse) {
assert this.muse == null;
assert this.connectionState == ConnectionState.DISCONNECTED;
this.muse = muse;
this.connectionState = this.muse.getConnectionState();
if (!this.connectionCallbacks.isEmpty()) {
this.connectToMuse();
}
notifyChange();
}
@Bindable
public ConnectionState getConnectionState() {
return this.connectionState;
}
/** @return Bluetooth device name, or default if not yet connected. */
public String getName() {
return this.muse == null ? "No device" : this.muse.getName();
}
/** @return Bluetooth mac address, or null if not yet connected. */
public String getMacAddress() {
return this.muse == null ? null : this.muse.getMacAddress();
}
/** @return A new live VM for a single time series from a raw data channel. */
public RawChannelViewModel createRawTimeSeries(final Eeg channel, int durationSec) {
int samples = (int)(durationSec * 220.0); // Muse sample rate.
return new RawChannelViewModel(this, channel, -1, samples);
}
/** @return A new live VM for each sensor's frequency value for a given band/type combo. */
public FrequencyBandViewModel createFrequencyLiveValue(Band band, ValueType type) {
return new FrequencyBandViewModel(this, band, type);
}
/** @return A new live VM for the frequency band powers. */
public PSDViewModel createPSDLiveValue() {
return new PSDViewModel(this);
}
/**
* Register a data listener to the device.
* - If already connected, registers it directly.
* - Otherwise, sets it up to register when conncted, and tries to connect if possible.
*/
public void registerDataListenerWhenConnected(
final MuseDataListener listener, final MuseDataPacketType type) { | Log.i(Constants.TAG, "Connecting to " + type.name() + " in state " + connectionState.name()); |
padster/Muse-EEG-Toolkit | sampleApp/src/main/java/eeg/useit/today/eegtoolkit/sampleapp/ListDevicesActivity.java | // Path: eegtoolkit/src/main/java/eeg/useit/today/eegtoolkit/vm/MuseListViewModel.java
// public class MuseListViewModel extends BaseObservable {
// /**
// * Listener for semantic events fired by the viewmodel.
// */
// public interface MuseListListener {
// void onScanForDevicesFinished();
// void onDeviceSelected(Muse muse);
// }
//
// /** Whether we're currently scanning for devices. */
// private boolean scanning = false;
//
// /** List of Muse devices found. */
// private List<Muse> devices = new ArrayList<>();
//
// /** Listener to be sent events. */
// private MuseListListener museListListener = null;
//
// /** @return Whether the list is currently scanning for devices. */
// @Bindable
// public boolean isScanning() {
// return this.scanning;
// }
//
// /** @return The list of devices that have been found. */
// @Bindable
// public List<Muse> getDevices() {
// return this.devices;
// }
//
// /**
// * Scan for devices for a given amount of time, and store all devices found in that period.
// *
// * @param scanLengthSec How long to scan for, in seconds.
// */
// public void scan(int scanLengthSec) {
// // Start listening for devices...
// Log.i(Constants.TAG, "Starting scan...");
// this.scanning = true;
// MuseManagerAndroid.getInstance().startListening();
//
// // ...and after a while...
// new Handler(Looper.getMainLooper()).postDelayed(new Runnable() {
// @Override public void run() {
// // ...stop listening.
// Log.i(Constants.TAG, "Stopping scan...");
// MuseListViewModel.this.scanning = false;
// MuseManagerAndroid.getInstance().stopListening();
//
// // Report the devices we have found:
// MuseListViewModel.this.devices = new ArrayList<>(MuseManagerAndroid.getInstance().getMuses());
// notifyChange();
// if (museListListener != null) {
// MuseListViewModel.this.museListListener.onScanForDevicesFinished();
// }
// }
// }, scanLengthSec * 1000);
//
// // Also need to let ppl know the scanning field has changed.
// notifyChange();
// }
//
// /** Attach a listener to the VM. */
// public void setListener(MuseListListener listener) {
// this.museListListener = listener;
// }
//
// /** Select a device, by forwarding the event to the listener. */
// public void onSelect(Muse selectedDevice) {
// Log.i(Constants.TAG, "Selected: " + selectedDevice.getMacAddress());
// if (this.museListListener != null) {
// museListListener.onDeviceSelected(selectedDevice);
// }
// }
// }
| import android.Manifest;
import android.annotation.TargetApi;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.pm.PackageManager;
import android.databinding.DataBindingUtil;
import android.os.Build;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.Toast;
import com.choosemuse.libmuse.MuseManagerAndroid;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import eeg.useit.today.eegtoolkit.sampleapp.databinding.ActivityListDevicesBinding;
import eeg.useit.today.eegtoolkit.vm.MuseListViewModel; | package eeg.useit.today.eegtoolkit.sampleapp;
/**
* Example activity to show the list of Muse devices found,
* which also handles permissions and connecting to the Muse API.
*/
public class ListDevicesActivity extends AppCompatActivity {
final private int REQUEST_CODE_ASK_MULTIPLE_PERMISSIONS = 124;
/** ViewModel for muse devices found. */ | // Path: eegtoolkit/src/main/java/eeg/useit/today/eegtoolkit/vm/MuseListViewModel.java
// public class MuseListViewModel extends BaseObservable {
// /**
// * Listener for semantic events fired by the viewmodel.
// */
// public interface MuseListListener {
// void onScanForDevicesFinished();
// void onDeviceSelected(Muse muse);
// }
//
// /** Whether we're currently scanning for devices. */
// private boolean scanning = false;
//
// /** List of Muse devices found. */
// private List<Muse> devices = new ArrayList<>();
//
// /** Listener to be sent events. */
// private MuseListListener museListListener = null;
//
// /** @return Whether the list is currently scanning for devices. */
// @Bindable
// public boolean isScanning() {
// return this.scanning;
// }
//
// /** @return The list of devices that have been found. */
// @Bindable
// public List<Muse> getDevices() {
// return this.devices;
// }
//
// /**
// * Scan for devices for a given amount of time, and store all devices found in that period.
// *
// * @param scanLengthSec How long to scan for, in seconds.
// */
// public void scan(int scanLengthSec) {
// // Start listening for devices...
// Log.i(Constants.TAG, "Starting scan...");
// this.scanning = true;
// MuseManagerAndroid.getInstance().startListening();
//
// // ...and after a while...
// new Handler(Looper.getMainLooper()).postDelayed(new Runnable() {
// @Override public void run() {
// // ...stop listening.
// Log.i(Constants.TAG, "Stopping scan...");
// MuseListViewModel.this.scanning = false;
// MuseManagerAndroid.getInstance().stopListening();
//
// // Report the devices we have found:
// MuseListViewModel.this.devices = new ArrayList<>(MuseManagerAndroid.getInstance().getMuses());
// notifyChange();
// if (museListListener != null) {
// MuseListViewModel.this.museListListener.onScanForDevicesFinished();
// }
// }
// }, scanLengthSec * 1000);
//
// // Also need to let ppl know the scanning field has changed.
// notifyChange();
// }
//
// /** Attach a listener to the VM. */
// public void setListener(MuseListListener listener) {
// this.museListListener = listener;
// }
//
// /** Select a device, by forwarding the event to the listener. */
// public void onSelect(Muse selectedDevice) {
// Log.i(Constants.TAG, "Selected: " + selectedDevice.getMacAddress());
// if (this.museListListener != null) {
// museListListener.onDeviceSelected(selectedDevice);
// }
// }
// }
// Path: sampleApp/src/main/java/eeg/useit/today/eegtoolkit/sampleapp/ListDevicesActivity.java
import android.Manifest;
import android.annotation.TargetApi;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.pm.PackageManager;
import android.databinding.DataBindingUtil;
import android.os.Build;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.Toast;
import com.choosemuse.libmuse.MuseManagerAndroid;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import eeg.useit.today.eegtoolkit.sampleapp.databinding.ActivityListDevicesBinding;
import eeg.useit.today.eegtoolkit.vm.MuseListViewModel;
package eeg.useit.today.eegtoolkit.sampleapp;
/**
* Example activity to show the list of Muse devices found,
* which also handles permissions and connecting to the Muse API.
*/
public class ListDevicesActivity extends AppCompatActivity {
final private int REQUEST_CODE_ASK_MULTIPLE_PERMISSIONS = 124;
/** ViewModel for muse devices found. */ | public final MuseListViewModel viewModel = new MuseListViewModel(); |
padster/Muse-EEG-Toolkit | eegtoolkit/src/main/java/eeg/useit/today/eegtoolkit/model/Raw2Frequency.java | // Path: eegtoolkit/src/main/java/eeg/useit/today/eegtoolkit/model/fft/DoFFT.java
// public class DoFFT {
// private static int WINDOW_SZ = 256;
// private double[] HAMMING_WINDOW = new double[WINDOW_SZ];
//
// public DoFFT() {
// double alpha = 0.53836;
// double beta = 1.0 - alpha;
// for (int i = 0; i < WINDOW_SZ; i++) {
// HAMMING_WINDOW[i] = alpha - beta * Math.cos(2 * Math.PI * i / (1.0 * WINDOW_SZ));
// }
// }
//
// public Double[] calc(Double[] rawSignal) {
// assert rawSignal.length == WINDOW_SZ;
//
// double[] windowed = new double[WINDOW_SZ];
// for (int i = 0; i < WINDOW_SZ; i++) {
// windowed[i] = rawSignal[i] * HAMMING_WINDOW[i];
// }
//
// FFT fft = new FFT(WINDOW_SZ);
// Complex1D result = fft.ft(windowed);
// Double[] powers = new Double[WINDOW_SZ/2 + 1];
// for (int i = 0; i < WINDOW_SZ/2 + 1; i++) {
// double x = result.real[i], y = result.imag[i];
// powers[i] = 10.0 * Math.log(Math.sqrt(x*x+y*y));
// }
// return powers;
// }
// }
| import android.databinding.DataBindingUtil;
import java.util.ArrayList;
import java.util.List;
import eeg.useit.today.eegtoolkit.model.fft.DoFFT; | package eeg.useit.today.eegtoolkit.model;
/**
* Given a raw signal, convert it to frequency domain by performing a
* windowed STFT every N samples.
*/
public class Raw2Frequency implements LiveSeries<Double[]>, TimeSeries.Listener<Double> {
public static final int WINDOW_SIZE = 256;
public static final int DOWNSAMPLE_RATE = 22;
private final TimeSeries<Double> timeSeries;
/** Listeners for new values that come in. */
private List<Listener<Double[]>> listeners = new ArrayList<>();
private int samplesLeftAtStart;
private int samplesLeftToFFT;
| // Path: eegtoolkit/src/main/java/eeg/useit/today/eegtoolkit/model/fft/DoFFT.java
// public class DoFFT {
// private static int WINDOW_SZ = 256;
// private double[] HAMMING_WINDOW = new double[WINDOW_SZ];
//
// public DoFFT() {
// double alpha = 0.53836;
// double beta = 1.0 - alpha;
// for (int i = 0; i < WINDOW_SZ; i++) {
// HAMMING_WINDOW[i] = alpha - beta * Math.cos(2 * Math.PI * i / (1.0 * WINDOW_SZ));
// }
// }
//
// public Double[] calc(Double[] rawSignal) {
// assert rawSignal.length == WINDOW_SZ;
//
// double[] windowed = new double[WINDOW_SZ];
// for (int i = 0; i < WINDOW_SZ; i++) {
// windowed[i] = rawSignal[i] * HAMMING_WINDOW[i];
// }
//
// FFT fft = new FFT(WINDOW_SZ);
// Complex1D result = fft.ft(windowed);
// Double[] powers = new Double[WINDOW_SZ/2 + 1];
// for (int i = 0; i < WINDOW_SZ/2 + 1; i++) {
// double x = result.real[i], y = result.imag[i];
// powers[i] = 10.0 * Math.log(Math.sqrt(x*x+y*y));
// }
// return powers;
// }
// }
// Path: eegtoolkit/src/main/java/eeg/useit/today/eegtoolkit/model/Raw2Frequency.java
import android.databinding.DataBindingUtil;
import java.util.ArrayList;
import java.util.List;
import eeg.useit.today.eegtoolkit.model.fft.DoFFT;
package eeg.useit.today.eegtoolkit.model;
/**
* Given a raw signal, convert it to frequency domain by performing a
* windowed STFT every N samples.
*/
public class Raw2Frequency implements LiveSeries<Double[]>, TimeSeries.Listener<Double> {
public static final int WINDOW_SIZE = 256;
public static final int DOWNSAMPLE_RATE = 22;
private final TimeSeries<Double> timeSeries;
/** Listeners for new values that come in. */
private List<Listener<Double[]>> listeners = new ArrayList<>();
private int samplesLeftAtStart;
private int samplesLeftToFFT;
| private DoFFT fft = new DoFFT(); |
padster/Muse-EEG-Toolkit | eegtoolkit/src/main/java/eeg/useit/today/eegtoolkit/view/graph/GraphGLView.java | // Path: eegtoolkit/src/main/java/eeg/useit/today/eegtoolkit/model/LiveSeries.java
// public interface LiveSeries<T> {
// /** API for callback invoked when a live series has new data. */
// interface Listener<U> {
// void valueAdded(long timestampMicro, U data);
// }
//
// void addListener(Listener<T> listener);
// }
//
// Path: eegtoolkit/src/main/java/eeg/useit/today/eegtoolkit/model/TimeSeries.java
// public class TimeSeries<T> extends BaseObservable implements LiveSeries<T> {
// public static <T> TimeSeries<T> fromMaxAgeMS(long maxAgeMS) {
// return new TimeSeries<T>(maxAgeMS, -1);
// }
// public static <T> TimeSeries<T> fromMaxLength(int maxSampleCount) {
// return new TimeSeries<T>(-1, maxSampleCount);
// }
//
// /** Values within the timeseries. */
// private final CircularArray<T> values = new CircularArray<>();
//
// /** Times at which the values were taken. */
// private final CircularArray<Long> timestampsMicro = new CircularArray<>();
//
// /** Values older than this will be removed. */
// private final long maxAgeMicro;
//
// /** Only store this many values. */
// private final int maxSampleCount;
//
// /** Things interested on when this series changes. */
// private final List<Listener<T>> listeners = new ArrayList<>();
//
// /** Create a timeseries, giving it a maximum age (in ms) length to contain. */
// public TimeSeries(long maxAgeMS) {
// this(maxAgeMS, -1);
// }
//
// /** Create a timeseries, giving either maximum age (in ms) or maximum sample count. */
// public TimeSeries(long maxAgeMS, int maxSampleCount) {
// this.maxAgeMicro = maxAgeMS == -1 ? -1 : maxAgeMS * 1000L;
// this.maxSampleCount = maxSampleCount;
// assert this.maxAgeMicro == -1 ^ this.maxSampleCount == -1;
// }
//
// /** @return Whether the time series has any data. */
// public boolean isEmpty() {
// return values.isEmpty();
// }
//
// /** Pushes a value to the end of the array. */
// public void pushValue(long timestampMicro, T value) {
// synchronized (this) {
// timestampsMicro.addLast(timestampMicro);
// values.addLast(value);
// for (Listener<T> listener : listeners) {
// listener.valueAdded(timestampMicro, value);
// }
// notifyChange();
// }
// }
//
// /**
// * Take a snapshot of the current values, first culling any that are too old.
// */
// public TimeSeriesSnapshot<T> getRecentSnapshot(Class<T> clazz) {
// synchronized (this) {
// if (this.isEmpty()) {
// return TimeSeriesSnapshot.EMPTY;
// }
//
// // First, remove all the old values.
// long finalSnapshot = timestampsMicro.getLast();
// if (maxSampleCount == -1) {
// while (timestampsMicro.getFirst() + maxAgeMicro < finalSnapshot) {
// timestampsMicro.popFirst();
// values.popFirst();
// }
// } else {
// while (timestampsMicro.size() > maxSampleCount) {
// timestampsMicro.popFirst();
// values.popFirst();
// }
// }
//
// // Next, snapshot into arrays and return:
// int n = this.values.size();
// long[] timestamps = new long[n];
// T[] values = (T[]) Array.newInstance(clazz, n);
// for (int i = 0; i < n; i++) {
// timestamps[i] = this.timestampsMicro.get(i);
// values[i] = this.values.get(i);
// }
// return new TimeSeriesSnapshot(timestamps, values);
// }
// }
//
// /**
// * Given a live series, and duration, convert into a TimeSeries with history.
// */
// public static <V> TimeSeries<V> fromLiveSeries(LiveSeries<V> liveSeries, long maxAgeMS) {
// final TimeSeries<V> result = TimeSeries.fromMaxAgeMS(maxAgeMS);
// liveSeries.addListener(new LiveSeries.Listener<V>() {
// @Override public void valueAdded(long timestampMicro, V data) {
// result.pushValue(timestampMicro, data);
// }
// });
// return result;
// }
//
// /**
// * Given a live series, and a smaple count, convert into a TimeSeries with history.
// */
// public static <V> TimeSeries<V> fromLiveSeriesWithCount(LiveSeries<V> liveSeries, int maxLength) {
// final TimeSeries<V> result = TimeSeries.fromMaxLength(maxLength);
// liveSeries.addListener(new LiveSeries.Listener<V>() {
// @Override public void valueAdded(long timestampMicro, V data) {
// result.pushValue(timestampMicro, data);
// }
// });
// return result;
// }
//
// @Override
// public void addListener(Listener<T> listener) {
// this.listeners.add(listener);
// }
// }
| import android.content.Context;
import android.opengl.GLSurfaceView;
import android.util.AttributeSet;
import eeg.useit.today.eegtoolkit.model.LiveSeries;
import eeg.useit.today.eegtoolkit.model.TimeSeries; | package eeg.useit.today.eegtoolkit.view.graph;
/** GLSurfaceView that draws a timeseries line to the view. */
public class GraphGLView extends GLSurfaceView {
private static final int DEFAULT_DURATION_SEC = 10;
/** Renderer that handles the drawing for this GL surface.*/
private final GraphGLRenderer renderer;
/**
* Create a GraphGL view, set a renderer to show the configured duration to time.
*/
public GraphGLView(Context context, AttributeSet attrs) {
super(context, attrs);
// OpenGL 2.0
setEGLContextClientVersion(2);
int durationSec = DEFAULT_DURATION_SEC;
for (int i = 0; i < attrs.getAttributeCount(); i++) {
if ("durationSec".equals(attrs.getAttributeName(i))) {
durationSec = attrs.getAttributeIntValue(i, DEFAULT_DURATION_SEC);
}
}
this.renderer = new GraphGLRenderer(this.getContext(), durationSec);
setRenderer(this.renderer);
}
/** Connect the view to a viewmodel. */ | // Path: eegtoolkit/src/main/java/eeg/useit/today/eegtoolkit/model/LiveSeries.java
// public interface LiveSeries<T> {
// /** API for callback invoked when a live series has new data. */
// interface Listener<U> {
// void valueAdded(long timestampMicro, U data);
// }
//
// void addListener(Listener<T> listener);
// }
//
// Path: eegtoolkit/src/main/java/eeg/useit/today/eegtoolkit/model/TimeSeries.java
// public class TimeSeries<T> extends BaseObservable implements LiveSeries<T> {
// public static <T> TimeSeries<T> fromMaxAgeMS(long maxAgeMS) {
// return new TimeSeries<T>(maxAgeMS, -1);
// }
// public static <T> TimeSeries<T> fromMaxLength(int maxSampleCount) {
// return new TimeSeries<T>(-1, maxSampleCount);
// }
//
// /** Values within the timeseries. */
// private final CircularArray<T> values = new CircularArray<>();
//
// /** Times at which the values were taken. */
// private final CircularArray<Long> timestampsMicro = new CircularArray<>();
//
// /** Values older than this will be removed. */
// private final long maxAgeMicro;
//
// /** Only store this many values. */
// private final int maxSampleCount;
//
// /** Things interested on when this series changes. */
// private final List<Listener<T>> listeners = new ArrayList<>();
//
// /** Create a timeseries, giving it a maximum age (in ms) length to contain. */
// public TimeSeries(long maxAgeMS) {
// this(maxAgeMS, -1);
// }
//
// /** Create a timeseries, giving either maximum age (in ms) or maximum sample count. */
// public TimeSeries(long maxAgeMS, int maxSampleCount) {
// this.maxAgeMicro = maxAgeMS == -1 ? -1 : maxAgeMS * 1000L;
// this.maxSampleCount = maxSampleCount;
// assert this.maxAgeMicro == -1 ^ this.maxSampleCount == -1;
// }
//
// /** @return Whether the time series has any data. */
// public boolean isEmpty() {
// return values.isEmpty();
// }
//
// /** Pushes a value to the end of the array. */
// public void pushValue(long timestampMicro, T value) {
// synchronized (this) {
// timestampsMicro.addLast(timestampMicro);
// values.addLast(value);
// for (Listener<T> listener : listeners) {
// listener.valueAdded(timestampMicro, value);
// }
// notifyChange();
// }
// }
//
// /**
// * Take a snapshot of the current values, first culling any that are too old.
// */
// public TimeSeriesSnapshot<T> getRecentSnapshot(Class<T> clazz) {
// synchronized (this) {
// if (this.isEmpty()) {
// return TimeSeriesSnapshot.EMPTY;
// }
//
// // First, remove all the old values.
// long finalSnapshot = timestampsMicro.getLast();
// if (maxSampleCount == -1) {
// while (timestampsMicro.getFirst() + maxAgeMicro < finalSnapshot) {
// timestampsMicro.popFirst();
// values.popFirst();
// }
// } else {
// while (timestampsMicro.size() > maxSampleCount) {
// timestampsMicro.popFirst();
// values.popFirst();
// }
// }
//
// // Next, snapshot into arrays and return:
// int n = this.values.size();
// long[] timestamps = new long[n];
// T[] values = (T[]) Array.newInstance(clazz, n);
// for (int i = 0; i < n; i++) {
// timestamps[i] = this.timestampsMicro.get(i);
// values[i] = this.values.get(i);
// }
// return new TimeSeriesSnapshot(timestamps, values);
// }
// }
//
// /**
// * Given a live series, and duration, convert into a TimeSeries with history.
// */
// public static <V> TimeSeries<V> fromLiveSeries(LiveSeries<V> liveSeries, long maxAgeMS) {
// final TimeSeries<V> result = TimeSeries.fromMaxAgeMS(maxAgeMS);
// liveSeries.addListener(new LiveSeries.Listener<V>() {
// @Override public void valueAdded(long timestampMicro, V data) {
// result.pushValue(timestampMicro, data);
// }
// });
// return result;
// }
//
// /**
// * Given a live series, and a smaple count, convert into a TimeSeries with history.
// */
// public static <V> TimeSeries<V> fromLiveSeriesWithCount(LiveSeries<V> liveSeries, int maxLength) {
// final TimeSeries<V> result = TimeSeries.fromMaxLength(maxLength);
// liveSeries.addListener(new LiveSeries.Listener<V>() {
// @Override public void valueAdded(long timestampMicro, V data) {
// result.pushValue(timestampMicro, data);
// }
// });
// return result;
// }
//
// @Override
// public void addListener(Listener<T> listener) {
// this.listeners.add(listener);
// }
// }
// Path: eegtoolkit/src/main/java/eeg/useit/today/eegtoolkit/view/graph/GraphGLView.java
import android.content.Context;
import android.opengl.GLSurfaceView;
import android.util.AttributeSet;
import eeg.useit.today.eegtoolkit.model.LiveSeries;
import eeg.useit.today.eegtoolkit.model.TimeSeries;
package eeg.useit.today.eegtoolkit.view.graph;
/** GLSurfaceView that draws a timeseries line to the view. */
public class GraphGLView extends GLSurfaceView {
private static final int DEFAULT_DURATION_SEC = 10;
/** Renderer that handles the drawing for this GL surface.*/
private final GraphGLRenderer renderer;
/**
* Create a GraphGL view, set a renderer to show the configured duration to time.
*/
public GraphGLView(Context context, AttributeSet attrs) {
super(context, attrs);
// OpenGL 2.0
setEGLContextClientVersion(2);
int durationSec = DEFAULT_DURATION_SEC;
for (int i = 0; i < attrs.getAttributeCount(); i++) {
if ("durationSec".equals(attrs.getAttributeName(i))) {
durationSec = attrs.getAttributeIntValue(i, DEFAULT_DURATION_SEC);
}
}
this.renderer = new GraphGLRenderer(this.getContext(), durationSec);
setRenderer(this.renderer);
}
/** Connect the view to a viewmodel. */ | public void setTimeSeries(TimeSeries<Double> ts) { |
padster/Muse-EEG-Toolkit | eegtoolkit/src/main/java/eeg/useit/today/eegtoolkit/view/graph/GraphGLView.java | // Path: eegtoolkit/src/main/java/eeg/useit/today/eegtoolkit/model/LiveSeries.java
// public interface LiveSeries<T> {
// /** API for callback invoked when a live series has new data. */
// interface Listener<U> {
// void valueAdded(long timestampMicro, U data);
// }
//
// void addListener(Listener<T> listener);
// }
//
// Path: eegtoolkit/src/main/java/eeg/useit/today/eegtoolkit/model/TimeSeries.java
// public class TimeSeries<T> extends BaseObservable implements LiveSeries<T> {
// public static <T> TimeSeries<T> fromMaxAgeMS(long maxAgeMS) {
// return new TimeSeries<T>(maxAgeMS, -1);
// }
// public static <T> TimeSeries<T> fromMaxLength(int maxSampleCount) {
// return new TimeSeries<T>(-1, maxSampleCount);
// }
//
// /** Values within the timeseries. */
// private final CircularArray<T> values = new CircularArray<>();
//
// /** Times at which the values were taken. */
// private final CircularArray<Long> timestampsMicro = new CircularArray<>();
//
// /** Values older than this will be removed. */
// private final long maxAgeMicro;
//
// /** Only store this many values. */
// private final int maxSampleCount;
//
// /** Things interested on when this series changes. */
// private final List<Listener<T>> listeners = new ArrayList<>();
//
// /** Create a timeseries, giving it a maximum age (in ms) length to contain. */
// public TimeSeries(long maxAgeMS) {
// this(maxAgeMS, -1);
// }
//
// /** Create a timeseries, giving either maximum age (in ms) or maximum sample count. */
// public TimeSeries(long maxAgeMS, int maxSampleCount) {
// this.maxAgeMicro = maxAgeMS == -1 ? -1 : maxAgeMS * 1000L;
// this.maxSampleCount = maxSampleCount;
// assert this.maxAgeMicro == -1 ^ this.maxSampleCount == -1;
// }
//
// /** @return Whether the time series has any data. */
// public boolean isEmpty() {
// return values.isEmpty();
// }
//
// /** Pushes a value to the end of the array. */
// public void pushValue(long timestampMicro, T value) {
// synchronized (this) {
// timestampsMicro.addLast(timestampMicro);
// values.addLast(value);
// for (Listener<T> listener : listeners) {
// listener.valueAdded(timestampMicro, value);
// }
// notifyChange();
// }
// }
//
// /**
// * Take a snapshot of the current values, first culling any that are too old.
// */
// public TimeSeriesSnapshot<T> getRecentSnapshot(Class<T> clazz) {
// synchronized (this) {
// if (this.isEmpty()) {
// return TimeSeriesSnapshot.EMPTY;
// }
//
// // First, remove all the old values.
// long finalSnapshot = timestampsMicro.getLast();
// if (maxSampleCount == -1) {
// while (timestampsMicro.getFirst() + maxAgeMicro < finalSnapshot) {
// timestampsMicro.popFirst();
// values.popFirst();
// }
// } else {
// while (timestampsMicro.size() > maxSampleCount) {
// timestampsMicro.popFirst();
// values.popFirst();
// }
// }
//
// // Next, snapshot into arrays and return:
// int n = this.values.size();
// long[] timestamps = new long[n];
// T[] values = (T[]) Array.newInstance(clazz, n);
// for (int i = 0; i < n; i++) {
// timestamps[i] = this.timestampsMicro.get(i);
// values[i] = this.values.get(i);
// }
// return new TimeSeriesSnapshot(timestamps, values);
// }
// }
//
// /**
// * Given a live series, and duration, convert into a TimeSeries with history.
// */
// public static <V> TimeSeries<V> fromLiveSeries(LiveSeries<V> liveSeries, long maxAgeMS) {
// final TimeSeries<V> result = TimeSeries.fromMaxAgeMS(maxAgeMS);
// liveSeries.addListener(new LiveSeries.Listener<V>() {
// @Override public void valueAdded(long timestampMicro, V data) {
// result.pushValue(timestampMicro, data);
// }
// });
// return result;
// }
//
// /**
// * Given a live series, and a smaple count, convert into a TimeSeries with history.
// */
// public static <V> TimeSeries<V> fromLiveSeriesWithCount(LiveSeries<V> liveSeries, int maxLength) {
// final TimeSeries<V> result = TimeSeries.fromMaxLength(maxLength);
// liveSeries.addListener(new LiveSeries.Listener<V>() {
// @Override public void valueAdded(long timestampMicro, V data) {
// result.pushValue(timestampMicro, data);
// }
// });
// return result;
// }
//
// @Override
// public void addListener(Listener<T> listener) {
// this.listeners.add(listener);
// }
// }
| import android.content.Context;
import android.opengl.GLSurfaceView;
import android.util.AttributeSet;
import eeg.useit.today.eegtoolkit.model.LiveSeries;
import eeg.useit.today.eegtoolkit.model.TimeSeries; | package eeg.useit.today.eegtoolkit.view.graph;
/** GLSurfaceView that draws a timeseries line to the view. */
public class GraphGLView extends GLSurfaceView {
private static final int DEFAULT_DURATION_SEC = 10;
/** Renderer that handles the drawing for this GL surface.*/
private final GraphGLRenderer renderer;
/**
* Create a GraphGL view, set a renderer to show the configured duration to time.
*/
public GraphGLView(Context context, AttributeSet attrs) {
super(context, attrs);
// OpenGL 2.0
setEGLContextClientVersion(2);
int durationSec = DEFAULT_DURATION_SEC;
for (int i = 0; i < attrs.getAttributeCount(); i++) {
if ("durationSec".equals(attrs.getAttributeName(i))) {
durationSec = attrs.getAttributeIntValue(i, DEFAULT_DURATION_SEC);
}
}
this.renderer = new GraphGLRenderer(this.getContext(), durationSec);
setRenderer(this.renderer);
}
/** Connect the view to a viewmodel. */
public void setTimeSeries(TimeSeries<Double> ts) {
// Delegate to renderer.
this.renderer.setTimeSeries(ts); | // Path: eegtoolkit/src/main/java/eeg/useit/today/eegtoolkit/model/LiveSeries.java
// public interface LiveSeries<T> {
// /** API for callback invoked when a live series has new data. */
// interface Listener<U> {
// void valueAdded(long timestampMicro, U data);
// }
//
// void addListener(Listener<T> listener);
// }
//
// Path: eegtoolkit/src/main/java/eeg/useit/today/eegtoolkit/model/TimeSeries.java
// public class TimeSeries<T> extends BaseObservable implements LiveSeries<T> {
// public static <T> TimeSeries<T> fromMaxAgeMS(long maxAgeMS) {
// return new TimeSeries<T>(maxAgeMS, -1);
// }
// public static <T> TimeSeries<T> fromMaxLength(int maxSampleCount) {
// return new TimeSeries<T>(-1, maxSampleCount);
// }
//
// /** Values within the timeseries. */
// private final CircularArray<T> values = new CircularArray<>();
//
// /** Times at which the values were taken. */
// private final CircularArray<Long> timestampsMicro = new CircularArray<>();
//
// /** Values older than this will be removed. */
// private final long maxAgeMicro;
//
// /** Only store this many values. */
// private final int maxSampleCount;
//
// /** Things interested on when this series changes. */
// private final List<Listener<T>> listeners = new ArrayList<>();
//
// /** Create a timeseries, giving it a maximum age (in ms) length to contain. */
// public TimeSeries(long maxAgeMS) {
// this(maxAgeMS, -1);
// }
//
// /** Create a timeseries, giving either maximum age (in ms) or maximum sample count. */
// public TimeSeries(long maxAgeMS, int maxSampleCount) {
// this.maxAgeMicro = maxAgeMS == -1 ? -1 : maxAgeMS * 1000L;
// this.maxSampleCount = maxSampleCount;
// assert this.maxAgeMicro == -1 ^ this.maxSampleCount == -1;
// }
//
// /** @return Whether the time series has any data. */
// public boolean isEmpty() {
// return values.isEmpty();
// }
//
// /** Pushes a value to the end of the array. */
// public void pushValue(long timestampMicro, T value) {
// synchronized (this) {
// timestampsMicro.addLast(timestampMicro);
// values.addLast(value);
// for (Listener<T> listener : listeners) {
// listener.valueAdded(timestampMicro, value);
// }
// notifyChange();
// }
// }
//
// /**
// * Take a snapshot of the current values, first culling any that are too old.
// */
// public TimeSeriesSnapshot<T> getRecentSnapshot(Class<T> clazz) {
// synchronized (this) {
// if (this.isEmpty()) {
// return TimeSeriesSnapshot.EMPTY;
// }
//
// // First, remove all the old values.
// long finalSnapshot = timestampsMicro.getLast();
// if (maxSampleCount == -1) {
// while (timestampsMicro.getFirst() + maxAgeMicro < finalSnapshot) {
// timestampsMicro.popFirst();
// values.popFirst();
// }
// } else {
// while (timestampsMicro.size() > maxSampleCount) {
// timestampsMicro.popFirst();
// values.popFirst();
// }
// }
//
// // Next, snapshot into arrays and return:
// int n = this.values.size();
// long[] timestamps = new long[n];
// T[] values = (T[]) Array.newInstance(clazz, n);
// for (int i = 0; i < n; i++) {
// timestamps[i] = this.timestampsMicro.get(i);
// values[i] = this.values.get(i);
// }
// return new TimeSeriesSnapshot(timestamps, values);
// }
// }
//
// /**
// * Given a live series, and duration, convert into a TimeSeries with history.
// */
// public static <V> TimeSeries<V> fromLiveSeries(LiveSeries<V> liveSeries, long maxAgeMS) {
// final TimeSeries<V> result = TimeSeries.fromMaxAgeMS(maxAgeMS);
// liveSeries.addListener(new LiveSeries.Listener<V>() {
// @Override public void valueAdded(long timestampMicro, V data) {
// result.pushValue(timestampMicro, data);
// }
// });
// return result;
// }
//
// /**
// * Given a live series, and a smaple count, convert into a TimeSeries with history.
// */
// public static <V> TimeSeries<V> fromLiveSeriesWithCount(LiveSeries<V> liveSeries, int maxLength) {
// final TimeSeries<V> result = TimeSeries.fromMaxLength(maxLength);
// liveSeries.addListener(new LiveSeries.Listener<V>() {
// @Override public void valueAdded(long timestampMicro, V data) {
// result.pushValue(timestampMicro, data);
// }
// });
// return result;
// }
//
// @Override
// public void addListener(Listener<T> listener) {
// this.listeners.add(listener);
// }
// }
// Path: eegtoolkit/src/main/java/eeg/useit/today/eegtoolkit/view/graph/GraphGLView.java
import android.content.Context;
import android.opengl.GLSurfaceView;
import android.util.AttributeSet;
import eeg.useit.today.eegtoolkit.model.LiveSeries;
import eeg.useit.today.eegtoolkit.model.TimeSeries;
package eeg.useit.today.eegtoolkit.view.graph;
/** GLSurfaceView that draws a timeseries line to the view. */
public class GraphGLView extends GLSurfaceView {
private static final int DEFAULT_DURATION_SEC = 10;
/** Renderer that handles the drawing for this GL surface.*/
private final GraphGLRenderer renderer;
/**
* Create a GraphGL view, set a renderer to show the configured duration to time.
*/
public GraphGLView(Context context, AttributeSet attrs) {
super(context, attrs);
// OpenGL 2.0
setEGLContextClientVersion(2);
int durationSec = DEFAULT_DURATION_SEC;
for (int i = 0; i < attrs.getAttributeCount(); i++) {
if ("durationSec".equals(attrs.getAttributeName(i))) {
durationSec = attrs.getAttributeIntValue(i, DEFAULT_DURATION_SEC);
}
}
this.renderer = new GraphGLRenderer(this.getContext(), durationSec);
setRenderer(this.renderer);
}
/** Connect the view to a viewmodel. */
public void setTimeSeries(TimeSeries<Double> ts) {
// Delegate to renderer.
this.renderer.setTimeSeries(ts); | ts.addListener(new LiveSeries.Listener<Double>() { |
source4code/repo | jaxb-missing-rootelement/src/main/java/info/source4code/jaxb/MarshalHelper.java | // Path: jaxb-unmarshal-string/src/main/java/info/source4code/jaxb/model/Car.java
// @XmlRootElement(namespace = "info.source4code.jaxb.model", name = "Car")
// public class Car {
//
// private String make;
// private String manufacturer;
// private String id;
//
// public String getMake() {
// return make;
// }
//
// @XmlElement
// public void setMake(String make) {
// this.make = make;
// }
//
// public String getManufacturer() {
// return manufacturer;
// }
//
// @XmlElement
// public void setManufacturer(String manufacturer) {
// this.manufacturer = manufacturer;
// }
//
// public String getId() {
// return id;
// }
//
// @XmlAttribute
// public void setId(String id) {
// this.id = id;
// }
//
// public String toString() {
// return "Car [" + "make=" + make + ", manufacturer=" + manufacturer
// + ", id=" + id + "]";
// }
// }
| import info.source4code.jaxb.model.Car;
import java.io.StringWriter;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBElement;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import javax.xml.namespace.QName;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory; | package info.source4code.jaxb;
public final class MarshalHelper {
private static final Logger LOGGER = LoggerFactory
.getLogger(MarshalHelper.class);
private MarshalHelper() {
// not called
}
| // Path: jaxb-unmarshal-string/src/main/java/info/source4code/jaxb/model/Car.java
// @XmlRootElement(namespace = "info.source4code.jaxb.model", name = "Car")
// public class Car {
//
// private String make;
// private String manufacturer;
// private String id;
//
// public String getMake() {
// return make;
// }
//
// @XmlElement
// public void setMake(String make) {
// this.make = make;
// }
//
// public String getManufacturer() {
// return manufacturer;
// }
//
// @XmlElement
// public void setManufacturer(String manufacturer) {
// this.manufacturer = manufacturer;
// }
//
// public String getId() {
// return id;
// }
//
// @XmlAttribute
// public void setId(String id) {
// this.id = id;
// }
//
// public String toString() {
// return "Car [" + "make=" + make + ", manufacturer=" + manufacturer
// + ", id=" + id + "]";
// }
// }
// Path: jaxb-missing-rootelement/src/main/java/info/source4code/jaxb/MarshalHelper.java
import info.source4code.jaxb.model.Car;
import java.io.StringWriter;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBElement;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import javax.xml.namespace.QName;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
package info.source4code.jaxb;
public final class MarshalHelper {
private static final Logger LOGGER = LoggerFactory
.getLogger(MarshalHelper.class);
private MarshalHelper() {
// not called
}
| public static String marshalError(Car car) throws JAXBException { |
source4code/repo | jaxb-unmarshal-string/src/test/java/info/source4code/jaxb/UnmarshalHelperTest.java | // Path: jaxb-unmarshal-string/src/main/java/info/source4code/jaxb/model/Car.java
// @XmlRootElement(namespace = "info.source4code.jaxb.model", name = "Car")
// public class Car {
//
// private String make;
// private String manufacturer;
// private String id;
//
// public String getMake() {
// return make;
// }
//
// @XmlElement
// public void setMake(String make) {
// this.make = make;
// }
//
// public String getManufacturer() {
// return manufacturer;
// }
//
// @XmlElement
// public void setManufacturer(String manufacturer) {
// this.manufacturer = manufacturer;
// }
//
// public String getId() {
// return id;
// }
//
// @XmlAttribute
// public void setId(String id) {
// this.id = id;
// }
//
// public String toString() {
// return "Car [" + "make=" + make + ", manufacturer=" + manufacturer
// + ", id=" + id + "]";
// }
// }
| import static org.junit.Assert.assertEquals;
import info.source4code.jaxb.model.Car;
import javax.xml.bind.JAXBException;
import org.junit.BeforeClass;
import org.junit.Test; | package info.source4code.jaxb;
public class UnmarshalHelperTest {
public static String xml;
@BeforeClass
public static void setUpBeforeClass() {
xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" "
+ "standalone=\"yes\"?>"
+ "<ns2:Car xmlns:ns2=\"info.source4code.jaxb.model\" id=\"ABC-123\">"
+ "<make>Passat</make>"
+ "<manufacturer>Volkswagen</manufacturer></ns2:Car>";
}
@Test
public void testUnmarshal() throws JAXBException { | // Path: jaxb-unmarshal-string/src/main/java/info/source4code/jaxb/model/Car.java
// @XmlRootElement(namespace = "info.source4code.jaxb.model", name = "Car")
// public class Car {
//
// private String make;
// private String manufacturer;
// private String id;
//
// public String getMake() {
// return make;
// }
//
// @XmlElement
// public void setMake(String make) {
// this.make = make;
// }
//
// public String getManufacturer() {
// return manufacturer;
// }
//
// @XmlElement
// public void setManufacturer(String manufacturer) {
// this.manufacturer = manufacturer;
// }
//
// public String getId() {
// return id;
// }
//
// @XmlAttribute
// public void setId(String id) {
// this.id = id;
// }
//
// public String toString() {
// return "Car [" + "make=" + make + ", manufacturer=" + manufacturer
// + ", id=" + id + "]";
// }
// }
// Path: jaxb-unmarshal-string/src/test/java/info/source4code/jaxb/UnmarshalHelperTest.java
import static org.junit.Assert.assertEquals;
import info.source4code.jaxb.model.Car;
import javax.xml.bind.JAXBException;
import org.junit.BeforeClass;
import org.junit.Test;
package info.source4code.jaxb;
public class UnmarshalHelperTest {
public static String xml;
@BeforeClass
public static void setUpBeforeClass() {
xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" "
+ "standalone=\"yes\"?>"
+ "<ns2:Car xmlns:ns2=\"info.source4code.jaxb.model\" id=\"ABC-123\">"
+ "<make>Passat</make>"
+ "<manufacturer>Volkswagen</manufacturer></ns2:Car>";
}
@Test
public void testUnmarshal() throws JAXBException { | Car car = UnmarshalHelper.unmarshal(xml); |
source4code/repo | jsf-jetty-primefaces-login-servlet-filter/src/test/java/info/source4code/jsf/primefaces/filter/LoginFilterTest.java | // Path: jsf-jetty-primefaces-login-servlet-filter/src/main/java/info/source4code/jsf/primefaces/controller/UserManager.java
// @ManagedBean
// @SessionScoped
// public class UserManager {
//
// private static final Logger LOGGER = LoggerFactory
// .getLogger(UserManager.class);
//
// public static final String HOME_PAGE_REDIRECT = "/secured/home.xhtml?faces-redirect=true";
// public static final String LOGOUT_PAGE_REDIRECT = "/logout.xhtml?faces-redirect=true";
//
// private String userId;
// private String userPassword;
// private User currentUser;
//
// public String login() {
// // lookup the user based on user name and user password
// currentUser = find(userId, userPassword);
//
// if (currentUser != null) {
// LOGGER.info("login successful for '{}'", userId);
//
// return HOME_PAGE_REDIRECT;
// } else {
// LOGGER.info("login failed for '{}'", userId);
// FacesContext.getCurrentInstance().addMessage(
// null,
// new FacesMessage(FacesMessage.SEVERITY_WARN,
// "Login failed",
// "Invalid or unknown credentials."));
//
// return null;
// }
// }
//
// public String logout() {
// String identifier = userId;
//
// // invalidate the session
// LOGGER.debug("invalidating session for '{}'", identifier);
// FacesContext.getCurrentInstance().getExternalContext()
// .invalidateSession();
//
// LOGGER.info("logout successful for '{}'", identifier);
// return LOGOUT_PAGE_REDIRECT;
// }
//
// public boolean isLoggedIn() {
// return currentUser != null;
// }
//
// public String isLoggedInForwardHome() {
// if (isLoggedIn()) {
// return HOME_PAGE_REDIRECT;
// }
//
// return null;
// }
//
// private User find(String userId, String password) {
// User result = null;
//
// // code block to be replaced with actual retrieval of user
// if ("john.doe".equalsIgnoreCase(userId)
// && "1234".equals(password)) {
// result = new User(userId, "John", "Doe");
// }
//
// return result;
// }
//
// public String getUserId() {
// return userId;
// }
//
// public void setUserId(String userId) {
// this.userId = userId;
// }
//
// public String getUserPassword() {
// return userPassword;
// }
//
// public void setUserPassword(String userPassword) {
// this.userPassword = userPassword;
// }
//
// public User getCurrentUser() {
// return currentUser;
// }
//
// // do not provide a setter for currentUser!
// }
| import static org.junit.Assert.fail;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import info.source4code.jsf.primefaces.controller.UserManager;
import java.io.IOException;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner; | package info.source4code.jsf.primefaces.filter;
@RunWith(PowerMockRunner.class)
@PrepareForTest({ FacesContext.class })
public class LoginFilterTest {
private static final String CONTEXT_PATH = "http://localhost:9090/s4c";
| // Path: jsf-jetty-primefaces-login-servlet-filter/src/main/java/info/source4code/jsf/primefaces/controller/UserManager.java
// @ManagedBean
// @SessionScoped
// public class UserManager {
//
// private static final Logger LOGGER = LoggerFactory
// .getLogger(UserManager.class);
//
// public static final String HOME_PAGE_REDIRECT = "/secured/home.xhtml?faces-redirect=true";
// public static final String LOGOUT_PAGE_REDIRECT = "/logout.xhtml?faces-redirect=true";
//
// private String userId;
// private String userPassword;
// private User currentUser;
//
// public String login() {
// // lookup the user based on user name and user password
// currentUser = find(userId, userPassword);
//
// if (currentUser != null) {
// LOGGER.info("login successful for '{}'", userId);
//
// return HOME_PAGE_REDIRECT;
// } else {
// LOGGER.info("login failed for '{}'", userId);
// FacesContext.getCurrentInstance().addMessage(
// null,
// new FacesMessage(FacesMessage.SEVERITY_WARN,
// "Login failed",
// "Invalid or unknown credentials."));
//
// return null;
// }
// }
//
// public String logout() {
// String identifier = userId;
//
// // invalidate the session
// LOGGER.debug("invalidating session for '{}'", identifier);
// FacesContext.getCurrentInstance().getExternalContext()
// .invalidateSession();
//
// LOGGER.info("logout successful for '{}'", identifier);
// return LOGOUT_PAGE_REDIRECT;
// }
//
// public boolean isLoggedIn() {
// return currentUser != null;
// }
//
// public String isLoggedInForwardHome() {
// if (isLoggedIn()) {
// return HOME_PAGE_REDIRECT;
// }
//
// return null;
// }
//
// private User find(String userId, String password) {
// User result = null;
//
// // code block to be replaced with actual retrieval of user
// if ("john.doe".equalsIgnoreCase(userId)
// && "1234".equals(password)) {
// result = new User(userId, "John", "Doe");
// }
//
// return result;
// }
//
// public String getUserId() {
// return userId;
// }
//
// public void setUserId(String userId) {
// this.userId = userId;
// }
//
// public String getUserPassword() {
// return userPassword;
// }
//
// public void setUserPassword(String userPassword) {
// this.userPassword = userPassword;
// }
//
// public User getCurrentUser() {
// return currentUser;
// }
//
// // do not provide a setter for currentUser!
// }
// Path: jsf-jetty-primefaces-login-servlet-filter/src/test/java/info/source4code/jsf/primefaces/filter/LoginFilterTest.java
import static org.junit.Assert.fail;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import info.source4code.jsf.primefaces.controller.UserManager;
import java.io.IOException;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
package info.source4code.jsf.primefaces.filter;
@RunWith(PowerMockRunner.class)
@PrepareForTest({ FacesContext.class })
public class LoginFilterTest {
private static final String CONTEXT_PATH = "http://localhost:9090/s4c";
| private UserManager userManager; |
source4code/repo | jsf-jetty-primefaces-fileupload/src/main/java/info/source4code/jsf/primefaces/controller/FileUploadManager.java | // Path: jsf-jetty-primefaces-fileupload/src/main/java/info/source4code/jsf/primefaces/model/UploadFile.java
// public class UploadFile implements Serializable {
//
// private static final long serialVersionUID = 1L;
//
// private String id;
// private String name;
// private String contentType;
// private long size;
// private byte[] contents;
//
// public UploadFile(String name, String contentType, long size,
// byte[] contents) {
//
// id = UUID.randomUUID().toString();
//
// this.name = name;
// this.contentType = contentType;
// this.size = size;
// this.contents = contents;
// }
//
// public String getId() {
// return id;
// }
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public String getContentType() {
// return contentType;
// }
//
// public void setContentType(String contentType) {
// this.contentType = contentType;
// }
//
// public long getSize() {
// return size;
//
// }
//
// public void setSize(long size) {
// this.size = size;
// }
//
// public byte[] getContents() {
// return contents;
// }
//
// public void setContents(byte[] contents) {
// this.contents = contents;
// }
//
// public long getSizeKB() {
// return size / 1024;
// }
//
// public String toString() {
// return "UploadedFile [" + "id=" + id + ", name=" + name
// + ", contentType=" + contentType + ", size="
// + getSizeKB() + "KB]";
// }
// }
| import info.source4code.jsf.primefaces.model.UploadFile;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.UUID;
import javax.annotation.PostConstruct;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;
import javax.faces.event.PhaseId;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.primefaces.event.FileUploadEvent;
import org.primefaces.model.DefaultStreamedContent;
import org.primefaces.model.StreamedContent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory; | package info.source4code.jsf.primefaces.controller;
@ManagedBean
@SessionScoped
public class FileUploadManager implements Serializable {
private static final long serialVersionUID = 1L;
private static final Logger LOGGER = LoggerFactory
.getLogger(FileUploadManager.class);
// maximum number of files that can be uploaded
public static final int FILE_LIMIT = 3;
// location to which the files will be written
private static final String FILE_SUBMIT_PATH = "target/tmp/flags/";
private static final String TEMP_EXTENSION = "_tmp/";
private String uploadId; | // Path: jsf-jetty-primefaces-fileupload/src/main/java/info/source4code/jsf/primefaces/model/UploadFile.java
// public class UploadFile implements Serializable {
//
// private static final long serialVersionUID = 1L;
//
// private String id;
// private String name;
// private String contentType;
// private long size;
// private byte[] contents;
//
// public UploadFile(String name, String contentType, long size,
// byte[] contents) {
//
// id = UUID.randomUUID().toString();
//
// this.name = name;
// this.contentType = contentType;
// this.size = size;
// this.contents = contents;
// }
//
// public String getId() {
// return id;
// }
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public String getContentType() {
// return contentType;
// }
//
// public void setContentType(String contentType) {
// this.contentType = contentType;
// }
//
// public long getSize() {
// return size;
//
// }
//
// public void setSize(long size) {
// this.size = size;
// }
//
// public byte[] getContents() {
// return contents;
// }
//
// public void setContents(byte[] contents) {
// this.contents = contents;
// }
//
// public long getSizeKB() {
// return size / 1024;
// }
//
// public String toString() {
// return "UploadedFile [" + "id=" + id + ", name=" + name
// + ", contentType=" + contentType + ", size="
// + getSizeKB() + "KB]";
// }
// }
// Path: jsf-jetty-primefaces-fileupload/src/main/java/info/source4code/jsf/primefaces/controller/FileUploadManager.java
import info.source4code.jsf.primefaces.model.UploadFile;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.UUID;
import javax.annotation.PostConstruct;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;
import javax.faces.event.PhaseId;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.primefaces.event.FileUploadEvent;
import org.primefaces.model.DefaultStreamedContent;
import org.primefaces.model.StreamedContent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
package info.source4code.jsf.primefaces.controller;
@ManagedBean
@SessionScoped
public class FileUploadManager implements Serializable {
private static final long serialVersionUID = 1L;
private static final Logger LOGGER = LoggerFactory
.getLogger(FileUploadManager.class);
// maximum number of files that can be uploaded
public static final int FILE_LIMIT = 3;
// location to which the files will be written
private static final String FILE_SUBMIT_PATH = "target/tmp/flags/";
private static final String TEMP_EXTENSION = "_tmp/";
private String uploadId; | private List<UploadFile> uploadedFiles; |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.