text:
package com.commonsware.android.advservice.callbackbinding.svc;

import android.app.Service;
import android.content.Intent;
import android.net.Uri;
import android.os.Environment;
import android.os.IBinder;
import android.os.RemoteException;
import android.util.Log;
import com.commonsware.android.advservice.callbackbinding.IDownload;
import com.commonsware.android.advservice.callbackbinding.IDownloadCallback;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;

public class DownloadService extends Service {
  @Override
  public IBinder onBind(Intent intent) {
    return(new DownloadBinder());
  }

  private static class DownloadBinder extends IDownload.Stub {
    @Override
    public void download(String url, IDownloadCallback cb) {
      new DownloadThread(url, cb).start();
    }
  }

  private static class DownloadThread extends Thread {
    String url=null;
    IDownloadCallback cb=null;

    DownloadThread(String url, IDownloadCallback cb) {
      this.url=url;
      this.cb=cb;
    }

    @Override
    public void run() {
      try {
        File root=
            Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);

        root.mkdirs();

        File output=new File(root, Uri.parse(url).getLastPathSegment());

        if (output.exists()) {
          output.delete();
        }

        HttpURLConnection c=(HttpURLConnection)new URL(url).openConnection();

        FileOutputStream fos=new FileOutputStream(output.getPath());
        BufferedOutputStream out=new BufferedOutputStream(fos);

        try {
          InputStream in=c.getInputStream();
          byte[] buffer=new byte[8192];
          int len=0;

          while ((len=in.read(buffer)) >= 0) {
            out.write(buffer, 0, len);
          }

          out.flush();

          try {
            cb.onSuccess();
          }
          catch (RemoteException e) {
            Log.e("DownloadJob", "Exception when calling onSuccess()", e);
          }
        }
        finally {
          fos.getFD().sync();
          out.close();
          c.disconnect();
        }
      }
      catch (IOException e2) {
        Log.e("DownloadJob", "Exception in download", e2);

        try {
          cb.onFailure(e2.getMessage());
        }
        catch (RemoteException e) {
          Log.e("DownloadJob", "Exception when calling onFailure()", e2);
        }
      }
    }
  }
}


text:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/ly_main_tab_bottom"
    android:layout_width="fill_parent"
    android:orientation="vertical"
    android:layout_height="@dimen/main_tab_high"
    android:background="@color/colorTabbarBg">

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="match_parent" >

        <LinearLayout
            android:id="@+id/id_tab_bottom_workroom"
            android:layout_width="0dp"
            android:layout_height="fill_parent"
            android:layout_weight="1"
            android:descendantFocusability="beforeDescendants"
            android:gravity="center"
            android:orientation="vertical" >

            <ImageButton
            android:id="@+id/btn_tab_bottom_icon_0"
            android:layout_width="25dp"
            android:layout_height="25dp"

            android:clickable="false"
            android:background="@drawable/wrench_un" />

            <TextView
                android:id="@+id/tabbar_text_0"
                android:textSize="15dp"
                android:layout_width="wrap_content"
                android:layout_height="19dp"
                android:text="工单" />
        </LinearLayout>
        <LinearLayout
            android:id="@+id/id_tab_bottom_weixin"
            android:layout_width="0dp"
            android:layout_height="fill_parent"
            android:layout_weight="1"
            android:descendantFocusability="beforeDescendants"
            android:gravity="center"
            android:orientation="vertical" >

            <ImageButton
                android:id="@+id/btn_tab_bottom_icon_1"
                android:layout_width="25dp"
                android:layout_height="25dp"

                android:clickable="false"
                android:background="@drawable/clock_un" />

            <TextView
                android:id="@+id/tabbar_text_1"
                android:textSize="15dp"
                android:layout_width="wrap_content"
                android:layout_height="19dp"
                android:text="提醒" />
        </LinearLayout>

        <LinearLayout
            android:id="@+id/id_tab_bottom_friend"
            android:layout_width="0dp"
            android:layout_height="fill_parent"
            android:layout_weight="1"
            android:descendantFocusability="beforeDescendants"
            android:gravity="center"
            android:orientation="vertical" >

            <ImageButton
                android:id="@+id/btn_tab_bottom_icon_2"
                android:layout_width="25dp"
                android:layout_height="25dp"

                android:clickable="false"
                android:background="@drawable/people_un" />

            <TextView
                android:id="@+id/tabbar_text_2"
                android:textSize="15dp"
                android:layout_width="wrap_content"
                android:layout_height="19dp"
                android:text="客户" />
        </LinearLayout>

        <LinearLayout
            android:id="@+id/id_tab_bottom_contact"
            android:layout_width="0dp"
            android:layout_height="fill_parent"
            android:layout_weight="1"
            android:descendantFocusability="beforeDescendants"
            android:gravity="center"
            android:orientation="vertical" >

            <ImageButton
                android:id="@+id/btn_tab_bottom_icon_3"
                android:layout_width="25dp"
                android:layout_height="25dp"

                android:clickable="false"
                android:background="@drawable/tongji_on" />

            <TextView
                android:id="@+id/tabbar_text_3"
                android:textSize="15dp"
                android:layout_width="wrap_content"
                android:layout_height="19dp"
                android:text="统计" />
        </LinearLayout>

        <LinearLayout
            android:id="@+id/id_tab_bottom_setting"
            android:layout_width="0dp"
            android:layout_height="fill_parent"
            android:layout_weight="1"
            android:descendantFocusability="beforeDescendants"
            android:gravity="center"
            android:orientation="vertical" >

            <ImageButton
                android:id="@+id/btn_tab_bottom_icon_4"
                android:layout_width="25dp"
                android:layout_height="25dp"

                android:clickable="false"
                android:background="@drawable/setup" />

            <TextView
                android:id="@+id/tabbar_text_4"
                android:textSize="15dp"
                android:layout_width="wrap_content"
                android:layout_height="19dp"
                android:text="我的" />

        </LinearLayout>
    </LinearLayout>

</FrameLayout>

redpajama_set_name: RedPajamaGithub


text:
<?xml version="1.0" encoding="UTF-8"?>
<module>
    <inherits name="gwt.react.React" />

    <source path='client' />
</module>


text:
namespace Azi.Cloud.DokanNet
{
    using System.Threading.Tasks;
    using Azi.Cloud.Common;

    public interface IAbsoluteCacheItem
    {
        FSItem FSItem { get; }

        void Dispose();

        Task<Block> GetBlock(long blockIndex);

        void ReleaseBlock(Block block);
    }
}


text:
<?php

namespace Tidal\WampWatch;

use React\Promise\Deferred;
use Thruway\Message\UnsubscribeMessage;
use Thruway\Common\Utils;

/**
 * Utility Class for the WampWatch package.
 *
 * @author Timo Michna
 */
class Util
{
    public static function unsubscribe(ClientSessionInterface $session, $subscriptionId)
    {
        $requestId = Utils::getUniqueId();
        $deferred = new Deferred();
        $unsubscribeMsg = new UnsubscribeMessage($requestId, $subscriptionId);
        $session->sendMessage($unsubscribeMsg);

        return $deferred->promise();
    }
}


text:
package com.scut.vsp.code.codemodule.entity;

import org.springframework.context.ApplicationContext;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by sosoo on 2016/11/28.
 */

public class Program {
    private ApplicationContext context;
    private String name;
    private List<variableModule> variableModules;
    private List<procedureModule> procedureModules;

    public Program(String name) {
        this.name = name;
        variableModules = new ArrayList<variableModule>();
        procedureModules = new ArrayList<procedureModule>();
    }

    public List<variableModule> getVariableModules() {
        return variableModules;
    }

    public void setVariableModules(List<Object> variableModules) throws Exception {
        for (Object object : variableModules) {
            Map map = (HashMap) object;
            String moduleTypeStr = (String) map.get("moduleType");
            variableModule variable = (variableModule) context.getBean(moduleTypeStr);
            variable.init(map);
            this.variableModules.add(variable);
        }
    }

    public List<procedureModule> getProcedureModules() {
        return procedureModules;
    }

    public void setProcedureModules(List<Object> procedureModules) throws Exception {
        for (Object object : procedureModules) {
            Map map = (HashMap) object;
            String moduleTypeStr = (String) map.get("moduleType");
            procedureModule procedure = (procedureModule) context.getBean(moduleTypeStr);
            procedure.setContext(context);
            procedure.init(map);
            this.procedureModules.add(procedure);
        }
    }

    public void setContext(ApplicationContext context) {
        this.context = context;
    }

    public String getName() {
        return name;
    }
}


text:
<!DOCTYPE public PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

  <meta name="generator" content="ex2html.rb" />
  <meta http-equiv="Content-Type" content=
  "text/html; charset=us-ascii" />
  <link rel="stylesheet" type="text/css" href="css/popup.css" />

  <title>RMagick example: coalesce.rb</title>

coalesce.rb

#!/home/software/ruby-1.8.7/bin/ruby -w
require 'RMagick'

buttons = Magick::ImageList.new

# Read 25 alphabet image files, scale to 1/4 size
letter = 'A'
26.times {
    if letter != 'M'            # "M" is not the same size as the other letters
        tiny = Magick::Image.read('images/Button_' + letter + '.gif').first
        tiny.scale! 0.25
        buttons << tiny
    end
    letter.succ!
    }

# Create a image that will hold the alphabet images in 5 rows and 5 columns.
cells = Magick::ImageList.new
cells.new_image buttons.columns*5, buttons.rows*5 do
    self.background_color = "#000000ff"     # transparent
    end
cells.matte = true

offset = Magick::Rectangle.new(0,0,0,0)

# Create 2 arrays from which we can randomly choose row,col pairs
row = [0]*5 + [1]*5 + [2]*5 + [3]*5 + [4]*5
col = (0..4).to_a * 5

# The coalesce method composites the 2nd image over the 1st, the 3rd image
# over the result, and so forth, respecting the page offset of the images.

srand 1234
25.times { |i|
    # Randomly select a row and column for this copy of the "tinya" image.
    # Compute the x,y position of this copy in pixels and store the
    # result in the image's page attribute. Append a copy of the image
    # to the image array in "a".
    n = rand row.length
    x = row.delete_at n
    y = col.delete_at n

    button = buttons[i]
    offset.x = x*button.columns
    offset.y = y*button.rows
    button.page = offset
    button.matte = true
    cells << button
    }

puts "This may take a few seconds..."
cells.delay = 10
cells.iterations = 10000
res = cells.coalesce
res.write "coalesce_anim.gif"
res[25].write "coalesce.gif"
exit

Close window


text:
<?php

namespace Kontrolio\Rules\Core;

use Kontrolio\Rules\AbstractComparisonRule;

/**
 * Not equal to validation rule.
 *
 * @package Kontrolio\Rules\Core
 */
class NotEqualTo extends AbstractComparisonRule
{
    /**
     * Validates input.
     *
     * @param mixed $input
     *
     * @return bool
     */
    public function isValid($input = null)
    {
        return $input != $this->value;
    }
}


text:
/**
 * Enum for different event names used for tab-communication
 * @type {Object}
 */
const PostMessageEventNamesEnum = {
  LOADED: '__TAB__LOADED_EVENT__',
  CUSTOM: '__TAB__CUSTOM_EVENT__',
  HANDSHAKE: '__TAB__HANDSHAKE_EVENT__',
  ON_BEFORE_UNLOAD: '__TAB__ON_BEFORE_UNLOAD__',
  PARENT_DISCONNECTED: '__PARENT_DISCONNECTED__',
  HANDSHAKE_WITH_PARENT: '__HANDSHAKE_WITH_PARENT__',
  PARENT_COMMUNICATED: '__PARENT_COMMUNICATED__'
};

export default PostMessageEventNamesEnum;


text:
using System;
using System.ComponentModel;
using System.Collections.Generic;

namespace AdventureWorks.EntityClasses.Purchasing
{
    using Sales;

    /// Class which represents the entity 'Purchasing.ShipMethod'
	public partial class ShipMethod
	{
		#region Class Member Declarations
		private ISet<PurchaseOrderHeader> _purchaseOrderHeaders;
		private ISet<SalesOrderHeader> _salesOrderHeaders;
		private System.DateTime _modifiedDate;
		private System.String _name;
		private System.Guid _rowguid;
		private System.Decimal _shipBase;
		private System.Int32 _shipMethodId;
		private System.Decimal _shipRate;
		#endregion

		/// Initializes a new instance of the <see cref="ShipMethod"/> class.
		public ShipMethod() : base()
		{
			_purchaseOrderHeaders = new HashSet<PurchaseOrderHeader>();
			_salesOrderHeaders = new HashSet<SalesOrderHeader>();
			_shipMethodId = default(System.Int32);
			OnCreated();
		}

		/// Method called from the constructor
		partial void OnCreated();

		/// Returns a hash code for this instance.
		/// <returns>A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table. </returns>
		public override int GetHashCode()
		{
			int toReturn = base.GetHashCode();
			toReturn ^= this.ShipMethodId.GetHashCode();
			return toReturn;
		}

		/// Determines whether the specified object is equal to this instance.
		/// <param name="obj">The <see cref="System.Object"/> to compare with this instance.</param>
		/// <returns><c>true</c> if the specified <see cref="System.Object"/> is equal to this instance; otherwise, <c>false</c>.</returns>
		public override bool Equals(object obj)
		{
			if(obj == null)
			{
				return false;
			}
			ShipMethod toCompareWith = obj as ShipMethod;
			return toCompareWith == null ? false : ((this.ShipMethodId == toCompareWith.ShipMethodId));
		}

		#region Class Property Declarations
		/// Gets or sets the ModifiedDate field.
		public virtual System.DateTime ModifiedDate
		{
			get { return _modifiedDate; }
			set { _modifiedDate = value; }
		}

		/// Gets or sets the Name field.
		public virtual System.String Name
		{
			get { return _name; }
			set { _name = value; }
		}

		/// Gets or sets the Rowguid field.
		public virtual System.Guid Rowguid
		{
			get { return _rowguid; }
			set { _rowguid = value; }
		}

		/// Gets or sets the ShipBase field.
		public virtual System.Decimal ShipBase
		{
			get { return _shipBase; }
			set { _shipBase = value; }
		}

		/// Gets the ShipMethodId field.
		public virtual System.Int32 ShipMethodId
		{
			get { return _shipMethodId; }
		}

		/// Gets or sets the ShipRate field.
		public virtual System.Decimal ShipRate
		{
			get { return _shipRate; }
			set { _shipRate = value; }
		}

		/// Represents the navigator which is mapped onto the association 'Purchasing.PurchaseOrderHeader.ShipMethod - Purchasing.ShipMethod.PurchaseOrderHeaders (m:1)'
		public virtual ISet<PurchaseOrderHeader> PurchaseOrderHeaders
		{
			get { return _purchaseOrderHeaders; }
			set { _purchaseOrderHeaders = value; }
		}

		/// Represents the navigator which is mapped onto the association 'Sales.SalesOrderHeader.ShipMethod - Purchasing.ShipMethod.SalesOrderHeaders (m:1)'
		public virtual ISet<SalesOrderHeader> SalesOrderHeaders
		{
			get { return _salesOrderHeaders; }
			set { _salesOrderHeaders = value; }
		}

		#endregion
	}
}


text:
<?xml version="1.0" encoding="UTF-8"?>
<testsuite name="org.apache.commons.math3.analysis.solvers.UnivariateSolverUtilsTest" time="0.002" tests="21" errors="0" skipped="0" failures="0">
  <properties>
    <property name="java.runtime.name" value="Java(TM) SE Runtime Environment"/>
    <property name="sun.boot.library.path" value="/Library/Java/JavaVirtualMachines/jdk1.7.0_09.jdk/Contents/Home/jre/lib"/>
    <property name="java.vm.version" value="23.5-b02"/>
    <property name="user.country.format" value="IN"/>
    <property name="gopherProxySet" value="false"/>
    <property name="java.vm.vendor" value="Oracle Corporation"/>
    <property name="java.vendor.url" value="http://java.oracle.com/"/>
    <property name="path.separator" value=":"/>
    <property name="guice.disable.misplaced.annotation.check" value="true"/>
    <property name="java.vm.name" value="Java HotSpot(TM) 64-Bit Server VM"/>
    <property name="file.encoding.pkg" value="sun.io"/>
    <property name="user.country" value="US"/>
    <property name="sun.java.launcher" value="SUN_STANDARD"/>
    <property name="sun.os.patch.level" value="unknown"/>
    <property name="java.vm.specification.name" value="Java Virtual Machine Specification"/>
    <property name="user.dir" value="/Users/nandu/Downloads/math (trunk)"/>
    <property name="java.runtime.version" value="1.7.0_09-b05"/>
    <property name="java.awt.graphicsenv" value="sun.awt.CGraphicsEnvironment"/>
    <property name="java.endorsed.dirs" value="/Library/Java/JavaVirtualMachines/jdk1.7.0_09.jdk/Contents/Home/jre/lib/endorsed"/>
    <property name="os.arch" value="x86_64"/>
    <property name="java.io.tmpdir" value="/var/folders/v3/9l6_62855xl2r1qshsbdv1l80000gn/T/"/>
    <property name="line.separator" value="
"/>
    <property name="java.vm.specification.vendor" value="Oracle Corporation"/>
    <property name="os.name" value="Mac OS X"/>
    <property name="classworlds.conf" value="/usr/share/maven/bin/m2.conf"/>
    <property name="sun.jnu.encoding" value="UTF-8"/>
    <property name="java.library.path" value="/Users/nandu/Library/Java/Extensions:/Library/Java/Extensions:/Network/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java:."/>
    <property name="java.specification.name" value="Java Platform API Specification"/>
    <property name="java.class.version" value="51.0"/>
    <property name="sun.management.compiler" value="HotSpot 64-Bit Tiered Compilers"/>
    <property name="os.version" value="10.7.5"/>
    <property name="http.nonProxyHosts" value="local|*.local|169.254/16|*.169.254/16"/>
    <property name="user.home" value="/Users/nandu"/>
    <property name="user.timezone" value="Asia/Kolkata"/>
    <property name="java.awt.printerjob" value="sun.lwawt.macosx.CPrinterJob"/>
    <property name="java.specification.version" value="1.7"/>
    <property name="file.encoding" value="UTF-8"/>
    <property name="user.name" value="nandu"/>
    <property name="java.class.path" value="/usr/share/maven/boot/plexus-classworlds-2.4.jar"/>
    <property name="java.vm.specification.version" value="1.7"/>
    <property name="sun.arch.data.model" value="64"/>
    <property name="java.home" value="/Library/Java/JavaVirtualMachines/jdk1.7.0_09.jdk/Contents/Home/jre"/>
    <property name="sun.java.command" value="org.codehaus.plexus.classworlds.launcher.Launcher clean install"/>
    <property name="java.specification.vendor" value="Oracle Corporation"/>
    <property name="user.language" value="en"/>
    <property name="awt.toolkit" value="sun.lwawt.macosx.LWCToolkit"/>
    <property name="java.vm.info" value="mixed mode"/>
    <property name="java.version" value="1.7.0_09"/>
    <property name="java.ext.dirs" value="/Users/nandu/Library/Java/Extensions:/Library/Java/JavaVirtualMachines/jdk1.7.0_09.jdk/Contents/Home/jre/lib/ext:/Library/Java/Extensions:/Network/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java"/>
    <property name="sun.boot.class.path" value="/Library/Java/JavaVirtualMachines/jdk1.7.0_09.jdk/Contents/Home/jre/lib/resources.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_09.jdk/Contents/Home/jre/lib/rt.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_09.jdk/Contents/Home/jre/lib/sunrsasign.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_09.jdk/Contents/Home/jre/lib/jsse.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_09.jdk/Contents/Home/jre/lib/jce.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_09.jdk/Contents/Home/jre/lib/charsets.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_09.jdk/Contents/Home/jre/lib/jfr.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_09.jdk/Contents/Home/jre/lib/JObjC.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_09.jdk/Contents/Home/jre/classes"/>
    <property name="java.vendor" value="Oracle Corporation"/>
    <property name="maven.home" value="/usr/share/maven"/>
    <property name="file.separator" value="/"/>
    <property name="java.vendor.url.bug" value="http://bugreport.sun.com/bugreport/"/>
    <property name="sun.cpu.endian" value="little"/>
    <property name="sun.io.unicode.encoding" value="UnicodeBig"/>
    <property name="socksNonProxyHosts" value="local|*.local|169.254/16|*.169.254/16"/>
    <property name="ftp.nonProxyHosts" value="local|*.local|169.254/16|*.169.254/16"/>
    <property name="sun.cpu.isalist" value=""/>
  </properties>
  <testcase name="testSolveNoRoot" classname="org.apache.commons.math3.analysis.solvers.UnivariateSolverUtilsTest" time="0"/>
  <testcase name="testSolveSin" classname="org.apache.commons.math3.analysis.solvers.UnivariateSolverUtilsTest" time="0"/>
  <testcase name="testBracketLinear" classname="org.apache.commons.math3.analysis.solvers.UnivariateSolverUtilsTest" time="0"/>
  <testcase name="testNullFunction" classname="org.apache.commons.math3.analysis.solvers.UnivariateSolverUtilsTest" time="0"/>
  <testcase name="testSolveAccuracySin" classname="org.apache.commons.math3.analysis.solvers.UnivariateSolverUtilsTest" time="0"/>
  <testcase name="testSolveBadAccuracy" classname="org.apache.commons.math3.analysis.solvers.UnivariateSolverUtilsTest" time="0"/>
  <testcase name="testMisc" classname="org.apache.commons.math3.analysis.solvers.UnivariateSolverUtilsTest" time="0"/>
  <testcase name="testBracketHigh" classname="org.apache.commons.math3.analysis.solvers.UnivariateSolverUtilsTest" time="0"/>
  <testcase name="testIterationExceeded" classname="org.apache.commons.math3.analysis.solvers.UnivariateSolverUtilsTest" time="0"/>
  <testcase name="testBracketCentered" classname="org.apache.commons.math3.analysis.solvers.UnivariateSolverUtilsTest" time="0"/>
  <testcase name="testSolveNull" classname="org.apache.commons.math3.analysis.solvers.UnivariateSolverUtilsTest" time="0"/>
  <testcase name="testBracketLow" classname="org.apache.commons.math3.analysis.solvers.UnivariateSolverUtilsTest" time="0"/>
  <testcase name="testBracketSin" classname="org.apache.commons.math3.analysis.solvers.UnivariateSolverUtilsTest" time="0"/>
  <testcase name="testBadInitial" classname="org.apache.commons.math3.analysis.solvers.UnivariateSolverUtilsTest" time="0"/>
  <testcase name="testBracketExponential" classname="org.apache.commons.math3.analysis.solvers.UnivariateSolverUtilsTest" time="0.001"/>
  <testcase name="testBadMaximumIterations" classname="org.apache.commons.math3.analysis.solvers.UnivariateSolverUtilsTest" time="0"/>
  <testcase name="testBadAdditive" classname="org.apache.commons.math3.analysis.solvers.UnivariateSolverUtilsTest" time="0.001"/>
  <testcase name="testBadEndpoints" classname="org.apache.commons.math3.analysis.solvers.UnivariateSolverUtilsTest" time="0"/>
  <testcase name="testBracketEndpointRoot" classname="org.apache.commons.math3.analysis.solvers.UnivariateSolverUtilsTest" time="0"/>
  <testcase name="testSolveAccuracyNull" classname="org.apache.commons.math3.analysis.solvers.UnivariateSolverUtilsTest" time="0"/>
  <testcase name="testSolveBadEndpoints" classname="org.apache.commons.math3.analysis.solvers.UnivariateSolverUtilsTest" time="0"/>
</testsuite>


text:
/**
 *
 * Created by Playground Milano
 *
 */

"use strict";

angular.module("playgrounds-map", []).config(PlaygroundsMapConfig);
PlaygroundsMapConfig.$inject = ["$stateProvider", "$urlRouterProvider"];

function PlaygroundsMapConfig($stateProvider) {

    $stateProvider
        .state("playgroundsmap", {
            parent: "headermenu",
            url: "/mappa-dei-campi",
            title: "Mappa dei campi",
            controller: "PlaygroundsMapController",
            templateProvider: ["$q", function ($q) {
                var deferred = $q.defer();
                require.ensure([], function (require) {
                        var template = require("./_views/playgrounds-map.html");
                        deferred.resolve(template);
                    }
                );
                return deferred.promise;
            }],
            resolve: {
                load: ["$q", "$ocLazyLoad", function ($q, $ocLazyLoad) {
                    var deferred = $q.defer();
                    require.ensure([], function (require) {
                            var module = require("./_controller/PlaygroundsMapController");
                            $ocLazyLoad.load({name: "playgrounds-map.controller"});
                            deferred.resolve(module);
                        }
                    );
                    return deferred.promise;
                }],
                playgroundsResponse: ["HttpWrapper", function (HttpWrapper) {
                    return HttpWrapper("GET", "playgrounds");
                }]
            }
        });

}


text:
#define DSS_SUBSYS_NAME "SDI"

#include <linux/kernel.h>
#include <linux/delay.h>
#include <linux/err.h>
#include <linux/regulator/consumer.h>
#include <linux/export.h>
#include <linux/platform_device.h>
#include <linux/string.h>

#include <video/omapdss.h>
#include "dss.h"

static struct {
	bool update_enabled;
	struct regulator *vdds_sdi_reg;

	struct dss_lcd_mgr_config mgr_config;
	struct omap_video_timings timings;
	int datapairs;

	struct omap_dss_output output;
} sdi;

struct sdi_clk_calc_ctx {
	unsigned long pck_min, pck_max;

	struct dss_clock_info dss_cinfo;
	struct dispc_clock_info dispc_cinfo;
};

static bool dpi_calc_dispc_cb(int lckd, int pckd, unsigned long lck,
		unsigned long pck, void *data)
{
	struct sdi_clk_calc_ctx *ctx = data;

	ctx->dispc_cinfo.lck_div = lckd;
	ctx->dispc_cinfo.pck_div = pckd;
	ctx->dispc_cinfo.lck = lck;
	ctx->dispc_cinfo.pck = pck;

	return true;
}

static bool dpi_calc_dss_cb(int fckd, unsigned long fck, void *data)
{
	struct sdi_clk_calc_ctx *ctx = data;

	ctx->dss_cinfo.fck = fck;
	ctx->dss_cinfo.fck_div = fckd;

	return dispc_div_calc(fck, ctx->pck_min, ctx->pck_max,
			dpi_calc_dispc_cb, ctx);
}

static int sdi_calc_clock_div(unsigned long pclk,
		struct dss_clock_info *dss_cinfo,
		struct dispc_clock_info *dispc_cinfo)
{
	int i;
	struct sdi_clk_calc_ctx ctx;

	/*
	 * DSS fclk gives us very few possibilities, so finding a good pixel
	 * clock may not be possible. We try multiple times to find the clock,
	 * each time widening the pixel clock range we look for, up to
	 * +/- 1MHz.
	 */

	for (i = 0; i < 10; ++i) {
		bool ok;

		memset(&ctx, 0, sizeof(ctx));
		if (pclk > 1000 * i * i * i)
			ctx.pck_min = max(pclk - 1000 * i * i * i, 0lu);
		else
			ctx.pck_min = 0;
		ctx.pck_max = pclk + 1000 * i * i * i;

		ok = dss_div_calc(ctx.pck_min, dpi_calc_dss_cb, &ctx);
		if (ok) {
			*dss_cinfo = ctx.dss_cinfo;
			*dispc_cinfo = ctx.dispc_cinfo;
			return 0;
		}
	}

	return -EINVAL;
}

static void sdi_config_lcd_manager(struct omap_dss_device *dssdev)
{
	struct omap_overlay_manager *mgr = dssdev->output->manager;

	sdi.mgr_config.io_pad_mode = DSS_IO_PAD_MODE_BYPASS;

	sdi.mgr_config.stallmode = false;
	sdi.mgr_config.fifohandcheck = false;

	sdi.mgr_config.video_port_width = 24;
	sdi.mgr_config.lcden_sig_polarity = 1;

	dss_mgr_set_lcd_config(mgr, &sdi.mgr_config);
}

int omapdss_sdi_display_enable(struct omap_dss_device *dssdev)
{
	struct omap_dss_output *out = dssdev->output;
	struct omap_video_timings *t = &sdi.timings;
	struct dss_clock_info dss_cinfo;
	struct dispc_clock_info dispc_cinfo;
	unsigned long pck;
	int r;

	if (out == NULL || out->manager == NULL) {
		DSSERR("failed to enable display: no output/manager\n");
		return -ENODEV;
	}

	r = omap_dss_start_device(dssdev);
	if (r) {
		DSSERR("failed to start device\n");
		goto err_start_dev;
	}

	r = regulator_enable(sdi.vdds_sdi_reg);
	if (r)
		goto err_reg_enable;

	r = dispc_runtime_get();
	if (r)
		goto err_get_dispc;

	/* 15.5.9.1.2 */
	t->data_pclk_edge = OMAPDSS_DRIVE_SIG_RISING_EDGE;
	t->sync_pclk_edge = OMAPDSS_DRIVE_SIG_RISING_EDGE;

	r = sdi_calc_clock_div(t->pixel_clock * 1000, &dss_cinfo, &dispc_cinfo);
	if (r)
		goto err_calc_clock_div;

	sdi.mgr_config.clock_info = dispc_cinfo;

	pck = dss_cinfo.fck / dispc_cinfo.lck_div / dispc_cinfo.pck_div / 1000;

	if (pck != t->pixel_clock) {
		DSSWARN("Could not find exact pixel clock. Requested %d kHz, "
				"got %lu kHz\n",
				t->pixel_clock, pck);

		t->pixel_clock = pck;
	}

	dss_mgr_set_timings(out->manager, t);

	r = dss_set_clock_div(&dss_cinfo);
	if (r)
		goto err_set_dss_clock_div;

	sdi_config_lcd_manager(dssdev);

	/*
	 * LCLK and PCLK divisors are located in shadow registers, and we
	 * normally write them to DISPC registers when enabling the output.
	 * However, SDI uses pck-free as source clock for its PLL, and pck-free
	 * is affected by the divisors. And as we need the PLL before enabling
	 * the output, we need to write the divisors early.
	 *
	 * It seems just writing to the DISPC register is enough, and we don't
	 * need to care about the shadow register mechanism for pck-free. The
	 * exact reason for this is unknown.
	 */
	dispc_mgr_set_clock_div(out->manager->id, &sdi.mgr_config.clock_info);

	dss_sdi_init(sdi.datapairs);
	r = dss_sdi_enable();
	if (r)
		goto err_sdi_enable;
	mdelay(2);

	r = dss_mgr_enable(out->manager);
	if (r)
		goto err_mgr_enable;

	return 0;

err_mgr_enable:
	dss_sdi_disable();
err_sdi_enable:
err_set_dss_clock_div:
err_calc_clock_div:
	dispc_runtime_put();
err_get_dispc:
	regulator_disable(sdi.vdds_sdi_reg);
err_reg_enable:
	omap_dss_stop_device(dssdev);
err_start_dev:
	return r;
}
EXPORT_SYMBOL(omapdss_sdi_display_enable);

void omapdss_sdi_display_disable(struct omap_dss_device *dssdev)
{
	struct omap_overlay_manager *mgr = dssdev->output->manager;

	dss_mgr_disable(mgr);

	dss_sdi_disable();

	dispc_runtime_put();

	regulator_disable(sdi.vdds_sdi_reg);

	omap_dss_stop_device(dssdev);
}
EXPORT_SYMBOL(omapdss_sdi_display_disable);

void omapdss_sdi_set_timings(struct omap_dss_device *dssdev,
		struct omap_video_timings *timings)
{
	sdi.timings = *timings;
}
EXPORT_SYMBOL(omapdss_sdi_set_timings);

void omapdss_sdi_set_datapairs(struct omap_dss_device *dssdev, int datapairs)
{
	sdi.datapairs = datapairs;
}
EXPORT_SYMBOL(omapdss_sdi_set_datapairs);

static int sdi_init_display(struct omap_dss_device *dssdev)
{
	DSSDBG("SDI init\n");

	if (sdi.vdds_sdi_reg == NULL) {
		struct regulator *vdds_sdi;

		vdds_sdi = dss_get_vdds_sdi();

		if (IS_ERR(vdds_sdi)) {
			DSSERR("can't get VDDS_SDI regulator\n");
			return PTR_ERR(vdds_sdi);
		}

		sdi.vdds_sdi_reg = vdds_sdi;
	}

	return 0;
}

static struct omap_dss_device *sdi_find_dssdev(struct platform_device *pdev)
{
	struct omap_dss_board_info *pdata = pdev->dev.platform_data;
	const char *def_disp_name = omapdss_get_default_display_name();
	struct omap_dss_device *def_dssdev;
	int i;

	def_dssdev = NULL;

	for (i = 0; i < pdata->num_devices; ++i) {
		struct omap_dss_device *dssdev = pdata->devices[i];

		if (dssdev->type != OMAP_DISPLAY_TYPE_SDI)
			continue;

		if (def_dssdev == NULL)
			def_dssdev = dssdev;

		if (def_disp_name != NULL &&
				strcmp(dssdev->name, def_disp_name) == 0) {
			def_dssdev = dssdev;
			break;
		}
	}

	return def_dssdev;
}

static int sdi_probe_pdata(struct platform_device *sdidev)
{
	struct omap_dss_device *plat_dssdev;
	struct omap_dss_device *dssdev;
	int r;

	plat_dssdev = sdi_find_dssdev(sdidev);

	if (!plat_dssdev)
		return 0;

	dssdev = dss_alloc_and_init_device(&sdidev->dev);
	if (!dssdev)
		return -ENOMEM;

	dss_copy_device_pdata(dssdev, plat_dssdev);

	r = sdi_init_display(dssdev);
	if (r) {
		DSSERR("device %s init failed: %d\n", dssdev->name, r);
		dss_put_device(dssdev);
		return r;
	}

	r = omapdss_output_set_device(&sdi.output, dssdev);
	if (r) {
		DSSERR("failed to connect output to new device: %s\n",
				dssdev->name);
		dss_put_device(dssdev);
		return r;
	}

	r = dss_add_device(dssdev);
	if (r) {
		DSSERR("device %s register failed: %d\n", dssdev->name, r);
		omapdss_output_unset_device(&sdi.output);
		dss_put_device(dssdev);
		return r;
	}

	return 0;
}

static void sdi_init_output(struct platform_device *pdev)
{
	struct omap_dss_output *out = &sdi.output;

	out->pdev = pdev;
	out->id = OMAP_DSS_OUTPUT_SDI;
	out->type = OMAP_DISPLAY_TYPE_SDI;
	out->name = "sdi.0";
	out->dispc_channel = OMAP_DSS_CHANNEL_LCD;

	dss_register_output(out);
}

static void __exit sdi_uninit_output(struct platform_device *pdev)
{
	struct omap_dss_output *out = &sdi.output;

	dss_unregister_output(out);
}

static int omap_sdi_probe(struct platform_device *pdev)
{
	int r;

	sdi_init_output(pdev);

	r = sdi_probe_pdata(pdev);
	if (r) {
		sdi_uninit_output(pdev);
		return r;
	}

	return 0;
}

static int __exit omap_sdi_remove(struct platform_device *pdev)
{
	dss_unregister_child_devices(&pdev->dev);

	sdi_uninit_output(pdev);

	return 0;
}

static struct platform_driver omap_sdi_driver = {
	.probe		= omap_sdi_probe,
	.remove         = __exit_p(omap_sdi_remove),
	.driver         = {
		.name   = "omapdss_sdi",
		.owner  = THIS_MODULE,
	},
};

int __init sdi_init_platform_driver(void)
{
	return platform_driver_register(&omap_sdi_driver);
}

void __exit sdi_uninit_platform_driver(void)
{
	platform_driver_unregister(&omap_sdi_driver);
}


text:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.uberfire.provisioning</groupId>
        <artifactId>uberfire-provisioning</artifactId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <artifactId>uberfire-provisioning-integration-tests</artifactId>
    <name>Uberfire Provisioning :: Integration Tests</name>
    <packaging>jar</packaging>
    <dependencies>

        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.uberfire.provisioning</groupId>
            <artifactId>uberfire-provisioning-spi</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.uberfire.provisioning</groupId>
            <artifactId>uberfire-provisioning-source-git</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.uberfire.provisioning</groupId>
            <artifactId>uberfire-provisioning-pipeline-local</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.uberfire.provisioning</groupId>
            <artifactId>uberfire-provisioning-build-maven</artifactId>
            <scope>test</scope>
        </dependency>

        <!-- Registry Local Mock Implementation -->
        <dependency>
            <groupId>org.uberfire.provisioning</groupId>
            <artifactId>uberfire-provisioning-registry-local</artifactId>
            <scope>test</scope>
        </dependency>

        <!-- Providers -->
        <dependency>
            <groupId>org.uberfire.provisioning</groupId>
            <artifactId>uberfire-provisioning-local-provider</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.uberfire.provisioning</groupId>
            <artifactId>uberfire-provisioning-docker-provider</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.uberfire.provisioning</groupId>
            <artifactId>uberfire-provisioning-openshift-provider</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.uberfire.provisioning</groupId>
            <artifactId>uberfire-provisioning-wildfly-provider</artifactId>
            <scope>test</scope>
        </dependency>

        <!-- Arquillian Tests -->

        <dependency>
            <groupId>org.jboss.weld.se</groupId>
            <artifactId>weld-se-core</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.jboss.arquillian.junit</groupId>
            <artifactId>arquillian-junit-container</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.jboss.arquillian.container</groupId>
            <artifactId>arquillian-weld-se-embedded-1.1</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-annotations</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.dataformat</groupId>
            <artifactId>jackson-dataformat-yaml</artifactId>
            <version>2.6.4</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpcore</artifactId>
            <version>4.4.1</version>
        </dependency>
        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
            <version>4.5.2</version>
        </dependency>
    </dependencies>
</project>


text:
(window["webpackJsonp_8217e442_8ed3_41fd_957d_b112e841286a_0_8_24"] = window["webpackJsonp_8217e442_8ed3_41fd_957d_b112e841286a_0_8_24"] || []).push([["sp-client-telemetry-aria"],{

/***/ "GdB4":
/*!****************************!*\
  !*** ./lib/ariaWrapper.js ***!
  \****************************/
/*! exports provided: ariaWrapper */
/***/ (function(module, __webpack_exports__, __webpack_require__) {

"use strict";
__webpack_require__.r(__webpack_exports__);
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "ariaWrapper", function() { return ariaWrapper; });
var ariaWrapper = __webpack_require__(/*! exports-loader?microsoft.applications.telemetry!@ms/aria-private */ "GMzq");

/***/ })

}]);
//# sourceMappingURL=chunk.sp-client-telemetry-aria_08869d8e4fa227dc23f3.js.map


text:
@class FRPSessionDetailsViewModel;

@interface FRPSessionDetailsViewController : UIViewController

@property (nonatomic, strong) FRPSessionDetailsViewModel* viewModel;

@end


text:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/activity_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fillViewport="true"
        android:id="@+id/scrollView1">
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:background="?attr/colorPrimary"
                app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
                app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
                />
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal">
                <RelativeLayout
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:padding="10dp">
                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_centerHorizontal="true"
                        android:text="本日总计"
                        android:id="@+id/textView2"/>
                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_centerHorizontal="true"
                        android:text="152"
                        android:layout_below="@id/textView2"
                        android:id="@+id/textViewDaySummary"
                        android:textSize="30sp"
                        android:layout_marginTop="5dp"/>
                </RelativeLayout>
                <View
                    android:layout_width="1dp"
                    android:layout_height="match_parent"
                    android:background="#eee"
                    />
                <RelativeLayout
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:padding="10dp">
                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_centerHorizontal="true"
                        android:text="本月总计"
                        android:id="@+id/textView1"
                        />
                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_centerHorizontal="true"
                        android:text="0"
                        android:layout_below="@id/textView1"
                        android:id="@+id/textViewMonthSummary"
                        android:textSize="30sp"
                        android:layout_marginTop="5dp"/>
                </RelativeLayout>

            </LinearLayout>
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_margin="5dp"
                android:text="本日明细"
                android:textSize="18sp"/>

            <com.example.zdk.tagnumber.ListViewForScrollView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:id="@+id/listViewTodayDetails"
                />
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="10dp"
                android:layout_marginBottom="10dp"
                android:layout_marginLeft="5dp"
                android:layout_marginRight="5dp"
                android:text="本月统计"
                android:textSize="18sp"/>

            <com.example.zdk.tagnumber.ListViewForScrollView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:id="@+id/listViewTagStatistics"
                />
        </LinearLayout>
    </ScrollView>
</LinearLayout>


text:
using System;

namespace CocosSharp
{
	public class CCEventGamePadTrigger : CCEventGamePad
	{
		public float Left { get; internal set; }
		public float Right { get; internal set; }

		public CCPlayerIndex Player { get; internal set; }

		internal CCEventGamePadTrigger()
			: base(CCGamePadEventType.GAMEPAD_TRIGGER)
		{ }
	}
}


text:
<?php

namespace DBORM\CSIBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;

class DefaultController extends Controller
{
    public function indexAction($name)
    {
        return $this->render('DBORMCSIBundle:Default:index.html.twig', array('name' => $name));
    }
}


text:
package org.wso2.developerstudio.eclipse.platform.ui.utils;

import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
import org.eclipse.emf.common.ui.dialogs.WorkspaceResourceDialog;
import org.eclipse.jface.viewers.CheckboxTableViewer;
import org.eclipse.jface.viewers.ViewerFilter;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.DirectoryDialog;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Link;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.forms.events.ExpansionAdapter;
import org.eclipse.ui.forms.events.ExpansionEvent;
import org.eclipse.ui.forms.widgets.ExpandableComposite;
import org.wso2.developerstudio.eclipse.platform.core.interfaces.IDeveloperStudioElement;
import org.wso2.developerstudio.eclipse.platform.core.model.AbstractComposite;
import org.wso2.developerstudio.eclipse.platform.core.model.ICompositeProvider;
import org.wso2.developerstudio.eclipse.platform.core.project.model.ProjectDataModel;
import org.wso2.developerstudio.eclipse.platform.core.project.model.ProjectOptionData;
import org.wso2.developerstudio.eclipse.platform.ui.interfaces.IFieldControlData;
import org.wso2.developerstudio.eclipse.platform.ui.interfaces.IOnAction;
import org.wso2.developerstudio.eclipse.platform.ui.interfaces.UIControl;
import org.wso2.developerstudio.eclipse.platform.ui.startup.RegisterUIControl;
import org.wso2.developerstudio.eclipse.platform.ui.wizard.AbstractWSO2ProjectCreationWizard;
import org.wso2.developerstudio.eclipse.platform.ui.wizard.pages.ProjectOptionsDataPage;

import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

public class WSO2UIToolkit {

	public static Button createOption(Composite container, String label, int columns, Integer verticalIndent,
	                                  Integer horizontalIndent) {
		Button optButton = new Button(container, SWT.RADIO);
		optButton.setText(label);
		if (columns != -1) {
			GridData gridData = new GridData();
			gridData.horizontalSpan = columns;
			gridData.grabExcessHorizontalSpace = true;
			gridData.horizontalAlignment = SWT.FILL;
			if (verticalIndent != null) {
				gridData.verticalIndent = verticalIndent;
			}
			if (horizontalIndent != null) {
				gridData.horizontalIndent = horizontalIndent;
			}
			optButton.setLayoutData(gridData);
		}
		return optButton;
	}

	public static Button createChoice(Composite container, String label, int columns, Integer verticalIndent,
	                                  Integer horizontalIndent) {
		Button chkButton = new Button(container, SWT.CHECK);
		chkButton.setText(label);
		if (columns != -1) {
			GridData gridData = new GridData();
			gridData.horizontalSpan = columns;
			gridData.grabExcessHorizontalSpace = true;
			gridData.horizontalAlignment = SWT.FILL;
			if (verticalIndent != null) {
				gridData.verticalIndent = verticalIndent;
			}
			if (horizontalIndent != null) {
				gridData.horizontalIndent = horizontalIndent;
			}
			chkButton.setLayoutData(gridData);
		}
		return chkButton;
	}

	public static Combo createCombo(Composite container, String label, int columns, boolean isEditable,
	                                Integer verticalIndent, Integer horizontalIndent) {
		final Label lblCaption = new Label(container, SWT.None);
		lblCaption.setText(label);
		GridData gridData = new GridData();
		if (verticalIndent != null) {
			gridData.verticalIndent = verticalIndent;
		}
		if (horizontalIndent != null) {
			gridData.horizontalIndent = horizontalIndent;
		}
		lblCaption.setLayoutData(gridData);
		final Combo cmbValue = new Combo(container, isEditable ? SWT.BORDER : SWT.BORDER | SWT.READ_ONLY);
		propagateControlStatus(cmbValue, lblCaption);
		if (columns != -1) {
			gridData = new GridData();
			gridData.horizontalSpan = columns - 1;
			gridData.grabExcessHorizontalSpace = true;
			gridData.horizontalAlignment = SWT.FILL;
			cmbValue.setLayoutData(gridData);
		}
		return cmbValue;
	}

	public static CheckboxTableViewer createList(Composite container, String label, int columns,
	                                             Integer verticalIndent, Integer horizontalIndent,
	                                             boolean isSelectAllbtn, final ProjectOptionsDataPage dataPage,
	                                             final ProjectOptionData optionData) {
		final Label lblCaption = new Label(container, SWT.None);
		lblCaption.setText(label);
		if (columns != -1) {
			GridData gridData = new GridData();
			gridData.horizontalSpan = columns;
			gridData.grabExcessHorizontalSpace = true;
			gridData.horizontalAlignment = SWT.FILL;
			// gridData.heightHint = 30;
			if (verticalIndent != null) {
				gridData.verticalIndent = verticalIndent;
			}
			if (horizontalIndent != null) {
				gridData.horizontalIndent = horizontalIndent;
			}
			lblCaption.setLayoutData(gridData);
		}

		final CheckboxTableViewer cmbValue =
		                                     CheckboxTableViewer.newCheckList(container, SWT.BORDER |
		                                                                              SWT.FULL_SELECTION);

		if (columns != -1) {
			GridData gridData = new GridData();
			gridData.horizontalSpan = columns;
			gridData.verticalSpan = 5;
			gridData.horizontalIndent = 10;
			gridData.heightHint = 50;
			if (horizontalIndent != null) {
				gridData.horizontalIndent += horizontalIndent;
			}
			gridData.grabExcessHorizontalSpace = true;
			gridData.grabExcessVerticalSpace = true;
			gridData.horizontalAlignment = SWT.FILL;
			gridData.verticalAlignment = SWT.FILL;
			cmbValue.getTable().setLayoutData(gridData);
		}

		if (isSelectAllbtn) {

			Label splabel = new Label(container, SWT.NONE);
			GridData gd = new GridData(GridData.FILL_HORIZONTAL);
			gd.horizontalSpan = columns - 3;
			splabel.setLayoutData(gd);
			splabel.setText("");

			Button selectAllButton = new Button(container, SWT.NONE);
			GridData gdb = new GridData(GridData.END);
			gdb.horizontalSpan = 1;
			selectAllButton.setLayoutData(gdb);
			selectAllButton.setText("Select All");
			selectAllButton.addListener(SWT.MouseDown, new Listener() {
				public void handleEvent(Event evt) {
					cmbValue.setAllChecked(true);
					dataPage.updateListCheckBox(optionData, cmbValue.getCheckedElements());
				}
			});
			Button unSelectAllButton = new Button(container, SWT.NONE);
			unSelectAllButton.setText("Deselect All");
			unSelectAllButton.addListener(SWT.MouseDown, new Listener() {
				public void handleEvent(Event evt) {
					cmbValue.setAllChecked(false);
					dataPage.updateListCheckBox(optionData, cmbValue.getCheckedElements());
				}
			});
			if (columns != -1) {

				GridData gridData = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
				gridData.horizontalSpan = 2;
				gridData.grabExcessHorizontalSpace = false;
				gridData.horizontalAlignment = SWT.RIGHT;
				// gridData.verticalAlignment = SWT.columns
				if (verticalIndent != null) {
					gridData.verticalIndent = verticalIndent;
				}
				if (horizontalIndent != null) {
					gridData.horizontalIndent = horizontalIndent;
				}
				selectAllButton.setLayoutData(gridData);

				gridData = new GridData();
				gridData.horizontalSpan = columns;
				gridData.grabExcessHorizontalSpace = false;
				gridData.horizontalAlignment = SWT.FILL;
				// gridData.verticalAlignment = SWT.columns
				if (verticalIndent != null) {
					gridData.verticalIndent = verticalIndent;
				}
				if (horizontalIndent != null) {
					gridData.horizontalIndent = horizontalIndent;
				}
				unSelectAllButton.setLayoutData(gdb);
			}
			propagateControlStatus(cmbValue.getTable(), lblCaption, selectAllButton, unSelectAllButton);
		} else {

			propagateControlStatus(cmbValue.getTable(), lblCaption);
		}
		return cmbValue;
	}

	public static Link createLink(Composite container, String label, int columns, int horizontalAlignment,
	                              Integer verticalIndent, Integer horizontalIndent) {
		Link linkButton = new Link(container, SWT.CHECK);
		linkButton.setText(label);
		if (columns != -1) {
			GridData gridData = new GridData();
			gridData.horizontalSpan = columns;
			gridData.grabExcessHorizontalSpace = true;
			gridData.horizontalAlignment = horizontalAlignment; // SWT.FILL;
			if (verticalIndent != null) {
				gridData.verticalIndent = verticalIndent;
			}
			if (horizontalIndent != null) {
				gridData.horizontalIndent = horizontalIndent;
			}
			linkButton.setLayoutData(gridData);
		}
		return linkButton;
	}

	public static Label createLabel(Composite container, String label, int columns, int horizontalAlignment,
	                                Integer verticalIndent, Integer horizontalIndent) {
		Label lbl = new Label(container, SWT.CHECK);
		lbl.setText(label);
		if (columns != -1) {
			GridData gridData = new GridData();
			gridData.horizontalSpan = columns;
			gridData.grabExcessHorizontalSpace = true;
			gridData.horizontalAlignment = horizontalAlignment; // SWT.FILL;
			if (verticalIndent != null) {
				gridData.verticalIndent = verticalIndent;
			}
			if (horizontalIndent != null) {
				gridData.horizontalIndent = horizontalIndent;
			}
			lbl.setLayoutData(gridData);
		}
		return lbl;
	}

	public static Label createTitleLabel(Composite container, String label, int columns, int horizontalAlignment,
	                                     Integer verticalIndent, Integer horizontalIndent) {
		Label lblCaption = new Label(container, SWT.CHECK);
		lblCaption.setText(label);
		GridData gridData = new GridData();
		if (verticalIndent != null) {
			gridData.verticalIndent = verticalIndent;
		}
		if (horizontalIndent != null) {
			gridData.horizontalIndent = horizontalIndent;
		}
		lblCaption.setLayoutData(gridData);
		Label lbl = new Label(container, SWT.CHECK);
		lbl.setText(label);
		if (columns != -1) {
			gridData = new GridData();
			gridData.horizontalSpan = columns - 1;
			gridData.grabExcessHorizontalSpace = true;
			gridData.horizontalAlignment = horizontalAlignment; // SWT.FILL;
			if (verticalIndent != null) {
				gridData.verticalIndent = verticalIndent;
			}
			if (horizontalIndent != null) {
				gridData.horizontalIndent = horizontalIndent;
			}
			lbl.setLayoutData(gridData);
		}
		propagateControlStatus(lbl, lblCaption);
		return lbl;
	}

	public static IFieldControlData createRegistryBrowserControl(String id, Composite container, int columns,
	                                                             Integer verticalIndent, Integer horizontalIndent,
	                                                             boolean isTextReadonly, final Shell shell,
	                                                             final String label, String fileButtonCaption,
	                                                             int selectedOption, ProjectDataModel model,
	                                                             String pathBindingProperty) {
		IFieldControlData fieldControl = null;
		Map<String, UIControl> uiControlList = RegisterUIControl.getUiControlList();
		for (Entry<String, UIControl> entry1 : uiControlList.entrySet()) {

			UIControl uiControl = entry1.getValue();
			String uiID = entry1.getKey();
			if (id.equals("registry.browser") && uiID.equals("RegistryBrowserUIControl")) {
				fieldControl =
				               uiControl.createUIField(id, container, columns, verticalIndent, horizontalIndent,
				                                       isTextReadonly, shell, label, fileButtonCaption, selectedOption,
				                                       model, pathBindingProperty);
				break;
			}
		}
		return fieldControl;
	}

	public static IFieldControlData createResourceBrowserControl(String id, Composite container, int columns,
	                                                             Integer verticalIndent, Integer horizontalIndent,
	                                                             boolean isTextReadonly, final Shell shell,
	                                                             final String label, String fileButtonCaption,
	                                                             int selectedOption, ProjectDataModel model,
	                                                             String pathBindingProperty) {
		IFieldControlData fieldControl = null;
		Map<String, UIControl> uiControlList = RegisterUIControl.getUiControlList();
		for (Entry<String, UIControl> entry1 : uiControlList.entrySet()) {

			UIControl uiControl = entry1.getValue();
			String uiID = entry1.getKey();
			if (id.equals("resource.browser") && uiID.equals("ResourceBrowserUIStrip")) {
				fieldControl =
				               uiControl.createUIField(id, container, columns, verticalIndent, horizontalIndent,
				                                       isTextReadonly, shell, label, fileButtonCaption, selectedOption,
				                                       model, pathBindingProperty);
				break;
			}
		}
		return fieldControl;
	}

	public static IFieldControlData createComposite(Composite container, int columns,
	                                                final ICompositeProvider iCompositeProvider,
	                                                ProjectDataModel model, ProjectOptionData optionData,
	                                                WizardPage wizardPage) {

		AbstractComposite composite = iCompositeProvider.createComposite(container, model, optionData, wizardPage);

		GridData gridData = new GridData();
		if (null != optionData.getVerticalIndent()) {
			gridData.verticalIndent = optionData.getVerticalIndent();
		}
		if (null != optionData.getHorizontalIndent()) {
			gridData.horizontalIndent = optionData.getHorizontalIndent();
		}
		if (columns != -1) {
			gridData = new GridData();
			gridData.horizontalSpan = columns;
			gridData.grabExcessHorizontalSpace = true;
			gridData.horizontalAlignment = SWT.FILL;
			gridData.heightHint = -1;
			gridData.grabExcessVerticalSpace = true;

		}
		composite.setLayoutData(gridData);

		FieldControlDataImpl fieldControl = new FieldControlDataImpl(composite) {

			public Composite getControl() {
				return (Composite) super.getControl();
			}

			public void setData(Object data) {
				getControl().setData(data);
			}

			public Object getData() {
				return getControl().getData();
			}

		};
		propagateControlStatus(composite);
		return fieldControl;
	}

	public static IFieldControlData createText(Composite container, String label, int columns, boolean isTextReadonly,
	                                           Integer verticalIndent, Integer horizontalIndent, boolean multiline,
	                                           boolean addlistner, final AbstractWSO2ProjectCreationWizard wizard,
	                                           String toolTip, int height) {
		int flags = (multiline) ? (SWT.BORDER | SWT.MULTI | SWT.WRAP | SWT.V_SCROLL) : SWT.BORDER;
		Label lblCaption = new Label(container, SWT.None);
		lblCaption.setText(label);
		GridData gridData = new GridData();
		if (verticalIndent != null) {
			gridData.verticalIndent = verticalIndent;
		}
		if (horizontalIndent != null) {
			gridData.horizontalIndent = horizontalIndent;
		}
		lblCaption.setLayoutData(gridData);
		Text txtValue = new Text(container, flags);;
		txtValue.setEditable(!isTextReadonly);
		propagateControlStatus(txtValue, lblCaption);
		if (columns != -1) {
			gridData = new GridData();
			gridData.horizontalSpan = columns - 1;
			gridData.grabExcessHorizontalSpace = true;
			gridData.horizontalAlignment = SWT.FILL;
			if (multiline) {
				height = (height > 0) ? height : 65;
				gridData.heightHint = height;
				gridData.grabExcessVerticalSpace = true;
			}
			txtValue.setLayoutData(gridData);
		}
		if (toolTip != null) {
			txtValue.setToolTipText(toolTip);
		}
		if (addlistner) {
			wizard.setMap(label.trim(), txtValue);
		}
		FieldControlDataImpl feildControl = createFieldControlForString(txtValue);
		return feildControl;
	}

	private static FieldControlDataImpl createFieldControlForString(Text txtValue) {
		FieldControlDataImpl feildControl = new FieldControlDataImpl(txtValue) {

			public Text getControl() {
				return (Text) super.getControl();
			}

			public Object getData() {
				return getControl().getText();
			}

			public void setData(Object data) {
				if (data == null) {
					data = "";
				}
				getControl().setText(data.toString());
			}

			public void setOnAction(IOnAction action) {
				super.setOnAction(action);
				getControl().addModifyListener(new ModifyListener() {

					public void modifyText(ModifyEvent arg0) {
						getOnAction().onModifyAction();

					}

				});
			}

		};
		return feildControl;
	}

	public static void createLine(Composite container, int columns, Integer verticalIndent, Integer horizontalIndent) {
		Label label = new Label(container, SWT.SEPARATOR | SWT.HORIZONTAL);
		if (columns != -1) {
			GridData gridData = new GridData();
			gridData.horizontalSpan = columns;
			gridData.grabExcessHorizontalSpace = true;
			gridData.horizontalAlignment = SWT.FILL;
			if (verticalIndent != null) {
				gridData.verticalIndent = verticalIndent;
			}
			if (horizontalIndent != null) {
				gridData.horizontalIndent = horizontalIndent;
			}
			label.setLayoutData(gridData);
		}
	}

	public static Composite createContainer(final Composite container, String label, int columns,
	                                        boolean isCollapsible, boolean isExpanded, Integer verticalIndent,
	                                        Integer horizontalIndent) {
		Composite composite;
		if (label == null) {
			createLine(container, columns, verticalIndent, horizontalIndent);
			verticalIndent = null;
			composite = new Composite(container, SWT.NONE);
		} else {
			if (isCollapsible) {
				ExpandableComposite expandableComposite = new ExpandableComposite(container, SWT.BOLD);
				expandableComposite.setText(label);
				expandableComposite.setFont(new Font(container.getDisplay(), "Sans", 8, SWT.BOLD));
				expandableComposite.setExpanded(isExpanded);
				GridData gridData = new GridData();
				gridData.horizontalSpan = columns;
				gridData.grabExcessHorizontalSpace = true;
				if (verticalIndent != null) {
					gridData.verticalIndent = verticalIndent;
					verticalIndent = null;
				}
				gridData.horizontalAlignment = SWT.FILL;
				expandableComposite.setLayoutData(gridData);
				composite = new Composite(expandableComposite, SWT.NONE);
				expandableComposite.setClient(composite);
				expandableComposite.addExpansionListener(new ExpansionAdapter() {

					public void expansionStateChanged(ExpansionEvent e) {
						layout(container);
					}
				});
			} else {
				composite = new Group(container, SWT.NONE);
				((Group) composite).setText(label);
			}
		}
		if (columns != -1) {
			GridData gridData = new GridData();
			gridData.horizontalSpan = columns;
			gridData.grabExcessHorizontalSpace = true;
			if (verticalIndent != null) {
				gridData.verticalIndent = verticalIndent;
			}
			if (horizontalIndent != null) {
				gridData.horizontalIndent = horizontalIndent;
			}
			gridData.horizontalAlignment = SWT.FILL;
			gridData.verticalIndent = 10;
			composite.setLayoutData(gridData);
		}
		return composite;
	}

	public static IFieldControlData createFileDirectoryBrowser(Composite container, final Shell shell,
	                                                           final String label, final String filter,
	                                                           boolean isTextReadonly, String fileButtonCaption,
	                                                           String dirButtonCaption, int columns,
	                                                           Integer verticalIndent, Integer horizontalIndent) {
		Label lblCaption = new Label(container, SWT.None);
		lblCaption.setText(label);
		GridData gridData = new GridData();
		if (verticalIndent != null) {
			gridData.verticalIndent = verticalIndent;
		}
		if (horizontalIndent != null) {
			gridData.horizontalIndent = horizontalIndent;
		}
		lblCaption.setLayoutData(gridData);
		final Text txtValue = new Text(container, SWT.BORDER);
		txtValue.setEditable(!isTextReadonly);
		if (columns != -1) {
			gridData = new GridData();
			gridData.horizontalSpan = columns - 3;
			gridData.grabExcessHorizontalSpace = true;
			gridData.horizontalAlignment = SWT.FILL;
			txtValue.setLayoutData(gridData);
		}
		Button btnFileBrowse = addFileBrowseButton(container, shell, label, filter, fileButtonCaption, txtValue);
		Button btnDirBrowse = addDirBrowseButton(container, shell, label, dirButtonCaption, txtValue);
		propagateControlStatus(txtValue, lblCaption, btnFileBrowse, btnDirBrowse);
		FileldControlTextDataImple feildControl = createFileBrowserFieldController(txtValue);
		return feildControl;
	}

	private static FileldControlTextDataImple createFileBrowserFieldController(final Text txtValue) {
		FileldControlTextDataImple feildControl = new FileldControlTextDataImple(txtValue) {

			//
			// public Text getControl() {
			// return (Text)super.getControl();
			// }

			public void setData(Object data) {
				if (data == null) {
					data = "";
				}
				getControl().setText(data.toString());

			}

			public Object getData() {
				return new File(getControl().getText());
			}
		};
		return feildControl;
	}

	public static Text createWorkspaceFileBrowser(Composite container, final Shell shell, final String label,
	                                              boolean isTextReadonly, String buttonCaption, int columns,
	                                              final ViewerFilter viewerFilter, Integer verticalIndent,
	                                              Integer horizontalIndent) {
		Label lblCaption = new Label(container, SWT.None);
		lblCaption.setText(label);
		GridData gridData = new GridData();
		if (verticalIndent != null) {
			gridData.verticalIndent = verticalIndent;
		}
		if (horizontalIndent != null) {
			gridData.horizontalIndent = horizontalIndent;
		}
		lblCaption.setLayoutData(gridData);
		final Text txtValue = new Text(container, SWT.BORDER);
		txtValue.setEditable(!isTextReadonly);
		if (columns != -1) {
			gridData = new GridData();
			gridData.horizontalSpan = columns - 2;
			gridData.grabExcessHorizontalSpace = true;
			gridData.horizontalAlignment = SWT.FILL;
			txtValue.setLayoutData(gridData);
		}
		Button btnFileBrowse = new Button(container, SWT.None);
		btnFileBrowse.setText(buttonCaption);
		btnFileBrowse.addSelectionListener(new SelectionListener() {

			public void widgetDefaultSelected(SelectionEvent event) {
				List<ViewerFilter> viewerFilters = null;
				if (viewerFilter == null) {
					viewerFilters = new ArrayList<ViewerFilter>();
				} else {
					viewerFilters = Arrays.asList(new ViewerFilter[] { viewerFilter });
				}
				IFile[] openFileSelection =
				                            WorkspaceResourceDialog.openFileSelection(shell, "Select file...", label,
				                                                                      false, new Object[] {},
				                                                                      viewerFilters);
				if (openFileSelection != null) {
					txtValue.setText(openFileSelection[0].getFullPath().toPortableString().substring(1));
				}
			}

			public void widgetSelected(SelectionEvent event) {
				widgetDefaultSelected(event);
			}
		});
		propagateControlStatus(txtValue, lblCaption, btnFileBrowse);
		return txtValue;
	}

	public static Text createWorkspaceFolderBrowser(Composite container, final Shell shell, final String label,
	                                                boolean isTextReadonly, String buttonCaption, int columns,
	                                                final ViewerFilter viewerFilter, Integer verticalIndent,
	                                                Integer horizontalIndent) {
		Label lblCaption = new Label(container, SWT.None);
		lblCaption.setText(label);
		GridData gridData = new GridData();
		if (verticalIndent != null) {
			gridData.verticalIndent = verticalIndent;
		}
		if (horizontalIndent != null) {
			gridData.horizontalIndent = horizontalIndent;
		}
		lblCaption.setLayoutData(gridData);
		final Text txtValue = new Text(container, SWT.BORDER);
		txtValue.setEditable(!isTextReadonly);
		if (columns != -1) {
			gridData = new GridData();
			gridData.horizontalSpan = columns - 2;
			gridData.grabExcessHorizontalSpace = true;
			gridData.horizontalAlignment = SWT.FILL;
			txtValue.setLayoutData(gridData);
		}
		Button btnFileBrowse = new Button(container, SWT.None);
		btnFileBrowse.setText(buttonCaption);
		btnFileBrowse.addSelectionListener(new SelectionListener() {

			public void widgetDefaultSelected(SelectionEvent event) {
				List<ViewerFilter> viewerFilters = null;
				if (viewerFilter == null) {
					viewerFilters = new ArrayList<ViewerFilter>();
				} else {
					viewerFilters = Arrays.asList(new ViewerFilter[] { viewerFilter });
				}
				IContainer[] openFolderSelection =
				                                   WorkspaceResourceDialog.openFolderSelection(shell,
				                                                                            "Select folder...",
				                                                                            label, false,
				                                                                            new Object[] {},
				                                                                            viewerFilters);
				if (openFolderSelection != null && openFolderSelection.length != 0) {
					txtValue.setText(openFolderSelection[0].getFullPath().toPortableString().substring(1));
				}
			}

			public void widgetSelected(SelectionEvent event) {
				widgetDefaultSelected(event);
			}
		});
		propagateControlStatus(txtValue, lblCaption, btnFileBrowse);
		return txtValue;
	}

	public static Text createWorkspaceBrowser(Composite container, final Shell shell, final String label,
	                                          boolean isTextReadonly, String buttonCaption, int columns,
	                                          final ViewerFilter viewerFilter, Integer verticalIndent,
	                                          Integer horizontalIndent) {
		Label lblCaption = new Label(container, SWT.None);
		lblCaption.setText(label);
		GridData gridData = new GridData();
		if (verticalIndent != null) {
			gridData.verticalIndent = verticalIndent;
		}
		if (horizontalIndent != null) {
			gridData.horizontalIndent = horizontalIndent;
		}
		lblCaption.setLayoutData(gridData);
		final Text txtValue = new Text(container, SWT.BORDER);
		txtValue.setEditable(!isTextReadonly);
		if (columns != -1) {
			gridData = new GridData();
			gridData.horizontalSpan = columns - 2;
			gridData.grabExcessHorizontalSpace = true;
			gridData.horizontalAlignment = SWT.FILL;
			txtValue.setLayoutData(gridData);
		}
		Button btnFileBrowse = new Button(container, SWT.None);
		btnFileBrowse.setText(buttonCaption);
		btnFileBrowse.addSelectionListener(new SelectionListener() {

			public void widgetDefaultSelected(SelectionEvent event) {
				// TODO
			}

			public void widgetSelected(SelectionEvent event) {
				widgetDefaultSelected(event);
			}
		});
		propagateControlStatus(txtValue, lblCaption, btnFileBrowse);
		return txtValue;
	}

	public static Text createWorkspacePathBrowser(Composite container, final Shell shell,
	        final String label, boolean isTextReadonly, String buttonCaption, int columns,
	        final ViewerFilter viewerFilter, Integer verticalIndent, Integer horizontalIndent) {

		Label lblCaption = new Label(container, SWT.None);
		lblCaption.setText(label);
		GridData gridData = new GridData();
		if (verticalIndent != null) {
			gridData.verticalIndent = verticalIndent;
		}
		if (horizontalIndent != null) {
			gridData.horizontalIndent = horizontalIndent;
		}
		lblCaption.setLayoutData(gridData);
		final Text txtValue = new Text(container, SWT.BORDER);
		txtValue.setEditable(!isTextReadonly);
		if (columns != -1) {
			gridData = new GridData();
			gridData.horizontalSpan = columns - 2;
			gridData.grabExcessHorizontalSpace = true;
			gridData.horizontalAlignment = SWT.FILL;
			txtValue.setLayoutData(gridData);
		}
		Button btnFileBrowse = new Button(container, SWT.None);
		btnFileBrowse.setText(buttonCaption);
		btnFileBrowse.addSelectionListener(new SelectionListener() {

			public void widgetDefaultSelected(SelectionEvent event) {
				List<ViewerFilter> viewerFilters = null;
				if (viewerFilter == null) {
					viewerFilters = new ArrayList<ViewerFilter>();
				} else {
					viewerFilters = Arrays.asList(new ViewerFilter[] { viewerFilter });
				}

				Map<String,List<String>> filters = new HashMap<String,List<String>>();
				DeveloperStudioRegistryResourceProviderDialog dialog = new DeveloperStudioRegistryResourceProviderDialog(shell, new Class[]{IDeveloperStudioElement.class},filters);
				dialog.create();
				dialog.getShell().setText("Copy deploy path from existing resource");
				dialog.open();
				String selectedPath = dialog.getSelectedPath();
              	if (selectedPath != null && !selectedPath.isEmpty()) {
              		int lastIndexOfSlash = selectedPath.lastIndexOf("/");
              		selectedPath = selectedPath.substring(0, lastIndexOfSlash);
              		if(selectedPath.startsWith("/_system/governance/")) {
              			selectedPath = selectedPath.substring("/_system/governance/".length());
              		}
              		else if(selectedPath.startsWith("/_system/config/")) {
              			selectedPath = selectedPath.substring("/_system/config/".length());
              		}
					txtValue.setText(selectedPath);
				}
			}

			public void widgetSelected(SelectionEvent event) {
				widgetDefaultSelected(event);
			}
		});
		propagateControlStatus(txtValue, lblCaption, btnFileBrowse);
		return txtValue;
	}

	public static IFieldControlData createFileBrowser(Composite container, final Shell shell, final String label,
	                                                  final String filter, boolean isTextReadonly,
	                                                  String buttonCaption, int columns, Integer verticalIndent,
	                                                  Integer horizontalIndent) {
		Label lblCaption = new Label(container, SWT.None);
		lblCaption.setText(label);
		GridData gridData = new GridData();
		if (verticalIndent != null) {
			gridData.verticalIndent = verticalIndent;
		}
		if (horizontalIndent != null) {
			gridData.horizontalIndent = horizontalIndent;
		}
		lblCaption.setLayoutData(gridData);
		final Text txtValue = new Text(container, SWT.BORDER);
		txtValue.setEditable(!isTextReadonly);
		if (columns != -1) {
			gridData = new GridData();
			gridData.horizontalSpan = columns - 2;
			gridData.grabExcessHorizontalSpace = true;
			gridData.horizontalAlignment = SWT.FILL;
			txtValue.setLayoutData(gridData);
		}
		Button btnFileBrowse = addFileBrowseButton(container, shell, label, filter, buttonCaption, txtValue);
		propagateControlStatus(txtValue, lblCaption, btnFileBrowse);
		FieldControlDataImpl feildControl = createFileBrowserFieldController(txtValue);
		return feildControl;
	}

	private static Button addFileBrowseButton(Composite container, final Shell shell, final String label,
	                                          final String filter, String buttonCaption, final Text txtValue) {
		Button btnFileBrowse = new Button(container, SWT.None);
		btnFileBrowse.setText(buttonCaption);
		btnFileBrowse.addSelectionListener(new SelectionListener() {

			public void widgetDefaultSelected(SelectionEvent event) {
				FileDialog fileDialog = new FileDialog(shell);
				fileDialog.setFilterExtensions(filter.split(","));
				// fileDialog.setFilterPath(txtValue.getText());
				fileDialog.setText(label);
				if (fileDialog.open() != null) {
					String fileName = new File(fileDialog.getFilterPath(), fileDialog.getFileName()).toString();
					txtValue.setText(fileName);
				}
			}

			public void widgetSelected(SelectionEvent event) {
				widgetDefaultSelected(event);
			}
		});
		return btnFileBrowse;
	}

	public static IFieldControlData createDirectoryBrowser(Composite container, final Shell shell, final String label,
	                                                       boolean isTextReadonly, String buttonCaption, int columns,
	                                                       Integer verticalIndent, Integer horizontalIndent) {
		Label lblCaption = new Label(container, SWT.None);
		lblCaption.setText(label);
		GridData gridData = new GridData();
		if (verticalIndent != null) {
			gridData.verticalIndent = verticalIndent;
		}
		if (horizontalIndent != null) {
			gridData.horizontalIndent = horizontalIndent;
		}
		lblCaption.setLayoutData(gridData);
		final Text txtValue = new Text(container, SWT.BORDER);
		txtValue.setEditable(!isTextReadonly);
		if (columns != -1) {
			gridData = new GridData();
			gridData.horizontalSpan = columns - 2;
			gridData.grabExcessHorizontalSpace = true;
			gridData.horizontalAlignment = SWT.FILL;
			txtValue.setLayoutData(gridData);
		}
		Button btnDirBrowse = addDirBrowseButton(container, shell, label, buttonCaption, txtValue);
		propagateControlStatus(txtValue, lblCaption, btnDirBrowse);
		FieldControlDataImpl feildControl = createFileBrowserFieldController(txtValue);
		return feildControl;
	}

	private static Button addDirBrowseButton(Composite container, final Shell shell, final String label,
	                                         String buttonCaption, final Text txtValue) {
		Button btnDirBrowse = new Button(container, SWT.None);
		btnDirBrowse.setText(buttonCaption);
		btnDirBrowse.addSelectionListener(new SelectionListener() {

			public void widgetDefaultSelected(SelectionEvent event) {
				DirectoryDialog dirDialog = new DirectoryDialog(shell);
				// dirDialog.setFilterPath(txtValue.getText());
				dirDialog.setText(label);
				String path = dirDialog.open();
				if (path != null) {
					// String fileName = new File(dirDialog.getFilterPath(),
					// path).toString();
					txtValue.setText(path);
				}
			}

			public void widgetSelected(SelectionEvent event) {
				widgetDefaultSelected(event);
			}
		});
		return btnDirBrowse;
	}

	public static void propagateControlStatus(Control watchControl, Control... controls) {
		propagateEnability(watchControl, controls);
		propagateVisibility(watchControl, controls);
	}

	private static void propagateEnability(final Control watchControl, final Control... controls) {
		watchControl.addPaintListener(new PaintListener() {

			public void paintControl(PaintEvent event) {
				for (Control control : controls) {
					control.setEnabled(watchControl.getEnabled());
				}
			}
		});
	}

	private static Map<Control, Control[]> visibilityControls = new HashMap<Control, Control[]>();

	public static void updateControlVisibilityStatus(Control watchControl) {
		if (visibilityControls.containsKey(watchControl)) {
			Control[] controls = visibilityControls.get(watchControl);
			if (watchControl.isDisposed()) {
				visibilityControls.remove(watchControl);
			} else {
				boolean visibleField = watchControl.getVisible();
				for (Control control : controls) {
					Object layoutData = control.getLayoutData();
					if (layoutData == null) {
						layoutData = new GridData();
					}
					if (layoutData instanceof GridData) {
						((GridData) layoutData).exclude = !visibleField;
						control.setLayoutData(layoutData);
					}
					control.setVisible(visibleField);
				}
				layout(watchControl.getParent());
			}
		}
	}

	private static void propagateVisibility(final Control watchControl, final Control... controls) {
		visibilityControls.put(watchControl, controls);
		watchControl.addDisposeListener(new DisposeListener() {

			public void widgetDisposed(DisposeEvent arg0) {
				visibilityControls.remove(watchControl);
			}
		});
	}

	public static void layout(final Composite container) {
		Composite parentLayout = container;
		while (parentLayout != null) {
			parentLayout.layout();
			parentLayout = parentLayout.getParent();
		}
	}

	private static abstract class FileldControlTextDataImple extends FieldControlDataImpl {

		public FileldControlTextDataImple(Control control) {
			super(control);
		}

		public Text getControl() {
			return (Text) super.getControl();
		}

		public void setOnAction(IOnAction action) {
			super.setOnAction(action);
			getControl().addModifyListener(new ModifyListener() {

				public void modifyText(ModifyEvent arg0) {
					getOnAction().onModifyAction();

				}

			});
		}

	}

	private static abstract class FieldControlDataImpl implements IFieldControlData {
		private Control control = null;
		private IOnAction onAction;

		public void setOnAction(IOnAction action) {
			this.onAction = action;
		}

		public IOnAction getOnAction() {
			return onAction;
		}

		public FieldControlDataImpl(Control control) {
			this.setControl(control);
		}

		public Control getControl() {
			return control;
		}

		public void setControl(Control control) {
			this.control = control;
		}

	}
}


text:
package com.github.pockethub.accounts;

import android.accounts.Account;
import android.accounts.AccountManager;
import android.accounts.AccountManagerFuture;
import android.accounts.AccountsException;
import android.accounts.AuthenticatorDescription;
import android.accounts.AuthenticatorException;
import android.accounts.OperationCanceledException;
import android.app.Activity;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnCancelListener;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.text.TextUtils;
import android.util.Log;

import com.afollestad.materialdialogs.DialogAction;
import com.afollestad.materialdialogs.MaterialDialog;
import com.alorma.github.sdk.bean.dto.response.Organization;
import com.alorma.github.sdk.bean.dto.response.User;
import com.github.pockethub.R;
import com.squareup.okhttp.internal.http.RequestException;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;

import static android.accounts.AccountManager.KEY_ACCOUNT_NAME;
import static android.util.Log.DEBUG;
import static com.github.pockethub.accounts.AccountConstants.ACCOUNT_TYPE;
import static java.net.HttpURLConnection.HTTP_UNAUTHORIZED;

/**
 * Helpers for accessing {@link AccountManager}
 */
public class AccountUtils {

    private static final String TAG = "AccountUtils";

    private static boolean AUTHENTICATOR_CHECKED;

    private static boolean HAS_AUTHENTICATOR;

    private static final AtomicInteger UPDATE_COUNT = new AtomicInteger(0);

    private static class AuthenticatorConflictException extends IOException {

        private static final long serialVersionUID = 641279204734869183L;
    }

    /**
     * Verify authenticator registered for account type matches the package name
     * of this application
     *
     * @param manager
     * @return true is authenticator registered, false otherwise
     */
    public static boolean hasAuthenticator(final AccountManager manager) {
        if (!AUTHENTICATOR_CHECKED) {
            final AuthenticatorDescription[] types = manager
                    .getAuthenticatorTypes();
            if (types != null && types.length > 0)
                for (AuthenticatorDescription descriptor : types)
                    if (descriptor != null
                            && ACCOUNT_TYPE.equals(descriptor.type)) {
                        HAS_AUTHENTICATOR = "com.github.pockethub"
                                .equals(descriptor.packageName);
                        break;
                    }
            AUTHENTICATOR_CHECKED = true;
        }

        return HAS_AUTHENTICATOR;
    }

    /**
     * Is the given user the owner of the default account?
     *
     * @param context
     * @param user
     * @return true if default account user, false otherwise
     */
    public static boolean isUser(final Context context, final User user) {
        if (user == null)
            return false;

        String login = user.login;
        if (login == null)
            return false;

        return login.equals(getLogin(context));
    }

    /**
     * Is the given user the owner of the default account?
     *
     * @param context
     * @param user
     * @return true if default account user, false otherwise
     */
    public static boolean isUser(final Context context, final Organization user) {
        if (user == null)
            return false;

        String login = user.login;
        if (login == null)
            return false;

        return login.equals(getLogin(context));
    }

    /**
     * Get login name of configured account
     *
     * @param context
     * @return login name or null if none configure
     */
    public static String getLogin(final Context context) {
        final Account account = getAccount(context);
        return account != null ? account.name : null;
    }

    /**
     * Get configured account
     *
     * @param context
     * @return account or null if none
     */
    public static Account getAccount(final Context context) {
        final Account[] accounts = AccountManager.get(context)
                .getAccountsByType(ACCOUNT_TYPE);
        return accounts.length > 0 ? accounts[0] : null;
    }

    private static Account[] getAccounts(final AccountManager manager)
            throws OperationCanceledException, AuthenticatorException,
            IOException {
        final AccountManagerFuture<Account[]> future = manager
                .getAccountsByTypeAndFeatures(ACCOUNT_TYPE, null, null, null);
        final Account[] accounts = future.getResult();
        if (accounts != null && accounts.length > 0)
            return getPasswordAccessibleAccounts(manager, accounts);
        else
            return new Account[0];
    }

    /**
     * Get default account where password can be retrieved
     *
     * @param context
     * @return password accessible account or null if none
     */
    public static Account getPasswordAccessibleAccount(final Context context) {
        AccountManager manager = AccountManager.get(context);
        Account[] accounts = manager.getAccountsByType(ACCOUNT_TYPE);
        if (accounts == null || accounts.length == 0)
            return null;

        try {
            accounts = getPasswordAccessibleAccounts(manager, accounts);
        } catch (AuthenticatorConflictException e) {
            return null;
        }
        return accounts != null && accounts.length > 0 ? accounts[0] : null;
    }

    private static Account[] getPasswordAccessibleAccounts(
            final AccountManager manager, final Account[] candidates)
            throws AuthenticatorConflictException {
        final List<Account> accessible = new ArrayList<>(
                candidates.length);
        boolean exceptionThrown = false;
        for (Account account : candidates)
            try {
                manager.getPassword(account);
                accessible.add(account);
            } catch (SecurityException ignored) {
                exceptionThrown = true;
            }
        if (accessible.isEmpty() && exceptionThrown)
            throw new AuthenticatorConflictException();
        return accessible.toArray(new Account[accessible.size()]);
    }

    /**
     * Get account used for authentication
     *
     * @param manager
     * @param activity
     * @return account
     * @throws IOException
     * @throws AccountsException
     */
    public static Account getAccount(final AccountManager manager,
            final Activity activity) throws IOException, AccountsException {
        final boolean loggable = Log.isLoggable(TAG, DEBUG);
        if (loggable)
            Log.d(TAG, "Getting account");

        if (activity == null)
            throw new IllegalArgumentException("Activity cannot be null");

        if (activity.isFinishing())
            throw new OperationCanceledException();

        Account[] accounts;
        try {
            if (!hasAuthenticator(manager))
                throw new AuthenticatorConflictException();

            while ((accounts = getAccounts(manager)).length == 0) {
                if (loggable)
                    Log.d(TAG, "No GitHub accounts for activity=" + activity);

                Bundle result = manager.addAccount(ACCOUNT_TYPE, null, null,
                        null, activity, null, null).getResult();

                if (loggable)
                    Log.d(TAG,
                            "Added account "
                                    + result.getString(KEY_ACCOUNT_NAME));
            }
        } catch (OperationCanceledException e) {
            Log.d(TAG, "Excepting retrieving account", e);
            activity.finish();
            throw e;
        } catch (AccountsException e) {
            Log.d(TAG, "Excepting retrieving account", e);
            throw e;
        } catch (AuthenticatorConflictException e) {
            activity.runOnUiThread(new Runnable() {

                public void run() {
                    showConflictMessage(activity);
                }
            });
            throw e;
        } catch (IOException e) {
            Log.d(TAG, "Excepting retrieving account", e);
            throw e;
        }

        if (loggable)
            Log.d(TAG, "Returning account " + accounts[0].name);

        return accounts[0];
    }

    /**
     * Update account
     *
     * @param account
     * @param activity
     * @return true if account was updated, false otherwise
     */
    public static boolean updateAccount(final Account account,
            final Activity activity) {
        int count = UPDATE_COUNT.get();
        synchronized (UPDATE_COUNT) {
            // Don't update the account if the account was successfully updated
            // while the lock was being waited for
            if (count != UPDATE_COUNT.get())
                return true;

            AccountManager manager = AccountManager.get(activity);
            try {
                if (!hasAuthenticator(manager))
                    throw new AuthenticatorConflictException();
                manager.updateCredentials(account, ACCOUNT_TYPE, null,
                        activity, null, null).getResult();
                UPDATE_COUNT.incrementAndGet();
                return true;
            } catch (OperationCanceledException e) {
                Log.d(TAG, "Excepting retrieving account", e);
                activity.finish();
                return false;
            } catch (AccountsException e) {
                Log.d(TAG, "Excepting retrieving account", e);
                return false;
            } catch (AuthenticatorConflictException e) {
                activity.runOnUiThread(new Runnable() {

                    public void run() {
                        showConflictMessage(activity);
                    }
                });
                return false;
            } catch (IOException e) {
                Log.d(TAG, "Excepting retrieving account", e);
                return false;
            }
        }
    }

    /**
     * Show conflict message about previously registered authenticator from
     * another application
     *
     * @param activity
     */
    private static void showConflictMessage(final Activity activity) {
        new MaterialDialog.Builder(activity)
                .title(R.string.authenticator_conflict_title)
                .content(R.string.authenticator_conflict_message)
                .positiveText(android.R.string.ok)
                .cancelListener(new OnCancelListener() {
                    @Override
                    public void onCancel(DialogInterface dialog) {
                        activity.finish();
                    }
                })
                .onPositive(new MaterialDialog.SingleButtonCallback() {
                    @Override
                    public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                        activity.finish();
                    }
                })
                .show();
    }

    /**
     * Is the given {@link Exception} due to a 401 Unauthorized API response?
     *
     * @param e
     * @return true if 401, false otherwise
     */
    public static boolean isUnauthorized(final Exception e) {
        String message = null;
        if (e instanceof IOException)
            message = e.getMessage();
        final Throwable cause = e.getCause();
        if (cause instanceof IOException) {
            String causeMessage = cause.getMessage();
            if (!TextUtils.isEmpty(causeMessage))
                message = causeMessage;
        }

        if (TextUtils.isEmpty(message))
            return false;

        if ("Received authentication challenge is null".equals(message))
            return true;
        return "No authentication challenges found".equals(message);

    }
}


text:
// Software License for MTL
//
// Copyright (c) 2007 The Trustees of Indiana University.
//               2008 Dresden University of Technology and the Trustees of Indiana University.
//               2010 SimuNova UG (haftungsbeschränkt), www.simunova.com.
// All rights reserved.
// Authors: Peter Gottschling and Andrew Lumsdaine
//
// This file is part of the Matrix Template Library
//
// See also license.mtl.txt in the distribution.

#ifndef MTL_IO_PATH_INCLUDE
#define MTL_IO_PATH_INCLUDE

namespace mtl { namespace io {

#if defined(_WIN32) || defined(__WIN32__) || defined(WIN32)
    const static char delim = '\\';
#else
    const static char delim = '/';
#endif

/// Join the directory and file
/** It concatenates both with the os-specific slash unless directory is empty, then only file is returned **/
std::string inline join(std::string directory, std::string file)
{
    return directory.empty() ? file : directory + delim + file;
}

/// Directory name in s that is everything before last slash
std::string inline directory_name(std::string s)
{
    for (int i= int(s.size()) - 1; i >= 0; i--)
	if (s[i] == delim)
	    return s.substr(0, i);
    return std::string();
}

/// File name in s that is everything after last slash
std::string inline file_name(std::string s)
{
    for (int i= int(s.size()) - 1; i >= 0; i--)
	if (s[i] == delim)
	    return s.substr(i + 1);
    return s;
}

}} // namespace mtl::io

#endif // MTL_IO_PATH_INCLUDE


text:
package org.winterblade.minecraft.harmony.crafting.events.wrappers;

import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import org.winterblade.minecraft.harmony.api.OperationException;
import org.winterblade.minecraft.harmony.common.ItemUtility;

public class ItemStackWrapper {
    private ItemStack itemStack;

    public ItemStackWrapper(ItemStack itemStack) {
        this.itemStack = itemStack;
    }

    /**
     * Sets the item's stack size to zero, destroying the item.
     */
    public ItemStackWrapper destroyItem() {
        itemStack.stackSize = 0;
        return this;
    }

    /**
     * Sets the item's stack size to one, returning the item.
     */
    public ItemStackWrapper returnItem() {
        itemStack.stackSize = 1;
        return this;
    }

    public ItemStackWrapper replaceItem(String id) throws OperationException {
        itemStack = ItemUtility.translateToItemStack(id);
        return this;
    }

    /**
     * Damages the item by 1
     */
    public ItemStackWrapper damageItem() {
        return damageItem(1);
    }

    /**
     * Damages the item by a given amount
     * @param by    The amount to damage it by
     */
    public ItemStackWrapper damageItem(int by) {
        itemStack.setItemDamage(itemStack.getItemDamage()+by);
        return this;
    }

    /**
     * Gets the item's metadata
     * @return  The metadata
     */
    public int getMetadata() {
        return itemStack.getMetadata();
    }

    /**
     * Gets the item's current damage
     * @return  The item's current damage value
     */
    public int getDamage() {
        return itemStack.getItemDamage();
    }

    /**
     * Gets the item's resource locator name
     * @return  The item's resource locator
     */
    public String getId() {
        return Item.REGISTRY.getNameForObject(itemStack.getItem()).toString();
    }

    /**
     * Returns the item stack itself
     * @return  The item stack we're wrapping.
     */
    public ItemStack getItemStack() {
        return itemStack;
    }
}