text:
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import javax.swing.event.*;
import java.applet.*;
import java.net.*;
import java.util.*;
import java.io.*;

/** The RubrusBoard class - carries out the tasks necessary to play the game
  * Tracks data and uses the RubrusPiece class objects
  * @author Tristan Amini, Victor Cong, Chen Chou
  * @version January 2012
  */
public class RubrusBoard extends JPanel implements MouseListener
{
    // Map to track placed pieces
    private int[] [] map;
    // Player who's turn it is
    private int currentPlayer = 1;
    // Pieces for all players
    private RubrusPiece playerPieces[] [];
    // Piece that is selected
    private int pieceMoving;
    private RubrusPiece movingPiece;
    // Coordinates of piece
    private Point lastPoint;
    // Music/audio
    private AudioClip backgroundSound;
    private AudioClip playerSkipSound;
    private AudioClip pieceSnapSound;
    private AudioClip instructionsSound;
    private AudioClip winnerSound;
    private AudioClip buttonSound;
    private AudioClip creditsSound;
    private boolean playerChange = false;
    // Images for menus
    private Image logo = new ImageIcon ("RubrusLogo.png").getImage ();
    private Image instructions1 = new ImageIcon ("Instructions-01.jpg").getImage ();
    private Image instructions2 = new ImageIcon ("Instructions-02.jpg").getImage ();
    private Image instructions3 = new ImageIcon ("Instructions-03.jpg").getImage ();
    private Image instructions4 = new ImageIcon ("Instructions-04.jpg").getImage ();
    private Image mainMenu = new ImageIcon ("MainMenu.jpg").getImage ();
    private Image credits = new ImageIcon ("About.jpg").getImage ();
    private Image rules = new ImageIcon ("Rules.jpg").getImage ();
    private Image modeChoice = new ImageIcon ("ModeSelect.jpg").getImage ();
    private Image endScreen = new ImageIcon ("EndScreen.jpg").getImage ();
    private Image background = new ImageIcon ("Background.jpg").getImage ();
    // Starting menu to show
    private Image menuToShow = mainMenu;
    private String menuShowing = "MainMenu";
    // Colours for each player
    private final Color[] COLOURS = {Color.WHITE, Color.BLUE, Color.RED, Color.GREEN, Color.ORANGE, Color.BLACK};
    // Array to track how many pieces each player has left
    private int[] piecesLeft = {0, 21, 21, 21, 21};
    // Which players are still in the game
    private boolean[] playersLeft = {false, true, true, true, true};
    // Each players score
    private int[] playerScore = new int [4];
    // Checks for game over and how many players are out
    private boolean gameOver = false;
    private int skipCount = 0;
    // Highest score and player that scored it
    private int highestScore = 0;
    private int highestPlayer = 0;
    // Fonts
    Font font1 = new Font ("Helvetica", Font.PLAIN, 20);
    Font font2 = new Font ("Arial", Font.PLAIN, 40);
    // Modes
    private static int mode = 1;
    private static int pieceMode = 1;
    // Ties and whether game has started
    private boolean tie = false;
    private boolean gameStart = false;

    /** Constructs a new RubrusBoard object
      */
    public RubrusBoard ()
    {
	// Sets up the board area, loads in piece images and starts a new game
	setPreferredSize (new Dimension (805, 830));
	// Add mouse listeners and Key Listeners to the game board
	addMouseListener (this);
	addMouseMotionListener (new MouseMotionHandler ());
	this.setFocusable (true);
	this.addKeyListener (new KeyHandler ());
	this.requestFocusInWindow ();
	// Set up all music
	playerSkipSound = Applet.newAudioClip (getCompleteURL ("playerSkip.wav"));
	pieceSnapSound = Applet.newAudioClip (getCompleteURL ("pieceSnap.wav"));
	instructionsSound = Applet.newAudioClip (getCompleteURL ("instructionsSound.wav"));
	winnerSound = Applet.newAudioClip (getCompleteURL ("winnerSound.wav"));
	creditsSound = Applet.newAudioClip (getCompleteURL ("creditsSound.wav"));
	buttonSound = Applet.newAudioClip (getCompleteURL ("button.wav"));
	backgroundSound = Applet.newAudioClip (getCompleteURL ("backgroundMusic.wav"));

	// Save map size
	map = new int [20] [20];
	// Set up all pieces
	playerPieces = new RubrusPiece [5] [21];
	for (int piece = 0 ; piece < 21 ; piece++)
	{
	    playerPieces [1] [piece] = new RubrusPiece ();
	}
	for (int piece = 0 ; piece < 21 ; piece++)
	{
	    playerPieces [2] [piece] = new RubrusPiece ();
	}
	for (int piece = 0 ; piece < 21 ; piece++)
	{
	    playerPieces [3] [piece] = new RubrusPiece ();
	}
	for (int piece = 0 ; piece < 21 ; piece++)
	{
	    playerPieces [4] [piece] = new RubrusPiece ();
	}
	// Set up pieces
	pieceMoving = -1;
	movingPiece = null;
	backgroundSound.loop ();
    } // contructor

    /** Gets the URL needed for newAudioClip
      * @param fileName The name of the audio file
      */
    public URL getCompleteURL (String fileName)
    {
	try
	{
	    return new URL ("file:" + System.getProperty ("user.dir") + "/" + fileName);
	}
	catch (MalformedURLException e)
	{
	    System.err.println (e.getMessage ());
	}
	return null;
    }

    /** Draws the menu screen that is clicked on
      * @param mouseX       the X coordinate the mouse clicked on
      * @param mouseY       the Y coordinate the mouse clicked on
      */
    private void menu (int mouseX, int mouseY)
    {
	// Main menu
	if (menuShowing.equals ("MainMenu"))
	{
	    menuToShow = mainMenu;
	    // Clicking on mode choice
	    if (mouseX > 23 && mouseX < 420 && mouseY > 265 && mouseY < 360)
	    {
		buttonSound.play ();

		menuToShow = modeChoice;
		menuShowing = "ModeChoice";
	    }
	    // Clicking on instructions
	    else if (mouseX > 23 && mouseX < 430 && mouseY > 385 && mouseY < 480)
	    {
		buttonSound.play ();
		menuShowing = "Instructions1";
		menuToShow = instructions1;
		backgroundSound.stop ();
		instructionsSound.loop ();
	    }
	    // Clicking on Rules
	    else if (mouseX > 23 && mouseX < 223 && mouseY > 515 && mouseY < 610)
	    {
		buttonSound.play ();
		menuShowing = "Rules";
		menuToShow = rules;
	    }
	    // Clicking on Exit
	    else if (mouseX > 23 && mouseX < 169 && mouseY > 715 && mouseY < 810)
	    {
		hide ();
		System.exit (0);
	    }
	    // Clicking on Credits
	    else if (mouseX > 620 && mouseX < 810 && mouseY > 770 && mouseY < 815)
	    {
		buttonSound.play ();
		menuShowing = "Credits";
		menuToShow = credits;
		backgroundSound.stop ();
		creditsSound.loop ();
	    }
	}
	// Showing instructions
	else if (menuShowing.equals ("Instructions1"))
	{
	    // Clicking on next
	    if (mouseX > 650 && mouseX < 900 && mouseY > 770 && mouseY < 830)
	    {
		buttonSound.play ();
		menuShowing = "Instructions2";
		menuToShow = instructions2;
	    }
	}
	else if (menuShowing.equals ("Instructions2"))
	{
	    // Clicking on next
	    if (mouseX > 650 && mouseX < 900 && mouseY > 770 && mouseY < 830)
	    {
		buttonSound.play ();
		menuShowing = "Instructions3";
		menuToShow = instructions3;
	    }
	}
	else if (menuShowing.equals ("Instructions3"))
	{
	    // Clicking on next
	    if (mouseX > 650 && mouseX < 900 && mouseY > 770 && mouseY < 830)
	    {
		buttonSound.play ();
		menuShowing = "Instructions4";
		menuToShow = instructions4;
	    }
	}
	else if (menuShowing.equals ("Instructions4"))
	{
	    // Clicking on back
	    if (mouseX > 650 && mouseX < 900 && mouseY > 770 && mouseY < 830)
	    {
		buttonSound.play ();
		instructionsSound.stop ();
		backgroundSound.loop ();
		menuShowing = "MainMenu";
		menuToShow = mainMenu;
	    }
	}
	// Show rules
	else if (menuShowing.equals ("Rules"))
	{
	    // Clicking on back
	    if (mouseX > 650 && mouseX < 900 && mouseY > 770 && mouseY < 830)
	    {
		buttonSound.play ();
		menuShowing = "MainMenu";
		menuToShow = mainMenu;
	    }
	}
	// Show credits
	else if (menuShowing.equals ("Credits"))
	{
	    // Clicking on back
	    if (mouseX > 650 && mouseX < 900 && mouseY > 770 && mouseY < 830)
	    {
		buttonSound.play ();
		creditsSound.stop ();
		backgroundSound.loop ();
		menuShowing = "MainMenu";
		menuToShow = mainMenu;
	    }
	}
	// Show mode select screen
	else if (menuShowing.equals ("ModeChoice"))
	{
	    // Back to menu
	    if (mouseX > 650 && mouseX < 900 && mouseY > 770 && mouseY < 830)
	    {
		buttonSound.play ();
		menuShowing = "MainMenu";
		menuToShow = mainMenu;
	    }
	    // Start Game
	    else if (mouseX > 0 && mouseX < 280 && mouseY > 770 && mouseY < 830)
	    {
		buttonSound.play ();
		gameStart = true;
		setUpPieces ();
		if (mode == 2 || mode == 4)
		{
		    skipCount = 2;
		    playersLeft [2] = false;
		    playersLeft [3] = false;
		}

	    }
	    // 4 Player
	    else if (mouseX > 65 && mouseX < 380 && mouseY > 215 && mouseY < 279)
	    {
		buttonSound.play ();
		mode = 1;
	    }
	    // 2 Player
	    else if (mouseX > 385 && mouseX < 685 && mouseY > 215 && mouseY < 279)
	    {
		buttonSound.play ();
		mode = 2;
	    }
	    // 4 Player Center
	    else if (mouseX > 65 && mouseX < 380 && mouseY > 280 && mouseY < 344)
	    {
		buttonSound.play ();
		mode = 3;
	    }
	    // Team
	    else if (mouseX > 65 && mouseX < 380 && mouseY > 355 && mouseY < 419)
	    {
		buttonSound.play ();
		mode = 5;
	    }
	    // 2 Player Center
	    else if (mouseX > 385 && mouseX < 685 && mouseY > 280 && mouseY < 344)
	    {
		buttonSound.play ();
		mode = 4;
	    }
	    // Regular pieces
	    if (mouseX > 50 && mouseX < 360 && mouseY > 575 && mouseY < 685)
	    {
		buttonSound.play ();
		pieceMode = 1;
	    }
	    // Alternate Pieces
	    else if (mouseX > 365 && mouseX < 730 && mouseY > 575 && mouseY < 685)
	    {
		buttonSound.play ();
		pieceMode = 2;
	    }
	}
	// Show end screen
	else if (menuShowing.equals ("EndScreen"))
	{
	    // Clicking anywhere
	    if (mouseX > 0 && mouseY > 0)
	    {
		hide ();
		System.exit (0);
	    }
	}
    }

    /** Starts a new game
      */
    public void newGame ()
    {
	// Resets game variables
	gameStart = false;
	gameOver = false;
	skipCount = 0;
	highestPlayer = 0;
	highestScore = 0;
	tie = false;
	repaint ();
	// Reset grid
	map = new int [20] [20];
	// Reset scores
	playerScore = new int [4];
	// Reset player and pieces
	playerPieces = new RubrusPiece [5] [21];
	for (int piece = 0 ; piece < 21 ; piece++)
	{
	    playerPieces [1] [piece] = new RubrusPiece ();
	}
	for (int piece = 0 ; piece < 21 ; piece++)
	{
	    playerPieces [2] [piece] = new RubrusPiece ();
	}
	for (int piece = 0 ; piece < 21 ; piece++)
	{
	    playerPieces [3] [piece] = new RubrusPiece ();
	}
	for (int piece = 0 ; piece < 21 ; piece++)
	{
	    playerPieces [4] [piece] = new RubrusPiece ();
	}
	// Resets all pieces back to inventory
	for (int i = 1 ; i < 4 ; i++)
	    piecesLeft [i] = 21;
	// Resets inventory
	pieceMoving = -1;
	movingPiece = null;
	// Player resets to 1
	currentPlayer = 1;
	// Reset players
	for (int player = 1 ; player > 4 ; player++)
	    playersLeft [player] = true;
    }

    /** Returns the mode of the game (4 player, 2 player, centered, etc.)
      * @return The current mode of the game
      */
    public static int getMode ()
    {
	return mode;
    }

    /** Returns the mode of the pieces (normal, alternate)
      * @return The current piece mode of the game
      */
    public static int getPieceMode ()
    {
	return pieceMode;
    }

    /** Places pieces into array
      */
    public void setUpPieces ()
    {
	// Places all pieces from all players into the array
	for (int player = 1 ; player < 5 ; player++)
	{
	    for (int piece = 0 ; piece < 21 ; piece++)
	    {
		playerPieces [player] [piece].placeInArray (piece);
	    }
	}
    }

    /** Places pieces into array
      * @param player The player to draw pieces for
      */
    public void setUpPieces (int player)
    {
	// Places all pieces into the array for the given player
	for (int piece = 0 ; piece < 21 ; piece++)
	{
	    playerPieces [player] [piece].placeInArray (piece);
	}
    }

    /** Changes the player to the next valid player
      */
    private void changePlayer ()
    {
	// If 1 piece is left, reset pieces for that player so they can keep playing
	if (piecesLeft [currentPlayer] == 1)
	{
	    setUpPieces (currentPlayer);
	    piecesLeft [currentPlayer] = 21;
	}
	do
	{
	    // Checks if all players are out
	    if (!isGameOver ())
	    {
		gameOver = true;
		gameOver ();
	    }
	    // Increase current player
	    currentPlayer++;
	    // Sets current player to 1 to not get more than 4
	    if (currentPlayer > 4)
		currentPlayer = 1;
	}
	while (!canPlay () && skipCount < 4);
	// Checks if everyone has skipped
	if (skipCount == 4)
	    gameOver = true;
	repaint ();
	// No longer needs to change players
	playerChange = false;

    }

    /** Checks if the current player can play
      * @return Whether the player can play or not
      */
    private boolean canPlay ()
    {
	// If player has no pieces, their turn must be skipped
	if (piecesLeft [currentPlayer] == 0)
	{
	    playersLeft [currentPlayer] = false;
	    skipCount++;
	}
	// Makes sure player is still in game
	if (playersLeft [currentPlayer])
	{
	    return true;
	}
	else
	{
	    return false;
	}

    }

    /** Adjusts the players score
      */
    private void playerScore ()
    {
	playerScore [currentPlayer - 1] += playerPieces [currentPlayer] [pieceMoving].getPieceScore ();
    }

    /** Compares scores to figure out the winner
      */
    private void checkWinner ()
    {
	// Free for all
	if (mode != 5)
	{
	    // Runs through all 4 players
	    for (int player = 0 ; player < 4 ; player++)
	    {
		// If score is higher than the current highscore
		if (playerScore [player] > highestScore)
		{
		    // The player becomes the new high player
		    // and his score becomes the high score
		    tie = false;
		    highestScore = playerScore [player];
		    highestPlayer = player + 1;
		}
		// If the score is equal to the top score
		else if (playerScore [player] == highestScore && highestPlayer != player + 1)
		{
		    // The players tie with the same highscore
		    tie = true;
		    highestScore = playerScore [player];
		}
	    }
	}
	// Team mode
	else
	{
	    // Team 1 has a higher score
	    if (playerScore [0] + playerScore [3] > playerScore [1] + playerScore [2])
	    {
		highestPlayer = 1;
		highestScore = playerScore [0] + playerScore [3];
	    }
	    // Scores are the same
	    else if (playerScore [0] + playerScore [3] == playerScore [1] + playerScore [2])
	    {
		// Team 1 and 2 tie with the same score
		tie = true;
		highestScore = playerScore [0] + playerScore [3];
	    }
	    // Team 2 has a higher score
	    else
	    {
		highestPlayer = 2;
		highestScore = playerScore [1] + playerScore [2];
	    }
	}
    }

    /** Checks if all players are out
      * @return Whether the game is over or not
      */
    private boolean isGameOver ()
    {
	for (int playerToCheck = 1 ; playerToCheck > 4 ; playerToCheck++)
	{
	    System.out.println (playerToCheck);
	    if (playersLeft [playerToCheck])
		return false;
	}
	return true;
    }

    /** Checks the winner and runs the end screen
      */
    private void gameOver ()
    {
	// Checks the winner
	checkWinner ();
	// The game is over, set the screen to end screen
	gameStart = false;
	menuToShow = endScreen;
	menuShowing = "EndScreen";
    }

    /** Displays the winner(s)
      */
    private void drawGameOver (Graphics g)
    {
	repaint (0);
	winnerSound.play ();
	g.setColor (COLOURS [0]);
	g.setFont (font2);
	// One winner
	if (!tie)
	{
	    // Free for all mode
	    if (mode != 5)
	    {
		g.drawString ("Player " + highestPlayer + " wins with a score of " + highestScore + "!", 140, 535);
	    }
	    //Team mode
	    else
	    {
		g.drawString ("Team " + highestPlayer + " wins with a score of " + highestScore + "!", 135, 535);
	    }
	}
	// More than one winner
	else
	{
	    g.drawString ("It's a tie with a score of " + highestScore + "!", 185, 535);
	}
    }

    /** Draws the box where the unused pieces are held
      * @param g    the graphics to draw in
      */
    public void drawItemBox (Graphics g)
    {
	g.setColor (COLOURS [currentPlayer]);
	g.fillRect (0, 520, 790, 300);
	g.setColor (COLOURS [0]);
	g.fillRect (10, 530, 770, 280);
	g.setColor (COLOURS [5]);
	g.drawRect (10, 530, 770, 280);
    }

    /** Draws the boxes to hold mini inventories
      * @param numPlayers   the number of players to draw boxes for
      * @param g    the graphics to draw in
      */
    public void drawPlayerBoxes (int numPlayers, Graphics g)
    {
	for (int boxCount = 0 ; boxCount < numPlayers ; boxCount++)
	{
	    g.setColor (COLOURS [boxCount + 1]);
	    g.fillRect (520, 75 + 108 * boxCount, 275, 100);
	    if (boxCount < 2)
		g.fillRect (665, 5 + 34 * boxCount, 61, 30);
	    else
		g.fillRect (735, 5 + 34 * (boxCount - 2), 61, 30);
	    g.setColor (COLOURS [0]);
	    g.fillRect (525, 80 + 108 * boxCount, 265, 90);
	    if (boxCount < 2)
		g.fillRect (668, 7 + 34 * boxCount, 56, 26);
	    else
		g.fillRect (738, 7 + 34 * (boxCount - 2), 56, 26);
	    g.setColor (COLOURS [5]);
	    g.drawRect (520, 75 + 108 * boxCount, 275, 100);
	    if (boxCount < 2)
		g.drawRect (665, 5 + 34 * boxCount, 61, 30);
	    else
		g.drawRect (735, 5 + 34 * (boxCount - 2), 61, 30);
	}
    }

    /** Updates the player scores
      * @param g    the graphics to draw in
      */
    public void drawPlayerScore (Graphics g)
    {
	for (int players = 0 ; players < 4 ; players++)
	{
	    // Display the score
	    g.setColor (Color.BLACK);
	    g.setFont (font1);
	    // Draws in the 2 boxes on the left
	    if (players < 2)
		g.drawString ("" + playerScore [players], 684, 30 + (34 * players));
	    // Draws in the 2 boxes on the right
	    else
		g.drawString ("" + playerScore [players], 755, 30 + (34 * (players - 2)));
	}
    }

    /** Draws the pieces placed on the board
      * @param g The graphics to draw in
      */
    public void drawPlacedPieces (Graphics g)
    {
	// Scan board
	for (int row = 0 ; row < map.length ; row++)
	{
	    for (int col = 0 ; col < 20 ; col++)
	    {
		// Draw different colour depending on piece
		if (map [row] [col] > 0)
		{
		    g.setColor (COLOURS [map [row] [col]]);
		    g.fillRect (25 * col, 25 * row, 25, 25);
		}
	    }
	}
    }

    /** Draws the grid where the pieces will be placed
      * @param g The graphics to draw in
      */
    public void drawGrid (Graphics g)
    {
	g.setColor (Color.black);
	// Horizontal Lines
	for (int lineCount = 0 ; lineCount < 21 ; lineCount++)
	{
	    g.drawLine (0, lineCount * 25, 20 * 25, lineCount * 25);
	}
	// Vertical lines
	for (int lineCount = 0 ; lineCount < 21 ; lineCount++)
	{
	    g.drawLine (lineCount * 25, 0, lineCount * 25, 20 * 25);
	}
    }

    /** Draws small starting circles
      * @param g    the graphics to draw in
      */
    public void drawStartCircles (Graphics g)
    {
	// Standard four player/ team 4 player/ alternate pieces four player
	if (mode == 1 || mode == 5)
	{
	    g.setColor (COLOURS [1]);
	    g.fillOval (7, 7, 12, 12);
	    g.setColor (COLOURS [2]);
	    g.fillOval (482, 7, 12, 12);
	    g.setColor (COLOURS [3]);
	    g.fillOval (7, 482, 12, 12);
	    g.setColor (COLOURS [4]);
	    g.fillOval (482, 482, 12, 12);
	}
	// Two player standard
	else if (mode == 2)
	{
	    g.setColor (COLOURS [1]);
	    g.fillOval (7, 7, 12, 12);
	    g.setColor (COLOURS [4]);
	    g.fillOval (482, 482, 12, 12);
	    playersLeft [2] = false;
	    playersLeft [3] = false;
	}
	// Centered 4 player
	else if (mode == 3)
	{
	    g.setColor (COLOURS [1]);
	    g.fillOval (132, 132, 12, 12);
	    g.setColor (COLOURS [2]);
	    g.fillOval (382, 132, 12, 12);
	    g.setColor (COLOURS [3]);
	    g.fillOval (132, 382, 12, 12);
	    g.setColor (COLOURS [4]);
	    g.fillOval (382, 382, 12, 12);
	}
	// Centered 4 player
	else if (mode == 4)
	{
	    g.setColor (COLOURS [1]);
	    g.fillOval (132, 132, 12, 12);
	    g.setColor (COLOURS [4]);
	    g.fillOval (382, 382, 12, 12);
	}
    }

    /** Draws the inventory
      * @param g The graphics to use
      */
    private void drawInventory (Graphics g)
    {
	for (int currentPiece = 0 ; currentPiece < 21 ; currentPiece++)
	{
	    g.setColor (Color.ORANGE);
	    playerPieces [currentPlayer] [currentPiece].drawPiece (g, COLOURS [currentPlayer]);
	}
    }

    /** Draws the little pieces in the small boxes
      * @param g    The graphics to draw in
      */
    private void drawLittlePiece (Graphics g)
    {
	for (int player = 0 ; player < 4 ; player++)
	{
	    if (mode != 2 || mode == 2 && player == 0 || mode == 2 && player == 3)
	    {
		for (int currentPiece = 0 ; currentPiece < 21 ; currentPiece++)
		{
		    if (!playerPieces [player + 1] [currentPiece].isPiecePlaced ())
			playerPieces [player + 1] [currentPiece].drawLittlePieces (g, COLOURS [player + 1], player);
		}
	    }
	}
    }

    /** Repaint the board's drawing panel
	  * @param g The graphics context
	  */
    public void paintComponent (Graphics g)
    {
	super.paintComponent (g);
	// If game is running, show board, pieces, etc.
	if (gameStart)
	{
	    // Draw background
	    g.drawImage (background, 0, 0, this);
	    // Draw white background for grid
	    g.setColor (Color.white);
	    g.fillRect (0, 0, 500, 500);
	    // Draws all player components
	    drawPlayerBoxes (4, g);
	    drawStartCircles (g);
	    drawPlacedPieces (g);
	    drawGrid (g);
	    if (playerChange)
		changePlayer ();
	    drawItemBox (g);
	    drawLittlePiece (g);
	    drawInventory (g);
	    // Draws the logo
	    g.drawImage (logo, 520, -18, this);
	    drawPlayerScore (g);
	}
	// Show menu
	else
	{
	    g.drawImage (menuToShow, 0, 0, this);
	    // IF game over, go to game over screen
	    if (gameOver)
	    {
		gameOver ();
		drawGameOver (g);
	    }
	}
    } // paint component method

    /** Checks if the move is valid
      *@param mouseX The X placement of the mouse when piece is dropped
      *@param mouseY The Y placement of the mouse when piece is dropped
      *@return Whether the move is valid or not
      */
    public boolean validMove (int mouseX, int mouseY)
    {
	repaint ();
	// Checks if mouse is within grid
	if (mouseX >= 0 && mouseX <= 500 && mouseY >= 0 && mouseY <= 500)
	    return true;
	// Move is not valid
	return false;
    }

    /** Places the current piece onto the grid
      */
    private void placeOnGrid ()
    {

	playerPieces [currentPlayer] [pieceMoving].snapToGrid ();
	// Makes sure the piece can be placed
	if (!playerPieces [currentPlayer] [pieceMoving].placeOnMap (map, currentPlayer))
	{
	    playerPieces [currentPlayer] [pieceMoving].placeInArray (pieceMoving);
	    currentPlayer--;
	}
	else
	    // Lower number of pieces remaining for current player
	    {
		pieceSnapSound.play ();
		piecesLeft [currentPlayer]--;
		playerPieces [currentPlayer] [pieceMoving].placeInArray (-1);
		playerScore ();
	    }
	repaint ();
    }

    // Keyboard events you can listen for since this JPanel is a KeyListener
    private class KeyHandler extends KeyAdapter
    {
	/** Responds to a dragging the mouse
	  * @param event Pressing and releasing on a certain key
	  */
	public void keyReleased (KeyEvent event)
	{
	    if (pieceMoving != -1)
	    {
		// Pressing 'w','a','s','d' will flip the piece moving
		if (event.getKeyCode () == KeyEvent.VK_D || event.getKeyCode () == KeyEvent.VK_A)
		{
		    playerPieces [currentPlayer] [pieceMoving].flipPieceColumn ();
		}
		else if (event.getKeyCode () == KeyEvent.VK_W || event.getKeyCode () == KeyEvent.VK_S)
		{

		    playerPieces [currentPlayer] [pieceMoving].flipPieceRow ();
		}
	    }
	    // Repaint the screen after the change
	    repaint ();
	    // Game has started, allowing skipping turns and quitting
	    if (gameStart)
	    {
		// Space pressed, skip player's turn from now on
		if (event.getKeyCode () == KeyEvent.VK_SPACE)
		{
		    playersLeft [currentPlayer] = false;
		    skipCount++;
		    if (skipCount < 4)
		    {
			changePlayer ();
			playerSkipSound.play ();
			repaint ();
		    }
		    else
		    {
			gameOver = true;
			gameStart = false;
		    }
		}
		// Escape pressed, quit the game
		if (event.getKeyCode () == KeyEvent.VK_ESCAPE)
		{
		    hide ();
		    System.exit (0);
		}
	    }
	}
    }

    private class MouseMotionHandler extends MouseMotionAdapter
    {
	/** Responds to a dragging the mouse
	  * @param event The dragging of the mouse
	  */
	public void mouseDragged (MouseEvent event)
	{
	    if (gameStart)
	    {
		// Change position of piece being moved
		if (movingPiece != null)
		{
		    movingPiece.translate (lastPoint, event.getPoint ());
		    lastPoint = event.getPoint ();
		}
	    }
	    repaint ();
	}
    }

    /** Checks to see if the left mouse button has been clicked over a piece
      * @param event The left mouse button press
      */
    public void mousePressed (MouseEvent event)
    {
	// Only if game has started
	if (gameStart)
	{
	    // Gets the coordinates of the last mouse position
	    Point selectedPoint = event.getPoint ();
	    // Checks each piece if the point is contained in one of the pieces
	    for (int i = 0 ; i < 21 ; i++)
	    {
		// If it does contain the point, the piece becomes the moving piece
		if (playerPieces [currentPlayer] [i].contains (selectedPoint))
		{
		    // Piece becomes the moving piece
		    movingPiece = playerPieces [currentPlayer] [i];
		    pieceMoving = i;
		    lastPoint = selectedPoint;
		}
	    }
	    // If piece has been placed, it cannot be moved again
	    if (pieceMoving != -1 && playerPieces [currentPlayer] [pieceMoving].isPiecePlaced ())
	    {
		pieceMoving = -1;
		movingPiece = null;
	    }
	}
	repaint ();
	return;
    }

    /** Detects when the mouse button has been released
      * @param event Releasing the mouse button
      */
    public void mouseReleased (MouseEvent event)
    {
	if (gameStart)
	{
	    if (event.getModifiers () == MouseEvent.BUTTON1_MASK)
	    {
		if (pieceMoving != -1)
		{
		    // Check if piece is in valid position

		    if (validMove (event.getX (), event.getY ()))
		    {
			placeOnGrid ();
		    }
		    else
		    {
			playerPieces [currentPlayer] [pieceMoving].resetPosition ();
		    }
		}
		// Checks to make sure the move is valid before changing players
		if (pieceMoving != -1 && validMove (event.getX (), event.getY ()))
		    changePlayer ();
		pieceMoving = -1;
		movingPiece = null;
	    }
	}
	repaint ();
    }

    /** Checks for then the button has been cliked, only used for right mouse button
      * @param event The right mouse button click
      */
    public void mouseClicked (MouseEvent event)
    {
	// Only when game has started
	if (gameStart)
	{
	    // Rotate piece clockwise when right-clicked
	    if (event.getModifiers () == MouseEvent.BUTTON3_MASK && pieceMoving != -1)
	    {
		playerPieces [currentPlayer] [pieceMoving].rotateClockwise ();
	    }
	}
	else
	    menu (event.getX (), event.getY ());
	repaint ();
    }

    // Unused methods for mouseListener
    public void mouseEntered (MouseEvent event)
    {
    }

    public void mouseExited (MouseEvent event)
    {
    }
}


text:
package org.apache.dubbo.metadata.annotation.processing.builder;

import org.apache.dubbo.metadata.annotation.processing.AbstractAnnotationProcessingTest;
import org.apache.dubbo.metadata.definition.model.ServiceDefinition;
import org.apache.dubbo.metadata.tools.TestServiceImpl;

import org.junit.jupiter.api.Test;

import java.util.Set;

import static org.apache.dubbo.metadata.annotation.processing.builder.ServiceDefinitionBuilder.build;
import static org.junit.jupiter.api.Assertions.assertEquals;

/**
 * {@link ServiceDefinitionBuilder} Test
 *
 * @since 2.7.6
 */
public class ServiceDefinitionBuilderTest extends AbstractAnnotationProcessingTest {

    @Override
    protected void addCompiledClasses(Set<Class<?>> classesToBeCompiled) {
        classesToBeCompiled.add(TestServiceImpl.class);
    }

    @Override
    protected void beforeEach() {
    }

    @Test
    public void testBuild() {
        ServiceDefinition serviceDefinition = build(processingEnv, getType(TestServiceImpl.class));
        assertEquals(TestServiceImpl.class.getTypeName(), serviceDefinition.getCanonicalName());
        assertEquals("org/apache/dubbo/metadata/tools/TestServiceImpl.class", serviceDefinition.getCodeSource());
        // types
        int i = 0;
        assertEquals("org.apache.dubbo.metadata.tools.TestServiceImpl", serviceDefinition.getTypes().get(i++).getType());
        assertEquals("org.apache.dubbo.metadata.tools.GenericTestService", serviceDefinition.getTypes().get(i++).getType());
        assertEquals("org.apache.dubbo.metadata.tools.DefaultTestService", serviceDefinition.getTypes().get(i++).getType());
        assertEquals("org.apache.dubbo.metadata.tools.TestService", serviceDefinition.getTypes().get(i++).getType());
        assertEquals("java.lang.AutoCloseable", serviceDefinition.getTypes().get(i++).getType());
        assertEquals("java.io.Serializable", serviceDefinition.getTypes().get(i++).getType());
        assertEquals("java.util.EventListener", serviceDefinition.getTypes().get(i++).getType());
        // methods
        assertEquals(14, serviceDefinition.getMethods().size());
    }
}

redpajama_set_name: RedPajamaGithub


text:
package org.eclipse.bpel.model.impl;

import org.eclipse.bpel.model.BPELPackage;
import org.eclipse.bpel.model.Expression;
import org.eclipse.bpel.model.util.BPELConstants;
import org.eclipse.bpel.model.util.BPELUtils;
import org.eclipse.bpel.model.util.ReconciliationHelper;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.wst.wsdl.internal.impl.ExtensibilityElementImpl;
import org.eclipse.wst.wsdl.WSDLElement;
import org.w3c.dom.Element;

/**
 *
 * An implementation of the model object 'Expression'.
 *
 *

 * The following features are implemented:
 *

 *
{@link org.eclipse.bpel.model.impl.ExpressionImpl#getBody Body}

 *
{@link org.eclipse.bpel.model.impl.ExpressionImpl#getExpressionLanguage Expression Language}

 *
{@link org.eclipse.bpel.model.impl.ExpressionImpl#getOpaque Opaque}

 *

 *

 *
 * @generated
 */
public class ExpressionImpl extends ExtensibilityElementImpl implements
		Expression {
	/**
	 * The default value of the '{@link #getBody() Body}' attribute.
	 *
	 *
	 * @see #getBody()
	 * @generated
	 * @ordered
	 */
	protected static final Object BODY_EDEFAULT = null;

	/**
	 * The cached value of the '{@link #getBody() Body}' attribute.
	 *
	 *
	 * @see #getBody()
	 * @generated
	 * @ordered
	 */
	protected Object body = BODY_EDEFAULT;

	/**
	 * The default value of the '{@link #getExpressionLanguage() Expression Language}' attribute.
	 *
	 *
	 * @see #getExpressionLanguage()
	 * @generated
	 * @ordered
	 */
	protected static final String EXPRESSION_LANGUAGE_EDEFAULT = null;

	/**
	 * The cached value of the '{@link #getExpressionLanguage() Expression Language}' attribute.
	 *
	 *
	 * @see #getExpressionLanguage()
	 * @generated
	 * @ordered
	 */
	protected String expressionLanguage = EXPRESSION_LANGUAGE_EDEFAULT;

	/**
	 * This is true if the Expression Language attribute has been set.
	 *
	 *
	 * @generated
	 * @ordered
	 */
	protected boolean expressionLanguageESet;

	/**
	 * The default value of the '{@link #getOpaque() Opaque}' attribute.
	 *
	 *
	 * @see #getOpaque()
	 * @generated
	 * @ordered
	 */
	protected static final Boolean OPAQUE_EDEFAULT = null;

	/**
	 * The cached value of the '{@link #getOpaque() Opaque}' attribute.
	 *
	 *
	 * @see #getOpaque()
	 * @generated
	 * @ordered
	 */
	protected Boolean opaque = OPAQUE_EDEFAULT;

	/**
	 * This is true if the Opaque attribute has been set.
	 *
	 *
	 * @generated
	 * @ordered
	 */
	protected boolean opaqueESet;

	/**
	 *
	 *
	 * @generated
	 */
	protected ExpressionImpl() {
		super();
	}

	/**
	 *
	 *
	 * @generated
	 */

	protected EClass eStaticClass() {
		return BPELPackage.Literals.EXPRESSION;
	}

	/**
	 *
	 *
	 * @generated
	 */
	public Object getBody() {
		return body;
	}

	/**
	 *
	 *
	 */
	public void setBody(Object newBody) {
		Object oldBody = body;

		BPELExtensibleElementImpl parent = ((BPELExtensibleElementImpl) eContainer());
		boolean transparent = BPELUtils.isTransparent(eContainer(), this);

		if ((!transparent && !isReconciling)
				|| (transparent && !parent.isReconciling())) {
			ReconciliationHelper.replaceText(transparent ? parent : this,
					newBody);
		}
		body = newBody;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET,
					BPELPackage.EXPRESSION__BODY, oldBody, body));
	}

	/**
	 *
	 *
	 * @generated
	 */
	public String getExpressionLanguage() {
		return expressionLanguage;
	}

	/**
	 *
	 *
	 */
	public void setExpressionLanguage(String newExpressionLanguage) {
		String oldExpressionLanguage = expressionLanguage;
		if (!isReconciling) {
			ReconciliationHelper.replaceAttribute(BPELUtils.isTransparent(
					eContainer(), this) ? (WSDLElement) eContainer() : this,
					BPELConstants.AT_EXPRESSIONLANGUAGE, newExpressionLanguage);
		}
		expressionLanguage = newExpressionLanguage;
		boolean oldExpressionLanguageESet = expressionLanguageESet;
		expressionLanguageESet = true;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET,
					BPELPackage.EXPRESSION__EXPRESSION_LANGUAGE,
					oldExpressionLanguage, expressionLanguage,
					!oldExpressionLanguageESet));
	}

	/**
	 *
	 *
	 */
	public void unsetExpressionLanguage() {
		String oldExpressionLanguage = expressionLanguage;
		if (!isReconciling) {
			ReconciliationHelper.replaceAttribute(BPELUtils.isTransparent(
					eContainer(), this) ? ((WSDLElement) eContainer()) : this,
					BPELConstants.AT_EXPRESSIONLANGUAGE, (String) null);
		}
		boolean oldExpressionLanguageESet = expressionLanguageESet;
		expressionLanguage = EXPRESSION_LANGUAGE_EDEFAULT;
		expressionLanguageESet = false;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.UNSET,
					BPELPackage.EXPRESSION__EXPRESSION_LANGUAGE,
					oldExpressionLanguage, EXPRESSION_LANGUAGE_EDEFAULT,
					oldExpressionLanguageESet));
	}

	/**
	 *
	 *
	 * @generated
	 */
	public boolean isSetExpressionLanguage() {
		return expressionLanguageESet;
	}

	/**
	 *
	 *
	 * @generated
	 */
	public Boolean getOpaque() {
		return opaque;
	}

	/**
	 *
	 *
	 */
	public void setOpaque(Boolean newOpaque) {
		Boolean oldOpaque = opaque;
		if (!isReconciling && getElement() != null) {
			ReconciliationHelper.replaceAttribute(BPELUtils.isTransparent(
					eContainer(), this) ? ((WSDLElement) eContainer()) : this,
					BPELConstants.AT_OPAQUE, BPELUtils.boolean2XML(newOpaque));
		}
		opaque = newOpaque;
		boolean oldOpaqueESet = opaqueESet;
		opaqueESet = true;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET,
					BPELPackage.EXPRESSION__OPAQUE, oldOpaque, opaque,
					!oldOpaqueESet));
	}

	/**
	 *
	 *
	 */
	public void unsetOpaque() {
		Boolean oldOpaque = opaque;
		if (!isReconciling && getElement() != null) {
			ReconciliationHelper.replaceAttribute(BPELUtils.isTransparent(
					eContainer(), this) ? ((WSDLElement) eContainer()) : this,
					BPELConstants.AT_OPAQUE, (String) null);
		}
		boolean oldOpaqueESet = opaqueESet;
		opaque = OPAQUE_EDEFAULT;
		opaqueESet = false;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.UNSET,
					BPELPackage.EXPRESSION__OPAQUE, oldOpaque, OPAQUE_EDEFAULT,
					oldOpaqueESet));
	}

	/**
	 *
	 *
	 * @generated
	 */
	public boolean isSetOpaque() {
		return opaqueESet;
	}

	/**
	 *
	 *
	 * @generated
	 */

	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
		case BPELPackage.EXPRESSION__BODY:
			return getBody();
		case BPELPackage.EXPRESSION__EXPRESSION_LANGUAGE:
			return getExpressionLanguage();
		case BPELPackage.EXPRESSION__OPAQUE:
			return getOpaque();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 *
	 *
	 * @generated
	 */

	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
		case BPELPackage.EXPRESSION__BODY:
			setBody(newValue);
			return;
		case BPELPackage.EXPRESSION__EXPRESSION_LANGUAGE:
			setExpressionLanguage((String) newValue);
			return;
		case BPELPackage.EXPRESSION__OPAQUE:
			setOpaque((Boolean) newValue);
			return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 *
	 *
	 * @generated
	 */

	public void eUnset(int featureID) {
		switch (featureID) {
		case BPELPackage.EXPRESSION__BODY:
			setBody(BODY_EDEFAULT);
			return;
		case BPELPackage.EXPRESSION__EXPRESSION_LANGUAGE:
			unsetExpressionLanguage();
			return;
		case BPELPackage.EXPRESSION__OPAQUE:
			unsetOpaque();
			return;
		}
		super.eUnset(featureID);
	}

	/**
	 *
	 *
	 * @generated
	 */

	public boolean eIsSet(int featureID) {
		switch (featureID) {
		case BPELPackage.EXPRESSION__BODY:
			return BODY_EDEFAULT == null ? body != null : !BODY_EDEFAULT
					.equals(body);
		case BPELPackage.EXPRESSION__EXPRESSION_LANGUAGE:
			return isSetExpressionLanguage();
		case BPELPackage.EXPRESSION__OPAQUE:
			return isSetOpaque();
		}
		return super.eIsSet(featureID);
	}

	/**
	 *
	 *
	 * @generated
	 */

	public String toString() {
		if (eIsProxy())
			return super.toString();

		StringBuffer result = new StringBuffer(super.toString());
		result.append(" (body: "); //$NON-NLS-1$
		result.append(body);
		result.append(", expressionLanguage: "); //$NON-NLS-1$
		if (expressionLanguageESet)
			result.append(expressionLanguage);
		else
			result.append("<unset>"); //$NON-NLS-1$
		result.append(", opaque: "); //$NON-NLS-1$
		if (opaqueESet)
			result.append(opaque);
		else
			result.append("<unset>"); //$NON-NLS-1$
		result.append(')');
		return result.toString();
	}

	protected void reconcile(Element changedElement) {
		ReconciliationHelper.getInstance().reconcile(this, changedElement);
	}
} //ExpressionImpl


text:
const assert = require("assert");
const errors = require("../lib/errors");

describe("lib/errors", () => {
  describe("#notFound", () => {
    it("field unset, msg set", done => {
      const error = errors.notFound("Not found");

      assert.equal(404, error.statusCode);
      assert.deepEqual(
        {
          code: "ResourceNotFound",
          message: "Not found"
        },
        error.body
      );

      done();
    });

    it("field unset, msg unset", done => {
      const error = errors.notFound();

      assert.equal(404, error.statusCode);
      assert.deepEqual(
        {
          code: "ResourceNotFound",
          message: "Resource not found."
        },
        error.body
      );

      done();
    });

    it("field set, msg set", done => {
      const error = errors.notFound("所属 Team 不存在", "teamId");

      assert.equal(422, error.statusCode);
      assert.deepEqual(
        {
          code: "ArgumentError",
          message: [
            {
              message: "所属 Team 不存在",
              path: "teamId"
            }
          ]
        },
        error.body
      );

      done();
    });

    it("field set, msg unset", done => {
      const error = errors.notFound(null, "teamId");

      assert.equal(422, error.statusCode);
      assert.deepEqual(
        {
          code: "ArgumentError",
          message: [
            {
              message: "Resource not found.",
              path: "teamId"
            }
          ]
        },
        error.body
      );

      done();
    });
  });

  describe("#notAllowed", () => {
    it("msg unset", done => {
      const error = errors.notAllowed();
      assert.equal(403, error.statusCode);
      assert.deepEqual(
        {
          code: "ForbiddenError",
          message: "Not allowed error."
        },
        error.body
      );

      done();
    });

    it("msg set", done => {
      const error = errors.notAllowed("您没有权限执行该操作。");
      assert.equal(403, error.statusCode);
      assert.deepEqual(
        {
          code: "ForbiddenError",
          message: "您没有权限执行该操作。"
        },
        error.body
      );

      done();
    });
  });

  describe("#notAuth", () => {
    it("msg unset", done => {
      const error = errors.notAuth();
      assert.equal(403, error.statusCode);
      assert.deepEqual(
        {
          code: "NotAuthorized",
          message: "Not authorized error."
        },
        error.body
      );

      done();
    });

    it("msg set", done => {
      const error = errors.notAuth("您没有权限执行该操作。");
      assert.equal(403, error.statusCode);
      assert.deepEqual(
        {
          code: "NotAuthorized",
          message: "您没有权限执行该操作。"
        },
        error.body
      );

      done();
    });
  });

  describe("#invalidArgument", () => {
    it("msg unset, values unset", done => {
      const error = errors.invalidArgument();
      assert.equal(409, error.statusCode);
      assert.deepEqual(
        {
          code: "InvalidArgument",
          message: "Invalid argument error."
        },
        error.body
      );

      done();
    });

    it("msg unset, values set", done => {
      const error = errors.invalidArgument(null, [1, 2, 3]);
      assert.equal(409, error.statusCode);
      assert.deepEqual(
        {
          code: "InvalidArgument",
          message: "Invalid argument error.",
          value: [1, 2, 3]
        },
        error.body
      );

      done();
    });

    it("msg set, values unset", done => {
      const error = errors.invalidArgument("参数不合法");
      assert.equal(409, error.statusCode);
      assert.deepEqual(
        {
          code: "InvalidArgument",
          message: "参数不合法"
        },
        error.body
      );

      done();
    });

    it("msg set, values set", done => {
      const error = errors.invalidArgument("参数不合法", [1, 2, 3]);
      assert.equal(409, error.statusCode);
      assert.deepEqual(
        {
          code: "InvalidArgument",
          message: "参数不合法",
          value: [1, 2, 3]
        },
        error.body
      );

      done();
    });
  });

  describe("#missingParameter", () => {
    it("msg unset, missings unset", done => {
      const error = errors.missingParameter();
      assert.equal(409, error.statusCode);
      assert.deepEqual(
        {
          code: "MissingParameter",
          message: "Missing parameter error."
        },
        error.body
      );

      done();
    });

    it("msg unset, missings set", done => {
      const error = errors.missingParameter(null, ["name", "email"]);
      assert.equal(409, error.statusCode);
      assert.deepEqual(
        {
          code: "MissingParameter",
          message: "Missing parameter error.",
          value: ["name", "email"]
        },
        error.body
      );

      done();
    });

    it("msg set, missings unset", done => {
      const error = errors.missingParameter("Email 必须要提供");
      assert.equal(409, error.statusCode);
      assert.deepEqual(
        {
          code: "MissingParameter",
          message: "Email 必须要提供"
        },
        error.body
      );

      done();
    });

    it("msg set, values set", done => {
      const error = errors.missingParameter("Email 必须要提供", "email");
      assert.equal(409, error.statusCode);
      assert.deepEqual(
        {
          code: "MissingParameter",
          message: "Email 必须要提供",
          value: "email"
        },
        error.body
      );

      done();
    });
  });

  describe("#sequelizeIfError", () => {
    it("error unset, field unset", done => {
      const error = errors.sequelizeIfError();
      assert.equal(null, error);

      done();
    });

    it("error unset, field set", done => {
      const error = errors.sequelizeIfError(null, "name");
      assert.equal(null, error);

      done();
    });

    it("error set, field unset", done => {
      const error = errors.sequelizeIfError(Error("Hello world"));
      assert.equal(422, error.statusCode);
      assert.deepEqual(
        {
          code: "ArgumentError",
          message: "Hello world"
        },
        error.body
      );

      done();
    });

    it("error set, field set", done => {
      const error = errors.sequelizeIfError(Error("Email 必须要提供"), "email");
      assert.equal(422, error.statusCode);
      assert.deepEqual(
        {
          code: "ArgumentError",
          message: [
            {
              message: "Email 必须要提供",
              path: "email"
            }
          ]
        },
        error.body
      );

      done();
    });
  });

  describe("#ifError", () => {
    it("error unset, field unset", done => {
      const error = errors.ifError();
      assert.equal(null, error);

      done();
    });

    it("error unset, field set", done => {
      const error = errors.ifError(null, "name");
      assert.equal(null, error);

      done();
    });

    it("error set, field unset", done => {
      const error = errors.ifError(Error("Hello world"));
      assert.deepEqual(Error("Hello world"), error);

      done();
    });

    it("error set, field set", done => {
      const error = errors.ifError(Error("Email 必须要提供"), "email");
      assert.equal(422, error.statusCode);
      assert.deepEqual(
        {
          code: "ArgumentError",
          message: [
            {
              message: "Email 必须要提供",
              path: "email"
            }
          ]
        },
        error.body
      );

      done();
    });
  });

  describe("#normalError", () => {
    it("msg unset, value... unset", done => {
      const error = errors.normalError();
      assert.equal(500, error.statusCode);
      assert.deepEqual(
        {
          code: "NormalError",
          message: [
            {
              message: "Normal error.",
              values: []
            }
          ]
        },
        error.body
      );

      done();
    });

    it("msg unset, value... set", done => {
      const error = errors.normalError(null, "name");
      assert.equal(500, error.statusCode);
      assert.deepEqual(
        {
          code: "NormalError",
          message: [
            {
              message: "Normal error.",
              values: ["name"]
            }
          ]
        },
        error.body
      );

      done();
    });

    it("msg set, value... unset", done => {
      const error = errors.normalError("出了点问题");
      assert.equal(500, error.statusCode);
      assert.deepEqual(
        {
          code: "NormalError",
          message: [
            {
              message: "出了点问题",
              values: []
            }
          ]
        },
        error.body
      );

      done();
    });

    it("msg set, value... set", done => {
      const error = errors.normalError("出了点问题", "name", "age");
      assert.equal(500, error.statusCode);
      assert.deepEqual(
        {
          code: "NormalError",
          message: [
            {
              message: "出了点问题",
              values: ["name", "age"]
            }
          ]
        },
        error.body
      );

      done();
    });
  });

  describe("#error", () => {
    it("msg unset, value... unset", done => {
      const error = errors.error();
      const err = Error("Unknown error.");
      err.value = [];
      assert.deepEqual(err, error);

      done();
    });

    it("msg unset, value... set", done => {
      const error = errors.error(null, "name");
      const err = Error("Unknown error.");
      err.value = ["name"];
      assert.deepEqual(err, error);

      done();
    });

    it("msg set, value... unset", done => {
      const error = errors.error("出了点问题");
      const err = Error("出了点问题");
      err.value = [];
      assert.deepEqual(err, error);

      done();
    });

    it("msg set, value... set", done => {
      const error = errors.error("出了点问题", "name", "age");
      const err = Error("出了点问题");
      err.value = ["name", "age"];
      assert.deepEqual(err, error);

      done();
    });
  });
});


text:
using ExtendedXmlSerializer.Core;
using ExtendedXmlSerializer.ExtensionModel;
using System.Collections;
using System.Collections.Generic;

namespace ExtendedXmlSerializer.Configuration
{
	sealed class RootContext : IRootContext
	{
		readonly IExtensionCollection _extensions;
		readonly IServicesFactory     _factory;

		public RootContext(IExtensionCollection extensions) : this(new TypeConfigurations(extensions), extensions) {}

		public RootContext(ITypeConfigurations types, IExtensionCollection extensions) : this(types, extensions,
		                                                                              ServicesFactory
			                                                                             .Default) {}

		public RootContext(ITypeConfigurations types, IExtensionCollection extensions, IServicesFactory factory)
		{
			Types       = types;
			_extensions = extensions;
			_factory    = factory;

			_extensions.Add(new RootContextExtension(this));
		}

		public IRootContext Root => this;
		public IContext Parent => null;

		public ITypeConfigurations Types { get; }

		public IExtendedXmlSerializer Create()
		{
			using (var services = _factory.Get(_extensions))
			{
				var result = services.Get<IExtendedXmlSerializer>();
				return result;
			}
		}

		IEnumerator<ISerializerExtension> IEnumerable<ISerializerExtension>.GetEnumerator()
			=> _extensions.GetEnumerator();

		IEnumerator IEnumerable.GetEnumerator() => _extensions.GetEnumerator();

		void ICollection<ISerializerExtension>.Add(ISerializerExtension item) => _extensions.Add(item);

		void ICollection<ISerializerExtension>.Clear() => _extensions.Clear();

		bool ICollection<ISerializerExtension>.Contains(ISerializerExtension item) => _extensions.Contains(item);

		void ICollection<ISerializerExtension>.CopyTo(ISerializerExtension[] array, int arrayIndex) =>
			_extensions.CopyTo(array, arrayIndex);

		bool ICollection<ISerializerExtension>.Remove(ISerializerExtension item) => _extensions.Remove(item);

		int ICollection<ISerializerExtension>.Count => _extensions.Count;
		bool ICollection<ISerializerExtension>.IsReadOnly => _extensions.IsReadOnly;

		bool IExtensionCollection.Contains<T>() => _extensions.Contains<T>();

		T IExtensionCollection.Find<T>() => _extensions.Find<T>();
	}
}


text:
from sparcssso.version import get_version_info

from .common import *  # noqa: F401, F403

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = False

ALLOWED_HOSTS = [
    'sparcssso.kaist.ac.kr',
    'sso.sparcs.org',
]

VERSION = get_version_info(DEBUG, ALLOWED_HOSTS)

DOMAIN = 'https://sparcssso.kaist.ac.kr'

LOGGING['loggers']['django.request'] = {  # noqa: F405
    'handlers': ['mail'],
    'level': 'ERROR',
}

LOG_DIR = '/data/archive/logs/'

LOG_BUFFER_DIR = '/data/archive/buffer/'

STAT_FILE = '/data/archive/stats.txt'


text:
/*********************************************************************\
	File name        : TreeView.cpp
	Description      : Implementation of the TreeView classes
	Created at       : 14.08.01, @ 19:13:56
	Created by       : Thomas Kunert
	Modified by      :
\*********************************************************************/

#if (defined _DEBUG) && (defined USE_CPP_NEW_DELETE)
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

#include "stdafx.h"
#include "globals.h"
#include "TreeView.h"
#include "TreeDialog.h"

#include "shellsort.h"
#include "DialogDoc.h"
#include "DialogItem.h"

#include "TreeDialog.h"

//////////////////////////////////////////////////////////////////////
// Konstruktion/Destruktion
//////////////////////////////////////////////////////////////////////

#define DEPTH_MULTIPLY        10
#define LINE_LENGTH           9

TreeViewItem::TreeViewItem()
{
	m_ppChildren = nullptr;
	m_lChildren = 0;
	m_bIsExpanded = false;
	m_pParent = nullptr;
}

TreeViewItem::~TreeViewItem()
{
	DestroyAllChildren(nullptr);
}

/*********************************************************************\
	Function name    : TreeViewItem::AddItem
	Description      :
	Created at       : 14.08.01, @ 19:05:03
	Created by       : Thomas Kunert
	Modified by      :
\*********************************************************************/
TreeViewItem* TreeViewItem::AddItem(const BaseContainer &data, TreeViewItem* pInsertAfter)
{
	TreeViewItem* pNewItem = NewObjClear(TreeViewItem);
	pNewItem->m_Data = data;

	TreeViewItem** pNewChildren = bNewDeprecatedUseArraysInstead<TreeViewItem*>(m_lChildren + 1);
	Int32 a, b;
	for (a = 0, b = 0; a < m_lChildren; a++, b++)
	{
		pNewChildren[b] = m_ppChildren[a];
		if ((m_ppChildren[a] == pInsertAfter) && b == a)
			pNewChildren[++b] = pNewItem;
	}

	//CopyMem(m_ppChildren, pNewChildren, sizeof(TreeViewItem*) * m_lChildren);

	bDelete(m_ppChildren);
	m_ppChildren = pNewChildren;
	if (b <= m_lChildren)
		m_ppChildren[m_lChildren] = pNewItem;
	m_lChildren++;

	return pNewItem;
}

/*********************************************************************\
	Function name    : TreeViewItem::DestroyAllChildren
	Description      :
	Created at       : 14.08.01, @ 19:11:49
	Created by       : Thomas Kunert
	Modified by      :
\*********************************************************************/
void TreeViewItem::DestroyAllChildren(DeleteTreeViewItemCallback func)
{
	for (Int32 a = 0; a < m_lChildren; a++) {
		m_ppChildren[a]->DestroyAllChildren(func);
		if (func)
			func(m_ppChildren[a]->GetData());

		DeleteObj(m_ppChildren[a]);
	}
	bDelete(m_ppChildren);
	m_lChildren = 0;
}

/*********************************************************************\
	Function name    : TreeViewItem::ChangeParent
	Description      :
	Created at       : 15.08.01, @ 11:23:57
	Created by       : Thomas Kunert
	Modified by      :
\*********************************************************************/
void TreeViewItem::ChangeParent(TreeViewItem* pNewParent, TreeViewItem* pInsertBefore, TreeViewItem* pInsertAfter)
{
	if (pNewParent->IsChildOf(this)) return;

	if (m_pParent->m_lChildren > 1)
	{
		TreeViewItem** ppNewChildren = bNewDeprecatedUseArraysInstead<TreeViewItem*>(m_pParent->m_lChildren - 1);
		for (Int32 s = 0, d = 0; s < m_pParent->m_lChildren; s++)
		{
			if (m_pParent->m_ppChildren[s] != this)
				ppNewChildren[d++] = m_pParent->m_ppChildren[s];
		}
		bDelete(m_pParent->m_ppChildren);
		m_pParent->m_ppChildren = ppNewChildren;
	}
	else
		bDelete(m_pParent->m_ppChildren);

	m_pParent->m_lChildren--;

	TreeViewItem** ppNewChildren = bNewDeprecatedUseArraysInstead<TreeViewItem*>(pNewParent->m_lChildren + 1);

	Bool bInserted = false;
	for (Int32 s = 0, d = 0; s < pNewParent->m_lChildren; s++, d++)
	{
		if (pNewParent->m_ppChildren[s] == pInsertBefore)
		{
			ppNewChildren[d++] = this;
			bInserted = true;
		}
		ppNewChildren[d] = pNewParent->m_ppChildren[s];
		if (pNewParent->m_ppChildren[s] == pInsertAfter)
		{
			ppNewChildren[++d] = this;
			bInserted = true;
		}
	}
	if (!bInserted)
	{
		for (Int32 a = pNewParent->m_lChildren; a >= 1; a--)
			ppNewChildren[a] = ppNewChildren[a - 1];
		ppNewChildren[0] = this;
	}

	bDelete(pNewParent->m_ppChildren);
	pNewParent->m_ppChildren = ppNewChildren;

	pNewParent->m_lChildren++;
	m_pParent = pNewParent;
}

/*********************************************************************\
	Function name    : TreeViewItem::IsChildOf
	Description      : checks, if pItem is a child of this
	Created at       : 15.08.01, @ 11:37:53
	Created by       : Thomas Kunert
	Modified by      :
\*********************************************************************/
Bool TreeViewItem::IsChildOf(TreeViewItem* pItem)
{
	TreeViewItem* pParent = this;
	while (pParent)
	{
		if (pParent == pItem) return true;
		pParent = pParent->GetParent();
	}
	return false;
}

/*********************************************************************\
	Function name    : TreeViewItem::GetIcon
	Description      :
	Created at       : 15.08.01, @ 09:44:05
	Created by       : Thomas Kunert
	Modified by      :
\*********************************************************************/
Int32 TreeViewItem::GetIcon()
{
	return m_Data.GetInt32(TREEVIEW_ICON);
}

/*********************************************************************\
	Function name    : TreeViewItem::RemoveChild
	Description      :
	Created at       : 23.08.01, @ 21:37:28
	Created by       : Thomas Kunert
	Modified by      :
\*********************************************************************/
void TreeViewItem::RemoveChild(TreeViewItem* pItem, DeleteTreeViewItemCallback cb)
{
	Int32 lItem = -1;
	for (Int32 a = 0; a < m_lChildren; a++)
	{
		if (m_ppChildren[a] == pItem)
			lItem = a;
	}
	RemoveChild(lItem, cb);
}

/*********************************************************************\
	Function name    : TreeViewItem::RemoveChild
	Description      :
	Created at       : 23.08.01, @ 21:37:30
	Created by       : Thomas Kunert
	Modified by      :
\*********************************************************************/
void TreeViewItem::RemoveChild(Int32 lChildIndex, DeleteTreeViewItemCallback cb)
{
	if (lChildIndex < 0 || lChildIndex >= m_lChildren) return;

	if (cb)
		cb(m_ppChildren[lChildIndex]->GetData());

	DeleteObj(m_ppChildren[lChildIndex]);

	if (m_lChildren == 1)
	{
		m_lChildren = 0;
		bDelete(m_ppChildren);
		return;
	}

	TreeViewItem** ppNewChild = bNewDeprecatedUseArraysInstead<TreeViewItem*>(m_lChildren - 1);
	for (Int32 d = 0, s = 0; s < m_lChildren; s++)
	{
		if (s != lChildIndex)
			ppNewChild[d++] = m_ppChildren[s];
	}
	bDelete(m_ppChildren);
	m_ppChildren = ppNewChild;
	m_lChildren--;
}

/*********************************************************************\
	Function name    : CompareTreeViewItemSort
	Description      :
	Created at       : 06.10.01, @ 12:37:32
	Created by       : Thomas Kunert
	Modified by      :
\*********************************************************************/
Int32 CompareTreeViewItemSort(TreeViewItem* const* pItem1, TreeViewItem* const* pItem2)
{
	String str1 = (*pItem1)->GetDataC()->GetString(TREEVIEW_TEXT);
	String str2 = (*pItem2)->GetDataC()->GetString(TREEVIEW_TEXT);

	return (str1.LexCompare(str2));
}

/*********************************************************************\
	Function name    : TreeViewItem::SortChildren
	Description      :
	Created at       : 26.09.01, @ 11:55:36
	Created by       : Thomas Kunert
	Modified by      :
\*********************************************************************/
void TreeViewItem::SortChildren()
{
	CShellSort <TreeViewItem*> sort;
	sort.Sort(m_ppChildren, CompareTreeViewItemSort, m_lChildren);

	/*Bool bAgain;
	do
	{
		bAgain = false;
		for (Int32 a = 0; a < m_lChildren - 1; a++)
		{
			for (Int32 b = a + 1; b < m_lChildren; b++)
			{
				TreeViewItem *pItem1 = m_ppChildren[a], *pItem2 = m_ppChildren[b];
				if (pItem1->m_Data.GetString(TREEVIEW_TEXT) > pItem2->m_Data.GetString(TREEVIEW_TEXT))
				{
					m_ppChildren[b] = pItem1;
					m_ppChildren[a] = pItem2;
					bAgain = true;
				}
			}
		}
	} while (bAgain);*/
}

/*********************************************************************\
	Function name    : TreeViewItem::GetNext
	Description      :
	Created at       : 26.03.02, @ 16:52:51
	Created by       : Thomas Kunert
	Modified by      :
\*********************************************************************/
TreeViewItem* TreeViewItem::GetNext()
{
	if (!m_pParent) return nullptr;
	if (!m_pParent->m_ppChildren || m_pParent->m_lChildren <= 1) return nullptr;

	for (Int32 a = 0; a < m_pParent->m_lChildren - 1; a++)
	{
		if (m_pParent->m_ppChildren[a] == this) return m_pParent->m_ppChildren[a + 1];
	}

	return nullptr;
}

/*********************************************************************\
	Function name    : TreeViewItem::GetPred
	Description      :
	Created at       : 26.03.02, @ 16:52:52
	Created by       : Thomas Kunert
	Modified by      :
\*********************************************************************/
TreeViewItem* TreeViewItem::GetPred()
{
	if (!m_pParent) return nullptr;
	if (!m_pParent->m_ppChildren || m_pParent->m_lChildren <= 1) return nullptr;

	for (Int32 a = 1; a < m_pParent->m_lChildren; a++)
	{
		if (m_pParent->m_ppChildren[a] == this) return m_pParent->m_ppChildren[a - 1];
	}
	return nullptr;
}

/*********************************************************************\
\*********************************************************************/
static class TreeViewModel : public TreeViewFunctions
{
	public:

		virtual void*	GetFirst(void *pRoot, void *userdata)
		{
			TreeViewItem *p = (TreeViewItem*)pRoot;
			return p->GetChild(0);
		}

		virtual void*	GetNext(void *root,void *userdata,void *obj)
		{
			TreeViewItem *p = (TreeViewItem*)obj;
			return p->GetNext();
		}

		virtual void* GetPred(void *root,void *userdata,void *obj)
		{
			TreeViewItem *p = (TreeViewItem*)obj;
			return p->GetPred();
		}

		virtual void*	GetDown(void *root,void *userdata,void *obj)
		{
			TreeViewItem *p = (TreeViewItem*)obj;
			return p->GetDown();
		}

		virtual void* GetUp(void *root,void *userdata,void *obj)
		{
			TreeViewItem *p = (TreeViewItem*)obj;
			void* pUp = p->GetUp();
			if (pUp == root) return nullptr;
			return pUp;
		}

		virtual Bool IsSelected(void *root,void *userdata,void *obj)
		{
			TreeView* pTree = (TreeView*)userdata;
			return obj == (void*)pTree->m_pCurrentItem;
		}

		virtual String GetName(void *root,void *userdata,void *obj)
		{
			TreeViewItem *p = (TreeViewItem*)obj;
			return p->m_Data.GetString(TREEVIEW_TEXT);
		}

		virtual Int GetId(void *root,void *userdata,void *obj)
		{
			return (Int)obj;
		}

		virtual Bool IsOpened(void *root,void *userdata,void *obj)
		{
			TreeViewItem *p = (TreeViewItem*)obj;
			return p->m_bIsExpanded;
		}

		virtual void Open(void *root,void *userdata,void *obj,Bool onoff)
		{
			TreeViewItem *p = (TreeViewItem*)obj;
			p->m_bIsExpanded = onoff;
			//GeEventAdd(MSG_REDRAWALL);
		}

		virtual void Select(void *root,void *userdata,void *obj,Int32 mode)
		{
			TreeView* pTree = (TreeView*)userdata;
			pTree->m_pCurrentItem = (TreeViewItem*)obj;

			BaseContainer bc;
			bc.SetInt32(TREEVIEW_MESSAGE_TYPE, TREEVIEW_SELCHANGE);
			if (mode == SELECTION_SUB) return;
				//bc.SetInt32(TREEVIEW_MESSAGE_ITEM, nullptr);
			//else
			bc.SetVoid(TREEVIEW_MESSAGE_ITEM, obj);

			pTree->m_pParent->Command(pTree->m_lTreeID, bc);
		}

		virtual Int32 AcceptDragObject(void *root,void *userdata,void *obj,Int32 dragtype,void *dragobject, Bool &bAllowCopy)
		{
			TreeView* pTree = (TreeView*)userdata;
			if (dragtype == DRAGTYPE_FILES)
			{
				return INSERT_BEFORE | INSERT_AFTER | INSERT_UNDER;
			}
			if (pTree->m_lFlags & TREE_VIEW_HAS_DRAG_DROP)
			{
				if (dragtype == pTree->m_lElementType)
				{
					Int32 lRet = INSERT_BEFORE | INSERT_AFTER;

					TreeViewItem* pDragDest = (TreeViewItem*)obj;
					CDialogItem* pDlgItem = (CDialogItem*)pDragDest->GetData()->GetVoid(TREEVIEW_DATA);
					if (pDlgItem->GetType() == Group || pDlgItem->GetType() == Dialog)
						lRet |= INSERT_UNDER;

					if (pDlgItem->GetType() == Dialog) bAllowCopy = false;
					else bAllowCopy = true;

					return lRet;
				}
			}
			return false;
		}

		virtual void InsertObject(void *root,void *userdata,void *obj,Int32 dragtype,void *dragobject,Int32 insertmode, Bool bCopy)
		{
			TreeView* pTree = (TreeView*)userdata;

			if (dragtype == DRAGTYPE_FILES)
			{
				Filename* fn = (Filename*)dragobject;
				if (!fn) return;
				((CTreeDialog*)pTree->m_pParent)->OpenDialog(*fn);
			}

			if (dragtype == pTree->m_lElementType)
			{
				TreeViewItem* pDragItem = (TreeViewItem*)dragobject;
				TreeViewItem* pDestItem = (TreeViewItem*)obj;

				if (bCopy)
				{
					if (!pDragItem || !pDestItem) return;

					CTreeDialog* pDlg = (CTreeDialog*)pTree->m_pParent;
					if (!pDlg) return;
					CDialogDoc* pDoc = pDlg->GetDocument();
					if (!pDoc) return;

					CDialogItem* pDlgItemDrag = (CDialogItem*)pDragItem->GetData()->GetVoid(TREEVIEW_DATA);
					CDialogItem* pDlgItemDrop = (CDialogItem*)pDestItem->GetData()->GetVoid(TREEVIEW_DATA);
					if (!pDlgItemDrag || !pDlgItemDrop) return;

					pDoc->ExportMacro(GeGetPluginPath() + String("DragDrop.dmf"), pDlgItemDrag);
					CDialogItem* pNewItem = pDoc->ImportMacro(GeGetPluginPath() + String("DragDrop.dmf"), pDlgItemDrop);
					GeFKill(GeGetPluginPath() + String("DragDrop.dmf"));

					if (pNewItem)
					{
						TreeViewItem* pNewTreeItem = pNewItem->m_pTreeViewItem;
						switch (insertmode)
						{
							case INSERT_BEFORE: pNewTreeItem->ChangeParent(pDestItem->GetParent(), pDestItem, nullptr); break;
							case INSERT_UNDER:  pNewTreeItem->ChangeParent(pDestItem, nullptr, nullptr); Open(root, userdata, obj, true); break;
							default:            pNewTreeItem->ChangeParent(pDestItem->GetParent(), nullptr, pDestItem); break;
						}
						Select(root, userdata, pNewTreeItem, SELECTION_NEW);
					}
				}
				else
				{
					switch (insertmode)
					{
						case INSERT_BEFORE: pDragItem->ChangeParent(pDestItem->GetParent(), pDestItem, nullptr); break;
						case INSERT_UNDER:  pDragItem->ChangeParent(pDestItem, nullptr, nullptr); Open(root, userdata, obj, true); break;
						default:            pDragItem->ChangeParent(pDestItem->GetParent(), nullptr, pDestItem); break;
					}
				}
				BaseContainer bc;
				bc.SetInt32(TREEVIEW_MESSAGE_TYPE, TREEVIEW_STRUCTURE_CHANGE);
				pTree->m_pParent->Command(pTree->m_lTreeID, bc);
				pTree->m_pTree->Refresh();
			}
		}

		virtual Int32 GetDragType(void *root,void *userdata,void *obj)
		{
			TreeView* pTree = (TreeView*)userdata;
			return pTree->m_lElementType;
		}

		virtual Bool DoubleClick(void *root,void *userdata,void *obj,Int32 col,MouseInfo *mouseinfo)
		{
			TreeView* pTree = (TreeView*)userdata;

			BaseContainer bc;
			bc.SetInt32(TREEVIEW_MESSAGE_TYPE, TREEVIEW_DOUBLECLICK);
			bc.SetVoid(TREEVIEW_MESSAGE_ITEM, obj);
			return pTree->m_pParent->Command(pTree->m_lTreeID, bc);
			//return false;
		}

		virtual Bool MouseDown(void *root,void *userdata,void *obj,Int32 col,MouseInfo *mouseinfo, Bool rightButton)
		{
			return false;
		}

		virtual Int32 GetColumnWidth(void *root,void *userdata,void *obj,Int32 col, GeUserArea* area)
		{
			if (col=='icon')
			{
				//BaseBitmap *pBmp = p->GetIcon();
				//if (pBmp) return pBmp->GetBw();
				//else return 0;
				return 20;
			}
			return 0;
		}

		virtual Int32 GetLineHeight(void *root,void *userdata,void *obj,Int32 col, GeUserArea* area)
		{
			if (col=='icon')
			{
				//BaseBitmap *pBmp = p->GetIcon();
				//if (pBmp) return pBmp->GetBh();
				//else return 0;
				return 20;
			}
			return 0;
		}

		virtual void DrawCell(void *root,void *userdata,void *obj,Int32 col,DrawInfo *drawinfo, const GeData& bgColor)
		{
			TreeViewItem* p = (TreeViewItem*)obj;
			if (col=='icon')
			{
				Int32 wx,wy,wh,ww;
				/*BaseBitmap *pBmp = p->GetIcon();
				if (pBmp)
				{
					wx = drawinfo->xpos;
					wy = drawinfo->ypos;
					ww = drawinfo->width;
					wh = drawinfo->height;

					if (ww > pBmp->GetBw()) { wx += (ww - pBmp->GetBw()) / 2; ww = pBmp->GetBw(); }
					if (wh > pBmp->GetBh()) { wy += (wh - pBmp->GetBh()) / 2; wh = pBmp->GetBh(); }

					drawinfo->frame->DrawSetPen(COLOR_BG);
					drawinfo->frame->DrawBitmap(pBmp, wx, wy, ww, wh, 0, 0, pBmp->GetBw(), pBmp->GetBh(), BMP_NORMALSCALED);
				}*/
				Int32 lWidth = CONTROLIMAGE_SIZE, lHeight = CONTROLIMAGE_SIZE;
				Int32 i = p->GetIcon();
				Int32 x = (i % 9) * CONTROLIMAGE_SIZE;
				Int32 y = (i / 9) * CONTROLIMAGE_SIZE;

				wx = drawinfo->xpos;
				wy = drawinfo->ypos;
				ww = drawinfo->width;
				wh = drawinfo->height;

				if (ww > lWidth) { wx += (ww - lWidth) / 2; ww = lWidth; }
				if (wh > lHeight) { wy += (wh - lHeight) / 2; wh = lHeight; }

				drawinfo->frame->DrawSetPen(COLOR_BG);
				drawinfo->frame->DrawBitmap(g_pControlImages, wx, wy, ww, wh, x, y, lWidth, lHeight, BMP_NORMALSCALED | BMP_ALLOWALPHA);
			}
		}
		virtual void DeletePressed(void *root, void *userdata)
		{
			TreeView* pTree = (TreeView*)userdata;
			if (!pTree) return;

			((CTreeDialog*)(pTree->m_pParent))->GetDocument()->OnEditDelete();
		}
		virtual Bool ContextMenuCall(void *root,void *userdata,void *obj, Int32 lColumn, Int32 lCommand)
		{
			if (lCommand == ID_TREEVIEW_CONTEXT_REMOVE)
				DeletePressed(root, userdata);
			if (lCommand == ID_TREEVIEW_CONTEXT_RESET)
			{
				TreeView* pTree = (TreeView*)userdata;
				if (!pTree) return false;

				((CTreeDialog*)(pTree->m_pParent))->GetDocument()->OnFileNew();
			}
			return true;
		}
} g_treeModel;

TreeView::TreeView(Bool showIcons)
{
	m_lCursor = MOUSE_SHOW;
	m_lVisibleHeight = m_lVisibleWidth = 0;
	m_RootItem.m_bIsExpanded = true;
	m_pCurrentItem = 0;
	m_lFlags = 0;
	m_pParent = 0;
	m_pDragDestination = nullptr;
	m_DeleteCallback = nullptr;
	m_bMayUpdate = true;
	m_bShowIcons = showIcons;
}

TreeView::~TreeView()
{
	m_RootItem.DestroyAllChildren(m_DeleteCallback);
}

/*********************************************************************\
	Function name    : TreeView::AddItem
	Description      :
	Created at       : 14.08.01, @ 18:33:46
	Created by       : Thomas Kunert
	Modified by      :
\*********************************************************************/
TreeViewItem* TreeView::AddItem(String strName, TreeViewItem* pParent)
{
	BaseContainer bc;
	bc.SetString(TREEVIEW_TEXT, strName);
	return AddItem(bc, pParent);
}

/*********************************************************************\
	Function name    : TreeView::AddItem
	Description      :
	Created at       : 15.08.01, @ 09:39:49
	Created by       : Thomas Kunert
	Modified by      :
\*********************************************************************/
TreeViewItem* TreeView::AddItem(String strName, Int32 lType, TreeViewItem* pParent)
{
	BaseContainer bc;
	bc.SetString(TREEVIEW_TEXT, strName);
	bc.SetInt32(TREEVIEW_ICON, lType);
	return AddItem(bc, pParent);
}

/*********************************************************************\
	Function name    : TreeView::AddItem
	Description      :
	Created at       : 14.08.01, @ 18:51:26
	Created by       : Thomas Kunert
	Modified by      :
\*********************************************************************/
TreeViewItem* TreeView::AddItem(const BaseContainer &data, TreeViewItem* pParent, TreeViewItem* pInsertAfter)
{
	if (!pParent) pParent = &m_RootItem;
	TreeViewItem* pNewItem = pParent->AddItem(data, pInsertAfter);
	pNewItem->m_pParent = pParent;

	if (m_bMayUpdate)
	{
		//CreateVisibleItemList();
		Redraw();
		//UpdateParentLayout();
	}

	return pNewItem;
}

/*********************************************************************\
	Function name    : TreeView::ExpandItem
	Description      :
	Created at       : 14.08.01, @ 19:28:34
	Created by       : Thomas Kunert
	Modified by      :
\*********************************************************************/
void TreeView::ExpandItem(TreeViewItem* pItem, Bool bExpand)
{
	pItem->m_bIsExpanded = bExpand;

	if (!bExpand && m_pCurrentItem->IsChildOf(pItem))
	{
		m_pCurrentItem = pItem;
		if (m_pParent)
		{
			BaseContainer bc;
			bc.SetInt32(TREEVIEW_MESSAGE_TYPE, TREEVIEW_SELCHANGE);
			bc.SetVoid(TREEVIEW_MESSAGE_ITEM, m_pCurrentItem);
			m_pParent->Command(m_lTreeID, bc);
		}
	}

	Redraw();
}

/*********************************************************************\
	Function name    : TreeView::Reset
	Description      :
	Created at       : 14.08.01, @ 22:28:01
	Created by       : Thomas Kunert
	Modified by      :
\*********************************************************************/
void TreeView::Reset()
{
	m_RootItem.DestroyAllChildren(m_DeleteCallback);
	Redraw();
	m_pCurrentItem = &m_RootItem;
}

/*********************************************************************\
	Function name    : TreeView::SelectItem
	Description      :
	Created at       : 14.08.01, @ 23:17:56
	Created by       : Thomas Kunert
	Modified by      :
\*********************************************************************/
void TreeView::SelectItem(TreeViewItem* pTreeItem)
{
	m_pCurrentItem = pTreeItem;

	TreeViewItem* pParent = pTreeItem->GetParent();
	while (pParent)
	{
		pParent->m_bIsExpanded = true;
		pParent = pParent->GetParent();
	};
	//m_VisibleItems.FreeList();
	if (m_bMayUpdate)
	{
		//CreateVisibleItemList();
		Redraw();
		//UpdateParentLayout();
	}
}

/*********************************************************************\
	Function name    : TreeView::ExpandAllItems
	Description      : expands all items that are children of pFirstItem
	Created at       : 18.08.01, @ 16:11:25
	Created by       : Thomas Kunert
	Modified by      :
\*********************************************************************/
void TreeView::ExpandAllItems(Bool bExpand, TreeViewItem* pFirstItem)
{
	_ExpandAllItems_(bExpand, pFirstItem);
	//CreateVisibleItemList();
	Redraw();
	//UpdateParentLayout();
}

/*********************************************************************\
	Function name    : TreeView::_ExpandAllItems_
	Description      :
	Created at       : 18.08.01, @ 16:19:50
	Created by       : Thomas Kunert
	Modified by      :
\*********************************************************************/
void TreeView::_ExpandAllItems_(Bool bExpand, TreeViewItem* pFirstItem)
{
	if (!pFirstItem) pFirstItem = &m_RootItem;

	if (pFirstItem == &m_RootItem) pFirstItem->m_bIsExpanded = true;  // the root item is always expanded
	else pFirstItem->m_bIsExpanded = bExpand;
	Int32 lChildren = pFirstItem->GetChildCount();
	for (Int32 a = 0; a < lChildren; a++)
	{
		TreeViewItem* pChild = pFirstItem->GetChild(a);
		pChild->m_bIsExpanded = bExpand;
		_ExpandAllItems_(bExpand, pChild);
	}
}

/*********************************************************************\
	Function name    : TreeView::VisitChildren
	Description      :
	Created at       : 22.08.01, @ 09:41:46
	Created by       : Thomas Kunert
	Modified by      :
\*********************************************************************/
void TreeView::VisitChildren(VisitChildrenCallbackA cb, TreeViewItem* pStartItem, void* pData)
{
	if (!pStartItem) pStartItem = &m_RootItem;
	Int32 lChildren = pStartItem->GetChildCount();
	cb(pStartItem, pData);
	for (Int32 a = 0; a < lChildren; a++)
	{
		TreeViewItem* pChild = pStartItem->GetChild(a);
		VisitChildren(cb, pChild, pData);
	}
}

/*********************************************************************\
	Function name    : TreeView::DeleteItem
	Description      :
	Created at       : 23.08.01, @ 21:33:07
	Created by       : Thomas Kunert
	Modified by      :
\*********************************************************************/
void TreeView::DeleteItem(TreeViewItem* pItem)
{
	if (!pItem || pItem == &m_RootItem) return;
	pItem->DestroyAllChildren(m_DeleteCallback);

	TreeViewItem* pNext = pItem->GetNext();
	if (!pNext)
		pNext = pItem->GetParent();
	pItem->GetParent()->RemoveChild(pItem, m_DeleteCallback);
	m_pCurrentItem = pNext;

	if (m_bMayUpdate)
	{
		//CreateVisibleItemList();
		Redraw();
		//UpdateParentLayout();
	}
}

/*********************************************************************\
	Function name    : TreeView::CreateTreeView
	Description      : Creates a tree view window and attaches it to the parent window
	Created at       : 26.09.01, @ 11:02:27
	Created by       : Thomas Kunert
	Modified by      :
\*********************************************************************/
Bool TreeView::CreateTreeView(Int32 lTreeID, GeDialog* pParent, Int32 lElementType,
		DeleteTreeViewItemCallback pDeleteCallbackFunc, Int32 lTreeViewFlags,
		Int32 lFlags)
{
	m_pParent = pParent;

	SetDeleteCallback(pDeleteCallbackFunc);

	BaseContainer treedata;
	treedata.SetBool(TREEVIEW_CTRL_DRAG, true);
	treedata.SetBool(TREEVIEW_NO_MULTISELECT, true);
	treedata.SetBool(TREEVIEW_CURSORKEYS, true);
	treedata.SetBool(TREEVIEW_ALTERNATE_BG, true);
	treedata.SetBool(TREEVIEW_FIXED_LAYOUT, true);
	//treedata.SetBool(TREEVIEW_HAS_HEADER, true);
	//treedata.SetBool(TREEVIEW_BORDER, true);
	pParent->AddCustomGui(lTreeID, CUSTOMGUI_TREEVIEW, String(), BFH_SCALEFIT | BFV_SCALEFIT, 0, 0, treedata);

	m_pTree = (TreeViewCustomGui*)pParent->FindCustomGui(lTreeID, CUSTOMGUI_TREEVIEW);
	if (!m_pTree) return false;

	Int32 count = 1;
	BaseContainer layout;
	if (m_bShowIcons) {
		layout.SetInt32('icon', LV_USER);
		count++;
	}
	layout.SetInt32('tree', LV_TREE);
	m_pTree->SetLayout(count, layout);

	m_pTree->SetRoot(&m_RootItem, &g_treeModel, this);

	m_lTreeID = lTreeID;
	m_lElementType = lElementType;
	m_lFlags = lTreeViewFlags;

	return true;
}

/*********************************************************************\
	Function name    : TreeView::SortChildren
	Description      :
	Created at       : 26.09.01, @ 11:52:55
	Created by       : Thomas Kunert
	Modified by      :
\*********************************************************************/
void TreeView::SortChildren(TreeViewItem* pStartItem)
{
	pStartItem->SortChildren();
	Redraw();
}

/*********************************************************************\
	Function name    : TreeView::MakeVisible
	Description      : makes pItem visible. It does not select the item
										 returns true if the item was visible
	Created at       : 21.10.01, @ 17:58:35
	Created by       : Thomas Kunert
	Modified by      :
\*********************************************************************/
Bool TreeView::MakeVisible(TreeViewItem* pItem)
{
	m_pTree->MakeVisible(pItem);
	return true;
}


text:
package io.github.mthli.Bitocle.About;

import android.app.Activity;

public class AboutActivity extends Activity {
    /* Do something */
}


text:
from flask import Blueprint

blueprint = Blueprint(
    'pdfhook', __name__,
)

from . import views