text:
package uk.joshiejack.penguinlib.tile.inventory;

import uk.joshiejack.penguinlib.network.PenguinNetwork;
import uk.joshiejack.penguinlib.network.packet.PacketSyncMembers;
import uk.joshiejack.penguinlib.network.packet.PacketSyncOffsets;
import uk.joshiejack.penguinlib.network.packet.PacketSurroundingsChanged;
import uk.joshiejack.penguinlib.util.helpers.generic.MathsHelper;
import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

public abstract class TileConnectable<T extends TileConnectable> extends TileSingleStack {
    private final int maxMembers;
    protected int members = 0;
    protected boolean facingEW; //If the master is "traveling along the x axis"
    protected int offsetX; //The offset from the master block
    protected int offsetZ; //The offset from the master block

    public TileConnectable(int maxMembers) {
        this.maxMembers = maxMembers;
    }

    @SuppressWarnings("unchecked")
    public T getMasterBlock() {
       // if (members > 0 || (offsetX == 0 && offsetZ == 0)) return (T) this;
        BlockPos pos = this.pos.add(offsetX, 0, offsetZ);
        TileEntity tile = world.getTileEntity(pos);
        return isSameTile(pos) ? (T) tile: (T) this;
    }

    public ItemStack getStack() {
        return handler.getStackInSlot(0);
    }

    protected abstract boolean isSameTile(BlockPos pos);

    private boolean setMaster(TileConnectable tile, EnumFacing facing) {
        boolean EW = facing == EnumFacing.WEST || facing == EnumFacing.EAST;
        if (tile.members < maxMembers && (tile.members == 0 || tile.facingEW == EW)) {
            //We found a match so let's update the master numbers
            tile.members++; //Increase by one
            tile.facingEW = EW; //Update the master's facing direction so they know!
            tile.markDirty();
            if (!world.isRemote) {
                PenguinNetwork.sendToNearby(tile, new PacketSyncMembers(tile.getPos(), tile.members));
            }

            this.offsetX = tile.pos.getX() - this.pos.getX();//facing.getFrontOffsetX();
            this.offsetZ = tile.pos.getZ() - this.pos.getZ();//facing.getFrontOffsetZ();
            if (!world.isRemote) {
                PenguinNetwork.sendToNearby(this, new PacketSyncOffsets(pos, this.offsetX, this.offsetZ));
            }

            this.markDirty();
            return true;
        }

        return false;
    }

    @SuppressWarnings("ConstantConditions")
    public void onBlockPlaced() {
        //Look for a block next to us, we need to check if that block is a master
        //If that block IS a master AND the master hasn't reached maximum members AND (members == 0 OR (facing == same way)
        //Then we have permission to ADD this block as counting this one as it's master
        //Which should update this block offsetX and offsetZ, and increase the length of the master
        for (EnumFacing facing: EnumFacing.HORIZONTALS) {
            BlockPos pos = this.pos.offset(facing);
            if (isSameTile(pos)) {
                if (setMaster(((TileConnectable) world.getTileEntity(pos)).getMasterBlock(), facing)) {//The block wasn't a master but a slave SO grab that slaves master
                    break;
                }
            }
        }

        onSurroundingsChanged();
    }

    public int getMembers() {
        return members;
    }

    @SideOnly(Side.CLIENT)
    public void setMembers(int members) {
        this.members = members;
    }

    @SideOnly(Side.CLIENT)
    public void setOffsets(int offsetX, int offsetZ) {
        this.offsetX = offsetX;
        this.offsetZ = offsetZ;
    }

    @Override
    public void dropInventory() {
        if (this == getMasterBlock()) {
            super.dropInventory();
        }
    }

    @SuppressWarnings("unchecked, ConstantConditions")
    @Nullable
    private T getNewMasterFrom(T oldMaster) {
        for (EnumFacing facing: EnumFacing.HORIZONTALS) {
            if (isSameTile(oldMaster.pos.offset(facing))) {
                T tile = (T) world.getTileEntity(oldMaster.pos.offset(facing));
                if (tile.getMasterBlock() == oldMaster) {
                    return tile;
                }
            }
        }
        return null;
    }

    private static final EnumFacing[] EW = new EnumFacing[] { EnumFacing.EAST, EnumFacing.WEST };
    private static final EnumFacing[] SN = new EnumFacing[] { EnumFacing.SOUTH, EnumFacing.NORTH };

    //This be the hard part?
    public void onBlockRemoved() {
        if (world.isRemote) return;
        //When a block is broken we need to do many things....
        //If this block wasn't a master block then we need to notify the master block itself
        //The master block needs to know that its surrounding have changed
        //First thing we'll check is if the master block has any blocks to the side of it, that have it as a master block
        //If this is not the case, then we need to search in the maximum radius on all sides for all blocks that are using this masterblock
        //With this information we should reset all of these tiles, so that they themselves are master blocks
        //We know that there will be one less member, so we need to split off from the master blocks inventory
        //The new size vs the old size of inventory
        T oldMaster = getMasterBlock();
        T newMaster = oldMaster == this ? getNewMasterFrom(oldMaster): oldMaster;

        ItemStack contents = oldMaster.getStack().copy();
        if (oldMaster != newMaster && newMaster != null) {
            newMaster.members = oldMaster.members;
            newMaster.facingEW = oldMaster.facingEW;
            newMaster.offsetX = 0;
            newMaster.offsetZ = 0;
            //We need to copy over all the data to the new master block
        } else newMaster = oldMaster;

        //We have one less member so let's make it so
        newMaster.members = MathsHelper.constrainToRangeInt(newMaster.members - 1, 0, maxMembers);
        //Now that we know how many members we have we can work out the stack leftover
        newMaster.handler.setStackInSlot(0, ItemStack.EMPTY);
        ItemStack leftovers = newMaster.handler.insertItem(0, contents, false);
        if (!leftovers.isEmpty()) {
            Block.spawnAsEntity(world, pos, leftovers);
        }

        //Everything is known, now we want to go and update all the slaves
        EnumFacing[] cardinals = newMaster.facingEW ? EW : SN;
        for (EnumFacing facing: cardinals) {
            for (int offset = 1; offset <= maxMembers; offset++) {
                updateMaster(newMaster.pos.offset(facing, offset), oldMaster, newMaster);
            }
        }

        newMaster.markDirty();
        PenguinNetwork.sendToNearby(newMaster, new PacketSyncMembers(newMaster.pos, newMaster.members));
        PenguinNetwork.sendToNearby(newMaster, new PacketSyncOffsets(newMaster.pos, newMaster.offsetX, newMaster.offsetZ));
        PenguinNetwork.sendToNearby(newMaster, new PacketSurroundingsChanged(newMaster.pos));
    }

    @SuppressWarnings("ConstantConditions, unchecked")
    private void updateMaster(BlockPos pos, T oldMaster, T newMaster) {
        if (isSameTile(pos)) {
            T multi = (T) world.getTileEntity(pos);
            if (multi.getMasterBlock() == oldMaster) {
                multi.offsetX = newMaster.pos.getX() - pos.getX();
                multi.offsetZ = newMaster.pos.getZ() - pos.getZ();
                multi.markDirty();
                PenguinNetwork.sendToNearby(multi, new PacketSyncOffsets(multi.pos, multi.offsetX, multi.offsetZ));
                PenguinNetwork.sendToNearby(multi, new PacketSurroundingsChanged(multi.pos));
            }
        }
    }

    public void onSurroundingsChanged() {
        if (!world.isRemote) {
            T master = getMasterBlock();
            PenguinNetwork.sendToNearby(master, new PacketSurroundingsChanged(master.pos));
        }
    }

    @Override
    public boolean onRightClicked(EntityPlayer player, EnumHand hand) {
        return getMasterBlock().onMasterClicked(player, hand);
    }

    protected abstract boolean onMasterClicked(EntityPlayer player, EnumHand hand);

    @Override
    public void readFromNBT(NBTTagCompound nbt) {
        super.readFromNBT(nbt);
        facingEW = nbt.getBoolean("FacingEW");
        offsetX = nbt.getInteger("OffsetX");
        offsetZ = nbt.getInteger("OffsetZ");
        members = nbt.getByte("Members");
    }

    @Override
    @Nonnull
    public NBTTagCompound writeToNBT(NBTTagCompound nbt) {
        nbt.setBoolean("FacingEW", facingEW);
        nbt.setInteger("OffsetX", offsetX);
        nbt.setInteger("OffsetZ", offsetZ);
        nbt.setByte("Members", (byte) members);
        return super.writeToNBT(nbt);
    }
}


text:
<?xml version="1.0" encoding="UTF-8"?>
<!-- Encoding Hint: 雀の往来 -->
<project>
 <property name="jnlp.title"    value="JST ComboBoxにSeparator挿入" />
 <property name="jnlp.Name"     value="ComboBoxSeparator" />
 <property name="jnlp.name"     value="comboboxseparator" />
 <property name="jnlp.codebase" value="http://ateraimemo.com/swing/${jnlp.name}/" />
 <property name="jnlp.homepage" value="http://ateraimemo.com/Swing/${jnlp.Name}.html" />
</project>

redpajama_set_name: RedPajamaGithub


text:
package org.pentaho.di.ui.trans.steps.wmiinput;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.FocusAdapter;
import org.eclipse.swt.events.FocusEvent;
import org.eclipse.swt.events.KeyAdapter;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.ShellAdapter;
import org.eclipse.swt.events.ShellEvent;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.pentaho.di.core.Const;
import org.pentaho.di.core.Props;
import org.pentaho.di.core.util.StringUtil;
import org.pentaho.di.i18n.BaseMessages;
import org.pentaho.di.trans.Trans;
import org.pentaho.di.trans.TransMeta;
import org.pentaho.di.trans.TransPreviewFactory;
import org.pentaho.di.trans.step.BaseStepMeta;
import org.pentaho.di.trans.step.StepDialogInterface;
import org.pentaho.di.trans.steps.wmiinput.WMIInputMeta;
import org.pentaho.di.ui.core.dialog.EnterNumberDialog;
import org.pentaho.di.ui.core.dialog.EnterTextDialog;
import org.pentaho.di.ui.core.dialog.PreviewRowsDialog;
import org.pentaho.di.ui.core.widget.ControlSpaceKeyAdapter;
import org.pentaho.di.ui.core.widget.StyledTextComp;
import org.pentaho.di.ui.core.widget.TextVar;
import org.pentaho.di.ui.trans.dialog.TransPreviewProgressDialog;
import org.pentaho.di.ui.trans.step.BaseStepDialog;
import org.pentaho.di.ui.trans.steps.tableinput.SQLValuesHighlight;

public class WMIInputDialog extends BaseStepDialog implements StepDialogInterface
{
	private static Class<?> PKG = WMIInputMeta.class; // for i18n purposes, needed by Translator2!!   $NON-NLS-1$

	private Label        wlWMI;
	private StyledTextComp         wWMI;
	private FormData     fdlWMI, fdWMI;

    private Label        wlVariables;
    private Button       wVariables;
    private FormData     fdlVariables, fdVariables;

	private WMIInputMeta input;

	private Label        wlPosition;
	private FormData     fdlPosition;

	private Label        wlLimit;
	private TextVar         wLimit;
	private FormData     fdlLimit, fdLimit;

	private Label        wlDomain;
	private TextVar         wDomain;
	private FormData     fdlDomain, fdDomain;

	private Label        wlHost;
	private TextVar         wHost;
	private FormData     fdlHost, fdHost;

	private Label        wlUserName;
	private TextVar         wUserName;
	private FormData     fdlUserName, fdUserName;

	private Label        wlPassword;
	private TextVar         wPassword;
	private FormData     fdlPassword, fdPassword;

	public WMIInputDialog(Shell parent, Object in, TransMeta transMeta, String sname)
	{
		super(parent, (BaseStepMeta)in, transMeta, sname);
		input=(WMIInputMeta)in;
	}

	public String open()
	{
		Shell parent = getParent();
		Display display = parent.getDisplay();

		shell = new Shell(parent, SWT.DIALOG_TRIM | SWT.RESIZE | SWT.MAX | SWT.MIN);
 		props.setLook(shell);
        setShellImage(shell, input);

		ModifyListener lsMod = new ModifyListener()
		{
			public void modifyText(ModifyEvent e)
			{
				input.setChanged();
			}
		};
		changed = input.hasChanged();

		FormLayout formLayout = new FormLayout ();
		formLayout.marginWidth  = Const.FORM_MARGIN;
		formLayout.marginHeight = Const.FORM_MARGIN;

		shell.setLayout(formLayout);
		shell.setText(BaseMessages.getString(PKG, "WMIInputDialog.WMIInput")); //$NON-NLS-1$

		int middle = props.getMiddlePct();
		int margin = Const.MARGIN;

        // Stepname line
		wlStepname=new Label(shell, SWT.RIGHT);
		wlStepname.setText(BaseMessages.getString(PKG, "WMIInputDialog.StepName")); //$NON-NLS-1$
 		props.setLook(wlStepname);
		fdlStepname=new FormData();
		fdlStepname.left = new FormAttachment(0, 0);
		fdlStepname.right= new FormAttachment(middle, -margin);
		fdlStepname.top  = new FormAttachment(0, margin);
		wlStepname.setLayoutData(fdlStepname);
		wStepname=new Text(shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
		wStepname.setText(stepname);
 		props.setLook(wStepname);
		wStepname.addModifyListener(lsMod);
		fdStepname=new FormData();
		fdStepname.left = new FormAttachment(middle, 0);
		fdStepname.top  = new FormAttachment(0, margin);
		fdStepname.right= new FormAttachment(100, 0);
		wStepname.setLayoutData(fdStepname);

		// Some buttons
		wOK=new Button(shell, SWT.PUSH);
		wOK.setText(BaseMessages.getString(PKG, "System.Button.OK")); //$NON-NLS-1$
        wPreview=new Button(shell, SWT.PUSH);
        wPreview.setText(BaseMessages.getString(PKG, "System.Button.Preview")); //$NON-NLS-1$
		wCancel=new Button(shell, SWT.PUSH);
		wCancel.setText(BaseMessages.getString(PKG, "System.Button.Cancel")); //$NON-NLS-1$

		setButtonPositions(new Button[] { wOK, wPreview, wCancel }, margin, null);

		// Password ...
		wlPassword=new Label(shell, SWT.RIGHT);
		wlPassword.setText(BaseMessages.getString(PKG, "WMIInputDialog.Password")); //$NON-NLS-1$
 		props.setLook(wlPassword);
		fdlPassword=new FormData();
		fdlPassword.left = new FormAttachment(0, 0);
		fdlPassword.right= new FormAttachment(middle, -margin);
		fdlPassword.bottom = new FormAttachment(wOK, -2*margin);
		wlPassword.setLayoutData(fdlPassword);
		wPassword=new TextVar(transMeta, shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
 		props.setLook(wPassword);
		wPassword.addModifyListener(lsMod);
		fdPassword=new FormData();
		fdPassword.left = new FormAttachment(middle, 0);
		fdPassword.right= new FormAttachment(100, 0);
		fdPassword.bottom = new FormAttachment(wOK, -2*margin);
		wPassword.setLayoutData(fdPassword);
	    wPassword.addModifyListener(
			 new ModifyListener()
			 {
				public void modifyText(ModifyEvent e)
				{
					input.setChanged();
					checkPasswordVisible(wPassword);
				}
		});

		// UserName ...
		wlUserName=new Label(shell, SWT.RIGHT);
		wlUserName.setText(BaseMessages.getString(PKG, "WMIInputDialog.UserName")); //$NON-NLS-1$
 		props.setLook(wlUserName);
		fdlUserName=new FormData();
		fdlUserName.left = new FormAttachment(0, 0);
		fdlUserName.right= new FormAttachment(middle, -margin);
		fdlUserName.bottom = new FormAttachment(wPassword, -margin);
		wlUserName.setLayoutData(fdlUserName);
		wUserName=new TextVar(transMeta, shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
 		props.setLook(wUserName);
		wUserName.addModifyListener(lsMod);
		fdUserName=new FormData();
		fdUserName.left = new FormAttachment(middle, 0);
		fdUserName.right= new FormAttachment(100, 0);
		fdUserName.bottom = new FormAttachment(wPassword, -margin);
		wUserName.setLayoutData(fdUserName);

		// Host ...
		wlHost=new Label(shell, SWT.RIGHT);
		wlHost.setText(BaseMessages.getString(PKG, "WMIInputDialog.Host")); //$NON-NLS-1$
 		props.setLook(wlHost);
		fdlHost=new FormData();
		fdlHost.left = new FormAttachment(0, 0);
		fdlHost.right= new FormAttachment(middle, -margin);
		fdlHost.bottom = new FormAttachment(wUserName, -margin);
		wlHost.setLayoutData(fdlHost);
		wHost=new TextVar(transMeta, shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
 		props.setLook(wHost);
		wHost.addModifyListener(lsMod);
		fdHost=new FormData();
		fdHost.left = new FormAttachment(middle, 0);
		fdHost.right= new FormAttachment(100, 0);
		fdHost.bottom = new FormAttachment(wUserName, -margin);
		wHost.setLayoutData(fdHost);

		// Domain input ...
		wlDomain=new Label(shell, SWT.RIGHT);
		wlDomain.setText(BaseMessages.getString(PKG, "WMIInputDialog.Domain")); //$NON-NLS-1$
 		props.setLook(wlDomain);
		fdlDomain=new FormData();
		fdlDomain.left = new FormAttachment(0, 0);
		fdlDomain.right= new FormAttachment(middle, -margin);
		fdlDomain.bottom = new FormAttachment(wHost, -margin);
		wlDomain.setLayoutData(fdlDomain);
		wDomain=new TextVar(transMeta, shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
 		props.setLook(wDomain);
		wDomain.addModifyListener(lsMod);
		fdDomain=new FormData();
		fdDomain.left = new FormAttachment(middle, 0);
		fdDomain.right= new FormAttachment(100, 0);
		fdDomain.bottom = new FormAttachment(wHost, -margin);
		wDomain.setLayoutData(fdDomain);

		// Limit input ...
		wlLimit=new Label(shell, SWT.RIGHT);
		wlLimit.setText(BaseMessages.getString(PKG, "WMIInputDialog.LimitSize")); //$NON-NLS-1$
 		props.setLook(wlLimit);
		fdlLimit=new FormData();
		fdlLimit.left = new FormAttachment(0, 0);
		fdlLimit.right= new FormAttachment(middle, -margin);
		fdlLimit.bottom = new FormAttachment(wDomain, -2*margin);
		wlLimit.setLayoutData(fdlLimit);
		wLimit=new TextVar(transMeta, shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
 		props.setLook(wLimit);
		wLimit.addModifyListener(lsMod);
		fdLimit=new FormData();
		fdLimit.left = new FormAttachment(middle, 0);
		fdLimit.right= new FormAttachment(100, 0);
		fdLimit.bottom = new FormAttachment(wDomain, -2*margin);
		wLimit.setLayoutData(fdLimit);

        // Variable?
        wlVariables = new Label(shell, SWT.RIGHT);
        wlVariables.setText(BaseMessages.getString(PKG, "WMIInputDialog.ReplaceVariables")); //$NON-NLS-1$
        props.setLook(wlVariables);
        fdlVariables = new FormData();
        fdlVariables.left = new FormAttachment(0, 0);
        fdlVariables.right = new FormAttachment(middle, -margin);
        fdlVariables.bottom = new FormAttachment(wLimit, -margin);
        wlVariables.setLayoutData(fdlVariables);
        wVariables = new Button(shell, SWT.CHECK);
        props.setLook(wVariables);
        fdVariables = new FormData();
        fdVariables.left = new FormAttachment(middle, 0);
        fdVariables.right = new FormAttachment(100, 0);
        fdVariables.bottom = new FormAttachment(wLimit, -margin);
        wVariables.setLayoutData(fdVariables);
        wVariables.addSelectionListener(
        		new SelectionAdapter() {
        			public void widgetSelected(SelectionEvent arg0) {
        				input.setChanged();
        				setWMIToolTip();
        				}
        			}
        		);

		wlPosition=new Label(shell, SWT.NONE);
		props.setLook(wlPosition);
		fdlPosition=new FormData();
		fdlPosition.left  = new FormAttachment(0,0);
		fdlPosition.right = new FormAttachment(100, 0);
		fdlPosition.bottom = new FormAttachment(wVariables, -margin);
		wlPosition.setLayoutData(fdlPosition);

		// Table line...
		wlWMI=new Label(shell, SWT.NONE);
		wlWMI.setText(BaseMessages.getString(PKG, "WMIInputDialog.WMI")); //$NON-NLS-1$
 		props.setLook(wlWMI);
		fdlWMI=new FormData();
		fdlWMI.left = new FormAttachment(0, 0);
		fdlWMI.top  = new FormAttachment(wStepname, margin*2);
		wlWMI.setLayoutData(fdlWMI);

		wWMI=new StyledTextComp(transMeta, shell, SWT.MULTI | SWT.LEFT | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL, "");
		props.setLook(wWMI, Props.WIDGET_STYLE_FIXED);
		fdWMI=new FormData();
		fdWMI.left  = new FormAttachment(0, 0);
		fdWMI.top   = new FormAttachment(wlWMI, margin );
		fdWMI.right = new FormAttachment(100, -2*margin);
		fdWMI.bottom= new FormAttachment(wlPosition, 0 );
		wWMI.setLayoutData(fdWMI);
		wWMI.addModifyListener(new ModifyListener()
            {
                public void modifyText(ModifyEvent arg0)
                {
                    setWMIToolTip();
                    setPosition();
                }

            }
        );

		wWMI.addKeyListener(new KeyAdapter(){
			public void keyPressed(KeyEvent e) { setPosition(); }
			public void keyReleased(KeyEvent e) { setPosition(); }
			}
		);
		wWMI.addFocusListener(new FocusAdapter(){
			public void focusGained(FocusEvent e) { setPosition(); }
			public void focusLost(FocusEvent e) { setPosition(); }
			}
		);
		wWMI.addMouseListener(new MouseAdapter(){
			public void mouseDoubleClick(MouseEvent e) { setPosition(); }
			public void mouseDown(MouseEvent e) { setPosition(); }
			public void mouseUp(MouseEvent e) { setPosition(); }
			}
		);
		wWMI.addModifyListener(lsMod);

		// Text Highlighting
		wWMI.addLineStyleListener(new SQLValuesHighlight());

        wWMI.addKeyListener(new ControlSpaceKeyAdapter(transMeta, wWMI));

		// Add listeners
		lsCancel   = new Listener() { public void handleEvent(Event e) { cancel();  } };
        lsPreview  = new Listener() { public void handleEvent(Event e) { preview(); } };
		lsOK       = new Listener() { public void handleEvent(Event e) { ok();      } };

		wCancel.addListener  (SWT.Selection, lsCancel);
        wPreview.addListener (SWT.Selection, lsPreview);
		wOK.addListener      (SWT.Selection, lsOK    );

		lsDef=new SelectionAdapter() { public void widgetDefaultSelected(SelectionEvent e) { ok(); } };

		wStepname.addSelectionListener( lsDef );
		wLimit.addSelectionListener( lsDef );

		// Detect X or ALT-F4 or something that kills this window...
		shell.addShellListener(	new ShellAdapter() { public void shellClosed(ShellEvent e) { cancel(); } } );

		getData();
		input.setChanged(changed);

		// Set the shell size, based upon previous time...
		setSize();

		shell.open();
		while (!shell.isDisposed())
		{
				if (!display.readAndDispatch()) display.sleep();
		}
		return stepname;
	}

	public void setPosition(){

		String scr = wWMI.getText();
		int linenr = wWMI.getLineAtOffset(wWMI.getCaretOffset())+1;
		int posnr  = wWMI.getCaretOffset();

		// Go back from position to last CR: how many positions?
		int colnr=0;
		while (posnr>0 && scr.charAt(posnr-1)!='\n' && scr.charAt(posnr-1)!='\r')
		{
			posnr--;
			colnr++;
		}
		wlPosition.setText(BaseMessages.getString(PKG, "WMIInputDialog.Position.Label",""+linenr,""+colnr));

	}
	protected void setWMIToolTip()
    {
       if (wVariables.getSelection())
       {
           wWMI.setToolTipText(transMeta.environmentSubstitute(wWMI.getText()));
       }
    }

    /**
	 * Copy information from the meta-data input to the dialog fields.
	 */
	public void getData()
	{
		if (input.getWMI() != null) wWMI.setText(input.getWMI());
		if (input.getDomain() != null) wDomain.setText(input.getDomain());
		if (input.getHost() != null) wHost.setText(input.getHost());
		if (input.getUserName() != null) wUserName.setText(input.getUserName());
		if (input.getPassword() != null) wPassword.setText(input.getPassword());

		wLimit.setText(Const.NVL(input.getRowLimit(), "0")); //$NON-NLS-1$

        wVariables.setSelection(input.isVariableReplacementActive());

		wStepname.selectAll();
        setWMIToolTip();
	}

	private void cancel()
	{
		stepname=null;
		input.setChanged(changed);
		dispose();
	}

    private void getInfo(WMIInputMeta meta, boolean preview)
    {
        meta.setWMIQuery(preview && !Const.isEmpty(wWMI.getSelectionText())?wWMI.getSelectionText():wWMI.getText());
        meta.setVariableReplacementActive(wVariables.getSelection());
        meta.setRowLimit( Const.NVL(wLimit.getText(), "0") );
        meta.setDomain(wDomain.getText());
        meta.setHost(wHost.getText());
        meta.setUserName(wUserName.getText());
        meta.setPassword(wPassword.getText());
    }

	private void ok()
	{
		  if(Const.isEmpty(wStepname.getText())) {
	 			MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR );
	 			mb.setMessage(BaseMessages.getString(PKG, "System.Error.StepNameMissing.Message"));
	 			mb.setText(BaseMessages.getString(PKG, "System.Error.StepNameMissing.Title"));
	 			mb.open();
	 			return;
	       }

		stepname = wStepname.getText(); // return value

        getInfo(input, false);

		dispose();
	}

	public void dispose()
	{
		super.dispose();
	}

    /**
     * Preview the data generated by this step.
     * This generates a transformation using this step & a dummy and previews it.
     *
     */
    private void preview()
    {
        // Create the table input reader step...
        WMIInputMeta oneMeta = new WMIInputMeta();
        getInfo(oneMeta, true);

        TransMeta previewMeta = TransPreviewFactory.generatePreviewTransformation(transMeta, oneMeta, wStepname.getText());

        EnterNumberDialog numberDialog = new EnterNumberDialog(shell, props.getDefaultPreviewSize(), BaseMessages.getString(PKG, "WMIInputDialog.EnterPreviewSize"), BaseMessages.getString(PKG, "WMIInputDialog.NumberOfRowsToPreview")); //$NON-NLS-1$ //$NON-NLS-2$
        int previewSize = numberDialog.open();
        if (previewSize>0)
        {
            TransPreviewProgressDialog progressDialog = new TransPreviewProgressDialog(shell, previewMeta, new String[] { wStepname.getText() }, new int[] { previewSize } );
            progressDialog.open();

            Trans trans = progressDialog.getTrans();
            String loggingText = progressDialog.getLoggingText();

            boolean error=false;
            List<Object[]> rows= null;
            if (!progressDialog.isCancelled())
            {
            	// Get previewed rows
            	rows=progressDialog.getPreviewRows(wStepname.getText());
                if (trans.getResult()!=null && trans.getResult().getNrErrors()>0 && rows.size()==0)
                {
                	error=true;
                	EnterTextDialog etd = new EnterTextDialog(shell, BaseMessages.getString(PKG, "System.Dialog.PreviewError.Title"),
                		BaseMessages.getString(PKG, "System.Dialog.PreviewError.Message"), loggingText, true );
                	etd.setReadOnly();
                	etd.open();
                }
            }

            if(!error) {
            	 PreviewRowsDialog prd =new PreviewRowsDialog(shell, transMeta, SWT.NONE, wStepname.getText(), progressDialog.getPreviewRowsMeta(wStepname.getText()), progressDialog.getPreviewRows(wStepname.getText()), loggingText);
                 prd.open();
            }
        }
    }

    public static final void checkPasswordVisible(TextVar control)
	   {
	       String password = control.getText();
	       java.util.List<String> list = new ArrayList<String>();
	       StringUtil.getUsedVariables(password, list, true);
	       // ONLY show the variable in clear text if there is ONE variable used
	       // Also, it has to be the only string in the field.
	       //

	       if (list.size() != 1)
	       {
	       	control.setEchoChar('*');
	       }
	       else
	       {
	       	String variableName = null;
	           if ((password.startsWith(StringUtil.UNIX_OPEN) && password.endsWith(StringUtil.UNIX_CLOSE)))
	           {
	           	//  ${VAR}
	           	//  012345
	           	//
	           	variableName = password.substring(StringUtil.UNIX_OPEN.length(), password.length()-StringUtil.UNIX_CLOSE.length());
	           }
	           if ((password.startsWith(StringUtil.WINDOWS_OPEN) && password.endsWith(StringUtil.WINDOWS_CLOSE)))
	           {
	           	//  %VAR%
	           	//  01234
	           	//
	           	variableName = password.substring(StringUtil.WINDOWS_OPEN.length(), password.length()-StringUtil.WINDOWS_CLOSE.length());
	           }

	           // If there is a variable name in there AND if it's defined in the system properties...
	           // Otherwise, we'll leave it alone.
	           //
	           /*if (variableName!=null && System.getProperty(variableName)!=null)
	           {
	           	control.setEchoChar('\0'); // Show it all...
	           }
	           else
	           {
	           	control.setEchoChar('*');
	           }*/
	           if(variableName!=null) {
	        	   control.setEchoChar('\0'); // Show it all...
	           }else {
	        	   control.setEchoChar('*');
	           }
	       }
	       control.setToolTipText("Password");
	   }

}


text:
from __future__ import annotations # isort:skip

import pytest ; pytest

#-----------------------------------------------------------------------------
# Imports
#-----------------------------------------------------------------------------

# Standard library imports
from types import MethodType

# Bokeh imports
from bokeh.core.properties import (
    Alias,
    AngleSpec,
    Either,
    Instance,
    Int,
    List,
    Nullable,
    NumberSpec,
    Override,
    String,
)
from bokeh.core.property.descriptors import DataSpecPropertyDescriptor, PropertyDescriptor
from bokeh.core.property.singletons import Intrinsic
from bokeh.core.property.vectorization import field, value

# Module under test
import bokeh.core.has_props as hp # isort:skip

#-----------------------------------------------------------------------------
# Setup
#-----------------------------------------------------------------------------

#-----------------------------------------------------------------------------
# General API
#-----------------------------------------------------------------------------

#-----------------------------------------------------------------------------
# Dev API
#-----------------------------------------------------------------------------

class Parent(hp.HasProps):
    int1 = Int(default=10)
    ds1 = NumberSpec(default=field("x"))
    lst1 = List(String)

    @property
    def foo_prop(self) -> int:
        return 110

    def foo_func(self) -> int:
        return 111

    @property
    def _foo_prop(self) -> int:
        return 1100

    def _foo_func(self) -> int:
        return 1110

class Child(Parent):
    int2 = Nullable(Int())
    str2 = String(default="foo")
    ds2 = NumberSpec(default=field("y"))
    lst2 = List(Int, default=[1,2,3])

    @property
    def str2_proxy(self):
        return self.str2
    @str2_proxy.setter
    def str2_proxy(self, value):
        self.str2 = value*2

class OverrideChild(Parent):
    int1 = Override(default=20)

class AliasedChild(Child):
    aliased_int1 = Alias("int1")
    aliased_int2 = Alias("int2")

def test_HasProps_getattr() -> None:
    p = Parent()

    assert getattr(p, "int1") == 10
    assert p.int1 == 10

    assert getattr(p, "foo_prop") == 110
    assert p.foo_prop == 110

    assert isinstance(getattr(p, "foo_func"), MethodType)
    assert isinstance(p.foo_func, MethodType)

    assert getattr(p, "foo_func")() == 111
    assert p.foo_func() == 111

    assert getattr(p, "_foo_prop") == 1100
    assert p._foo_prop == 1100

    assert isinstance(getattr(p, "_foo_func"), MethodType)
    assert isinstance(p._foo_func, MethodType)

    assert getattr(p, "_foo_func")() == 1110
    assert p._foo_func() == 1110

    with pytest.raises(AttributeError):
        getattr(p, "foo_prop2")
    with pytest.raises(AttributeError):
        p.foo_prop2

    with pytest.raises(AttributeError):
        getattr(p, "foo_func2")
    with pytest.raises(AttributeError):
        p.foo_func2

    with pytest.raises(AttributeError):
        getattr(p, "_foo_prop2")
    with pytest.raises(AttributeError):
        p._foo_prop2

    with pytest.raises(AttributeError):
        getattr(p, "_foo_func2")
    with pytest.raises(AttributeError):
        p._foo_func2

def test_HasProps_default_init() -> None:
    p = Parent()
    assert p.int1 == 10
    assert p.ds1 == field("x")
    assert p.lst1 == []

    c = Child()
    assert c.int1 == 10
    assert c.ds1 == field("x")
    assert c.lst1 == []
    assert c.int2 is None
    assert c.str2 == "foo"
    assert c.ds2 == field("y")
    assert c.lst2 == [1,2,3]

def test_HasProps_kw_init() -> None:
    p = Parent(int1=30, ds1=field("foo"))
    assert p.int1 == 30
    assert p.ds1 == field("foo")
    assert p.lst1 == []

    c = Child(str2="bar", lst2=[2,3,4], ds2=10)
    assert c.int1 == 10
    assert c.ds1 == field("x")
    assert c.lst1 == []
    assert c.int2 is None
    assert c.str2 == "bar"
    assert c.ds2 == 10
    assert c.lst2 == [2,3,4]

def test_HasProps_override() -> None:
    ov = OverrideChild()
    assert ov.int1 == 20
    assert ov.ds1 == field("x")
    assert ov.lst1 == []

def test_HasProps_intrinsic() -> None:
    obj0 = Parent(int1=Intrinsic, ds1=Intrinsic, lst1=Intrinsic)

    assert obj0.int1 == 10
    assert obj0.ds1 == field("x")
    assert obj0.lst1 == []

    obj1 = Parent(int1=30, ds1=field("y"), lst1=["x", "y", "z"])

    assert obj1.int1 == 30
    assert obj1.ds1 == field("y")
    assert obj1.lst1 == ["x", "y", "z"]

    obj1.int1 = Intrinsic
    obj1.ds1 = Intrinsic
    obj1.lst1 = Intrinsic

    assert obj1.int1 == 10
    assert obj1.ds1 == field("x")
    assert obj1.lst1 == []

def test_HasProps_alias() -> None:
    obj0 = AliasedChild()
    assert obj0.int1 == 10
    assert obj0.int2 is None
    assert obj0.aliased_int1 == 10
    assert obj0.aliased_int2 is None
    obj0.int1 = 20
    assert obj0.int1 == 20
    assert obj0.int2 is None
    assert obj0.aliased_int1 == 20
    assert obj0.aliased_int2 is None
    obj0.int2 = 1
    assert obj0.int1 == 20
    assert obj0.int2 == 1
    assert obj0.aliased_int1 == 20
    assert obj0.aliased_int2 == 1
    obj0.aliased_int1 = 30
    assert obj0.int1 == 30
    assert obj0.int2 == 1
    assert obj0.aliased_int1 == 30
    assert obj0.aliased_int2 == 1
    obj0.aliased_int2 = 2
    assert obj0.int1 == 30
    assert obj0.int2 == 2
    assert obj0.aliased_int1 == 30
    assert obj0.aliased_int2 == 2

    obj1 = AliasedChild(int1=20)
    assert obj1.int1 == 20
    assert obj1.int2 is None
    assert obj1.aliased_int1 == 20
    assert obj1.aliased_int2 is None

    obj2 = AliasedChild(int2=1)
    assert obj2.int1 == 10
    assert obj2.int2 == 1
    assert obj2.aliased_int1 == 10
    assert obj2.aliased_int2 == 1

    obj3 = AliasedChild(int1=20, int2=1)
    assert obj3.int1 == 20
    assert obj3.int2 == 1
    assert obj3.aliased_int1 == 20
    assert obj3.aliased_int2 == 1

    obj4 = AliasedChild(aliased_int1=20)
    assert obj4.int1 == 20
    assert obj4.int2 is None
    assert obj4.aliased_int1 == 20
    assert obj4.aliased_int2 is None

    obj5 = AliasedChild(aliased_int2=1)
    assert obj5.int1 == 10
    assert obj5.int2 == 1
    assert obj5.aliased_int1 == 10
    assert obj5.aliased_int2 == 1

    obj6 = AliasedChild(aliased_int1=20, aliased_int2=1)
    assert obj6.int1 == 20
    assert obj6.int2 == 1
    assert obj6.aliased_int1 == 20
    assert obj6.aliased_int2 == 1

def test_HasProps_equals() -> None:
    p1 = Parent()
    p2 = Parent()
    assert p1.equals(p2)
    p1.int1 = 25
    assert not p1.equals(p2)
    p2.int1 = 25
    assert p1.equals(p2)

def test_HasProps_update() -> None:
    c = Child()
    c.update(**dict(lst2=[1,2], str2="baz", int1=25, ds1=value(123)))
    assert c.int1 == 25
    assert c.ds1 == value(123)
    assert c.lst1 == []
    assert c.int2 is None
    assert c.str2 == "baz"
    assert c.ds2 == field("y")
    assert c.lst2 == [1,2]

def test_HasProps_set_from_json() -> None:
    c = Child()
    c.set_from_json('lst2', [1,2])
    assert c.int1 == 10
    assert c.ds1 == field("x")
    assert c.lst1 == []
    assert c.int2 is None
    assert c.str2 == "foo"
    assert c.ds2 == field("y")
    assert c.lst2 == [1,2]

    c.set_from_json('ds1', "foo")
    assert c.int1 == 10
    assert c.ds1 == "foo"
    assert c.lst1 == []
    assert c.int2 is None
    assert c.str2 == "foo"
    assert c.ds2 == field("y")
    assert c.lst2 == [1,2]

    c.set_from_json('int2', 100)
    assert c.int1 == 10
    assert c.ds1 == "foo"
    assert c.lst1 == []
    assert c.int2 == 100
    assert c.str2 == "foo"
    assert c.ds2 == field("y")
    assert c.lst2 == [1,2]

def test_HasProps_set() -> None:
    c = Child()
    c.update(**dict(lst2=[1,2], str2="baz", int1=25, ds1=field("foo")))
    assert c.int1 == 25
    assert c.ds1 == field("foo")
    assert c.lst1 == []
    assert c.int2 is None
    assert c.str2 == "baz"
    assert c.ds2 == field("y")
    assert c.lst2 == [1,2]

    c.str2_proxy = "some"
    assert c.str2 == "somesome"
    assert c.str2_proxy == "somesome"

def test_HasProps_set_error() -> None:
    c = Child()
    with pytest.raises(AttributeError) as e:
        c.int3 = 10
    assert str(e.value).endswith("unexpected attribute 'int3' to Child, similar attributes are int2 or int1")
    with pytest.raises(AttributeError) as e:
        c.junkjunk = 10
    assert str(e.value).endswith("unexpected attribute 'junkjunk' to Child, possible attributes are ds1, ds2, int1, int2, lst1, lst2 or str2")

def test_HasProps_lookup() -> None:
    p = Parent()
    d = p.lookup('int1')
    assert isinstance(d, PropertyDescriptor)
    assert d.name == 'int1'
    d = p.lookup('ds1')
    assert isinstance(d, DataSpecPropertyDescriptor)
    assert d.name == 'ds1'
    d = p.lookup('lst1')
    assert isinstance(d, PropertyDescriptor)
    assert d.name == 'lst1'

def test_HasProps_apply_theme() -> None:
    c = Child()
    theme = dict(int2=10, lst1=["foo", "bar"])
    c.apply_theme(theme)
    assert c.themed_values() is theme
    c.apply_theme(theme)
    assert c.themed_values() is theme

    assert c.int2 == 10
    assert c.lst1 == ["foo", "bar"]

    assert c.int1 == 10
    assert c.ds1 == field("x")
    assert c.str2 == "foo"
    assert c.ds2 == field("y")
    assert c.lst2 == [1,2,3]

    c.int2 = 25
    assert c.int2 == 25
    assert c.lst1 == ["foo", "bar"]

    assert c.int1 == 10
    assert c.ds1 == field("x")
    assert c.str2 == "foo"
    assert c.ds2 == field("y")
    assert c.lst2 == [1,2,3]

    c.ds2 = "foo"
    assert c.int2 == 25
    assert c.lst1 == ["foo", "bar"]

    assert c.int1 == 10
    assert c.ds1 == field("x")
    assert c.str2 == "foo"
    assert c.ds2 == "foo"
    assert c.lst2 == [1,2,3]

def test_HasProps_unapply_theme() -> None:
    c = Child()
    theme = dict(int2=10, lst1=["foo", "bar"])
    c.apply_theme(theme)
    assert c.int2 == 10
    assert c.lst1 == ["foo", "bar"]

    assert c.int1 == 10
    assert c.ds1 == field("x")
    assert c.str2 == "foo"
    assert c.ds2 == field("y")
    assert c.lst2 == [1,2,3]

    c.unapply_theme()
    assert c.int2 is None
    assert c.lst1 == []

    assert c.int1 == 10
    assert c.ds1 == field("x")
    assert c.str2 == "foo"
    assert c.ds2 == field("y")
    assert c.lst2 == [1,2,3]

    assert c.themed_values() is None

class EitherSimpleDefault(hp.HasProps):
    foo = Either(List(Int), Int, default=10)

def test_HasProps_apply_theme_either_simple() -> None:

    # check applying multiple themes
    c = EitherSimpleDefault()
    assert c.foo == 10

    theme = dict(foo=20)
    c.apply_theme(theme)
    assert c.foo == 20

    theme = dict(foo=30)
    c.apply_theme(theme)
    assert c.foo == 30

    # check user set before theme
    c = EitherSimpleDefault()
    theme = dict(foo=30)
    c.foo = 50
    c.apply_theme(theme)
    assert c.foo == 50

    # check user set after theme
    c = EitherSimpleDefault()
    theme = dict(foo=30)
    c.apply_theme(theme)
    c.foo = 50
    assert c.foo == 50

    # check user set alt type
    c = EitherSimpleDefault()
    theme = dict(foo=30)
    c.foo = [50]
    c.apply_theme(theme)
    assert c.foo == [50]

    # check themed alt type
    c = EitherSimpleDefault()
    theme = dict(foo=[100])
    c.apply_theme(theme)
    assert c.foo == [100]

class EitherContainerDefault(hp.HasProps):
    foo = Either(List(Int), Int, default=[10])

def test_HasProps_apply_theme_either_container() -> None:

    # check applying multiple themes
    c = EitherContainerDefault()
    assert c.foo == [10]

    theme = dict(foo=[20])
    c.apply_theme(theme)
    assert c.foo == [20]

    theme = dict(foo=[30])
    c.apply_theme(theme)
    assert c.foo == [30]

    # check user set before theme
    c = EitherContainerDefault()
    theme = dict(foo=[30])
    c.foo = [50]
    c.apply_theme(theme)
    assert c.foo == [50]

    # check user set after theme
    c = EitherContainerDefault()
    theme = dict(foo=[30])
    c.apply_theme(theme)
    c.foo = [50]
    assert c.foo == [50]

    # check user set alt type
    c = EitherContainerDefault()
    theme = dict(foo=[30])
    c.foo = 50
    c.apply_theme(theme)
    assert c.foo == 50

    # check themed alt type
    c = EitherContainerDefault()
    theme = dict(foo=100)
    c.apply_theme(theme)
    assert c.foo == 100

class IntFuncDefault(hp.HasProps):
    foo = Int(default=lambda: 10)

def test_HasProps_apply_theme_func_default() -> None:

    # check applying multiple themes
    c = IntFuncDefault()
    assert c.foo == 10

    theme = dict(foo=20)
    c.apply_theme(theme)
    assert c.foo == 20

    theme = dict(foo=30)
    c.apply_theme(theme)
    assert c.foo == 30

    # check user set before theme
    c = IntFuncDefault()
    theme = dict(foo=30)
    c.foo = 50
    c.apply_theme(theme)
    assert c.foo == 50

    # check user set after theme
    c = IntFuncDefault()
    theme = dict(foo=30)
    c.apply_theme(theme)
    c.foo = 50
    assert c.foo == 50

def test_has_props_dupe_prop() -> None:
    try:
        class DupeProps(hp.HasProps):
            bar = AngleSpec()
            bar_units = String()
    except RuntimeError as e:
        assert str(e) == "Two property generators both created DupeProps.bar_units"
    else:
        assert False

class TopLevelQualified(hp.HasProps, hp.Qualified):
    foo = Int()

class TopLevelNonQualified(hp.HasProps, hp.NonQualified):
    foo = Int()

def test_qualified() -> None:
    class InnerQualified(hp.HasProps, hp.Qualified):
        foo = Int()

    class InnerNonQualified(hp.HasProps, hp.NonQualified):
        foo = Int()

    assert TopLevelQualified.__qualified_model__ == "test_has_props.TopLevelQualified"
    assert TopLevelNonQualified.__qualified_model__ == "TopLevelNonQualified"
    assert InnerQualified.__qualified_model__ == "test_has_props.test_qualified.InnerQualified"
    assert InnerNonQualified.__qualified_model__ == "test_qualified.InnerNonQualified"

class Some0HasProps(hp.HasProps, hp.Local):
    f0 = Int(default=3)
    f1 = List(Int, default=[3, 4, 5])

class Some1HasProps(hp.HasProps, hp.Local):
    f0 = String(default="xyz")
    f1 = List(String, default=["x", "y", "z"])

class Some2HasProps(hp.HasProps, hp.Local):
    f0 = Instance(Some0HasProps, lambda: Some0HasProps())
    f1 = Instance(Some1HasProps, lambda: Some1HasProps())
    f2 = Int(default=1)
    f3 = String(default="xyz")
    f4 = List(Int, default=[1, 2, 3])

class Some3HasProps(hp.HasProps, hp.Local):
    f4 = Int(default=4)
    f3 = Int(default=3)
    f2 = Int(default=2)
    f1 = Int(default=1)

def test_HasProps_properties_with_values_maintains_order() -> None:
    v0 = Some3HasProps()
    assert list(v0.properties_with_values(include_defaults=False).items()) == []
    assert list(v0.properties_with_values(include_defaults=True).items()) == [("f4", 4), ("f3", 3), ("f2", 2), ("f1", 1)]

    v1 = Some3HasProps(f1=10, f4=40)
    assert list(v1.properties_with_values(include_defaults=False).items()) == [("f4", 40), ("f1", 10)]
    assert list(v1.properties_with_values(include_defaults=True).items()) == [("f4", 40), ("f3", 3), ("f2", 2), ("f1", 10)]

    v2 = Some3HasProps(f4=40, f1=10)
    assert list(v2.properties_with_values(include_defaults=False).items()) == [("f4", 40), ("f1", 10)]
    assert list(v2.properties_with_values(include_defaults=True) .items()) == [("f4", 40), ("f3", 3), ("f2", 2), ("f1", 10)]

def test_HasProps_properties_with_values_unstable() -> None:
    v0 = Some0HasProps()
    assert v0.properties_with_values(include_defaults=False) == {}

    v1 = Some1HasProps()
    assert v1.properties_with_values(include_defaults=False) == {}

    v2 = Some2HasProps()
    assert v2.properties_with_values(include_defaults=False) == {"f0": v2.f0, "f1": v2.f1}

def test_HasProps_descriptors() -> None:
    v0 = Some0HasProps()

    d0 = v0.descriptors()
    assert len(d0) == 2
    assert d0[0].name == "f0"
    assert d0[1].name == "f1"

    v1 = Some1HasProps()

    d1 = v1.descriptors()
    assert len(d1) == 2
    assert d1[0].name == "f0"
    assert d1[1].name == "f1"

    v2 = Some2HasProps()

    d2 = v2.descriptors()
    assert len(d2) == 5
    assert d2[0].name == "f0"
    assert d2[1].name == "f1"
    assert d2[2].name == "f2"
    assert d2[3].name == "f3"
    assert d2[4].name == "f4"

#-----------------------------------------------------------------------------
# Private API
#-----------------------------------------------------------------------------

#-----------------------------------------------------------------------------
# Code
#-----------------------------------------------------------------------------


text:
<!doctype html>

    <meta name="viewport" content="width=device-width, initial-scale=1" charset="UTF-8">
    <title>presentPaymentOptions</title>
<link href="../../../../images/logo-icon.svg" rel="icon" type="image/svg">

<link href="../../../../styles/style.css" rel="Stylesheet">
<link href="../../../../styles/jetbrains-mono.css" rel="Stylesheet">
<link href="../../../../styles/main.css" rel="Stylesheet">
<link href="../../../../styles/prism.css" rel="Stylesheet">
<link href="../../../../styles/logo-styles.css" rel="Stylesheet">

stripe-android

        <button id="theme-toggle-button"></button>

paymentsheet/com.stripe.android.paymentsheet/PaymentSheet/FlowController/presentPaymentOptions

present<wbr>Payment<wbr>Options

abstract fun presentPaymentOptions()

Present a sheet where the customer chooses how to pay, either by selecting an existing payment method or adding a new one. Call this when your "Select a payment method" button is tapped.

        © 2022 CopyrightGenerated by dokka


text:
package org.apache.drill.exec.physical.impl.unnest;

import org.apache.drill.categories.OperatorTest;
import org.apache.drill.common.exceptions.DrillException;
import org.apache.drill.common.exceptions.UserException;
import org.apache.drill.common.expression.PathSegment;
import org.apache.drill.common.expression.SchemaPath;
import org.apache.drill.common.types.TypeProtos;
import org.apache.drill.exec.ExecConstants;
import org.apache.drill.exec.ops.OperatorContext;
import org.apache.drill.exec.physical.base.LateralContract;
import org.apache.drill.exec.physical.base.PhysicalOperator;
import org.apache.drill.exec.physical.config.UnnestPOP;
import org.apache.drill.exec.physical.impl.MockRecordBatch;
import org.apache.drill.exec.record.RecordBatch;
import org.apache.drill.exec.record.metadata.TupleMetadata;
import org.apache.drill.exec.record.VectorContainer;
import org.apache.drill.exec.store.mock.MockStorePOP;
import org.apache.drill.exec.vector.ValueVector;
import org.apache.drill.exec.vector.VarCharVector;
import org.apache.drill.exec.vector.complex.MapVector;
import org.apache.drill.test.SubOperatorTest;
import org.apache.drill.test.rowSet.RowSet;
import org.apache.drill.test.rowSet.RowSetBuilder;
import org.apache.drill.test.rowSet.schema.SchemaBuilder;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import java.util.ArrayList;
import java.util.List;

import static junit.framework.TestCase.fail;
import static org.junit.Assert.assertTrue;

@Category(OperatorTest.class) public class TestUnnestCorrectness extends SubOperatorTest {

  // Operator Context for mock batch
  public static OperatorContext operatorContext;

  // use MockLateralJoinPop for MockRecordBatch ??
  public static PhysicalOperator mockPopConfig;

  @BeforeClass public static void setUpBeforeClass() throws Exception {
    mockPopConfig = new MockStorePOP(null);
    operatorContext = fixture.newOperatorContext(mockPopConfig);
  }

  @AfterClass public static void tearDownAfterClass() throws Exception {
    operatorContext.close();
  }

  @Test
  public void testUnnestFixedWidthColumn() {

    Object[][] data = {
        { (Object) new int[] {1, 2},
          (Object) new int[] {3, 4, 5}},
        { (Object) new int[] {6, 7, 8, 9},
          (Object) new int[] {10, 11, 12, 13, 14}}
    };

    // Create input schema
    TupleMetadata incomingSchema =
        new SchemaBuilder()
            .add("rowNumber", TypeProtos.MinorType.INT)
            .addArray("unnestColumn", TypeProtos.MinorType.INT)
            .buildSchema();
    TupleMetadata[] incomingSchemas = { incomingSchema, incomingSchema };

    // First batch in baseline is an empty batch corresponding to OK_NEW_SCHEMA
    Integer[][] baseline = {{}, {1, 2}, {3, 4, 5}, {6, 7, 8, 9}, {10, 11, 12, 13, 14}};

    RecordBatch.IterOutcome[] iterOutcomes = {RecordBatch.IterOutcome.OK_NEW_SCHEMA, RecordBatch.IterOutcome.OK};

    try {
      testUnnest(incomingSchemas, iterOutcomes, data, baseline);
    } catch (Exception e) {
      fail("Failed due to exception: " + e.getMessage());
    }

  }

  @Test
  public void testUnnestVarWidthColumn() {

    Object[][] data = {
        { (Object) new String[] {"", "zero"},
          (Object) new String[] {"one", "two", "three"}},
        { (Object) new String[] {"four", "five", "six", "seven"},
          (Object) new String[] {"eight", "nine", "ten", "eleven", "twelve"}}
    };

    // Create input schema
    TupleMetadata incomingSchema = new SchemaBuilder()
        .add("someColumn", TypeProtos.MinorType.INT)
        .addArray("unnestColumn", TypeProtos.MinorType.VARCHAR).buildSchema();
    TupleMetadata[] incomingSchemas = {incomingSchema, incomingSchema};

    // First batch in baseline is an empty batch corresponding to OK_NEW_SCHEMA
    String[][] baseline = {{}, {"", "zero"}, {"one", "two", "three"}, {"four", "five", "six", "seven"},
        {"eight", "nine", "ten", "eleven", "twelve"}};

    RecordBatch.IterOutcome[] iterOutcomes = {RecordBatch.IterOutcome.OK_NEW_SCHEMA, RecordBatch.IterOutcome.OK};

    try {
      testUnnest(incomingSchemas, iterOutcomes, data, baseline);
    } catch (Exception e) {
      fail("Failed due to exception: " + e.getMessage());
    }

  }

  @Test
  @Ignore("With DRILL-6321 commits, Unnest's output could be multiplec olumns")
  public void testUnnestMapColumn() {

    Object[][] data = getMapData();

    // Create input schema
    TupleMetadata incomingSchema = getRepeatedMapSchema();
    TupleMetadata[] incomingSchemas = {incomingSchema, incomingSchema};

    // First batch in baseline is an empty batch corresponding to OK_NEW_SCHEMA
    Object[][] baseline = getMapBaseline();

    RecordBatch.IterOutcome[] iterOutcomes = {RecordBatch.IterOutcome.OK_NEW_SCHEMA, RecordBatch.IterOutcome.OK};

    try {
      testUnnest(incomingSchemas, iterOutcomes, data, baseline);
    } catch (Exception e) {
      fail("Failed due to exception: " + e.getMessage());
    }

  }

  @Test
  public void testUnnestEmptyList() {

    Object[][] data = {
        { (Object) new String[] {},
          (Object) new String[] {}
        },
        { (Object) new String[] {},
          (Object) new String[] {}
        }
    };

    // Create input schema
    TupleMetadata incomingSchema = new SchemaBuilder()
        .add("someColumn", TypeProtos.MinorType.INT)
        .addArray("unnestColumn", TypeProtos.MinorType.VARCHAR).buildSchema();
    TupleMetadata[] incomingSchemas = {incomingSchema, incomingSchema};

    // First batch in baseline is an empty batch corresponding to OK_NEW_SCHEMA
    // All subsequent batches are also empty
    String[][] baseline = {{}, {}, {}, {}, {}};

    RecordBatch.IterOutcome[] iterOutcomes = {RecordBatch.IterOutcome.OK_NEW_SCHEMA, RecordBatch.IterOutcome.OK};

    try {
      testUnnest(incomingSchemas, iterOutcomes, data, baseline);
    } catch (Exception e) {
      fail("Failed due to exception: " + e.getMessage());
    }

  }

  @Test
  public void testUnnestMultipleNewSchemaIncoming() {

    // Schema changes in incoming have no effect on unnest unless the type of the
    // unnest column itself has changed
    Object[][] data = {
        {
            (Object) new String[] {"0", "1"},
            (Object) new String[] {"2", "3", "4"}
        },
        {
            (Object) new String[] {"5", "6" },
        },
        {
            (Object) new String[] {"9"}
        }
    };

    // Create input schema
    TupleMetadata incomingSchema = new SchemaBuilder()
        .add("someColumn", TypeProtos.MinorType.INT)
        .addArray("unnestColumn", TypeProtos.MinorType.VARCHAR).buildSchema();
    TupleMetadata[] incomingSchemas = {incomingSchema, incomingSchema, incomingSchema};

    // First batch in baseline is an empty batch corresponding to OK_NEW_SCHEMA
    String[][] baseline = {{}, {"0", "1"}, {"2", "3", "4"}, {"5", "6" }, {"9"} };

    RecordBatch.IterOutcome[] iterOutcomes = {
        RecordBatch.IterOutcome.OK_NEW_SCHEMA,
        RecordBatch.IterOutcome.OK,
        RecordBatch.IterOutcome.OK_NEW_SCHEMA};

    try {
      testUnnest(incomingSchemas, iterOutcomes, data, baseline);
    } catch (Exception e) {
      fail("Failed due to exception: " + e.getMessage());
    }

  }

  @Test
  public void testUnnestSchemaChange() {
    Object[][] data = {
        {
            (Object) new String[] {"0", "1"},
            (Object) new String[] {"2", "3", "4"}
        },
        {
            (Object) new String[] {"5", "6" },
        },
        {
            (Object) new int[] {9}
        }
    };

    // Create input schema
    TupleMetadata incomingSchema1 = new SchemaBuilder()
        .add("someColumn", TypeProtos.MinorType.INT)
        .addArray("unnestColumn", TypeProtos.MinorType.VARCHAR).buildSchema();
    TupleMetadata incomingSchema2 = new SchemaBuilder()
        .add("someColumn", TypeProtos.MinorType.INT)
        .addArray("unnestColumn", TypeProtos.MinorType.INT).buildSchema();

    TupleMetadata[] incomingSchemas = {incomingSchema1, incomingSchema1, incomingSchema2};

    // First batch in baseline is an empty batch corresponding to OK_NEW_SCHEMA
    // Another empty batch introduced by the schema change in the last batch
    Object[][] baseline = {{}, {"0", "1"}, {"2", "3", "4"}, {"5", "6" }, {}, {9} };

    RecordBatch.IterOutcome[] iterOutcomes = {
        RecordBatch.IterOutcome.OK_NEW_SCHEMA,
        RecordBatch.IterOutcome.OK,
        RecordBatch.IterOutcome.OK_NEW_SCHEMA};

    try {
      testUnnest(incomingSchemas, iterOutcomes, data, baseline);
    } catch (Exception e) {
      fail("Failed due to exception: " + e.getMessage());
    }

  }

  @Test
  public void testUnnestLimitBatchSize() {

    final int limitedOutputBatchSize = 1023; // one less than the power of two. See RecordBatchMemoryManager
                                             // .adjustOutputRowCount
    final int limitedOutputBatchSizeBytes = 1024*4*1; // (num rows+1) * size of int
    final int inputBatchSize = 1023+1;
    // single record batch with single row. The unnest column has one
    // more record than the batch size we want in the output
    Object[][] data = new Object[1][1];

    for (int i = 0; i < data.length; i++) {
      for (int j = 0; j < data[i].length; j++) {
        data[i][j] = new int[inputBatchSize];
        for (int k =0; k < inputBatchSize; k++) {
          ((int[])data[i][j])[k] = k;
        }
      }
    }
    Integer[][] baseline = new Integer[3][];
    baseline[0] = new Integer[] {};
    baseline[1] = new Integer[limitedOutputBatchSize];
    baseline[2] = new Integer[1];
    for (int i = 0; i < limitedOutputBatchSize; i++) {
      baseline[1][i] = i;
    }
    baseline[2][0] = limitedOutputBatchSize;

    // Create input schema
    TupleMetadata incomingSchema = new SchemaBuilder()
        .add("rowNumber", TypeProtos.MinorType.INT)
        .addArray("unnestColumn", TypeProtos.MinorType.INT).buildSchema();

    TupleMetadata[] incomingSchemas = {incomingSchema};

    RecordBatch.IterOutcome[] iterOutcomes = {RecordBatch.IterOutcome.OK};

    final long outputBatchSize = fixture.getFragmentContext().getOptions().getOption(ExecConstants
        .OUTPUT_BATCH_SIZE_VALIDATOR);
    fixture.getFragmentContext().getOptions().setLocalOption(ExecConstants.OUTPUT_BATCH_SIZE, limitedOutputBatchSizeBytes);

    try {
      testUnnest(incomingSchemas, iterOutcomes, data, baseline);
    } catch (Exception e) {
      fail("Failed due to exception: " + e.getMessage());
    } finally {
      fixture.getFragmentContext().getOptions().setLocalOption(ExecConstants.OUTPUT_BATCH_SIZE, outputBatchSize);
    }

  }

  @Test
  // Limit sends a kill. Unnest has more than one record batch for a record when
  // the kill is sent.
  public void testUnnestKillFromLimitSubquery1() {

    // similar to previous test; we split a record across more than one batch.
    // but we also set a limit less than the size of the batch so only one batch gets output.

    final int limitedOutputBatchSize = 1023; // one less than the power of two. See RecordBatchMemoryManager
                                             // .adjustOutputRowCount
    final int limitedOutputBatchSizeBytes = 1024*4*1; // (num rows+1) * size of int
    final int inputBatchSize = 1023+1;
    // single record batch with single row. The unnest column has one
    // more record than the batch size we want in the output
    Object[][] data = new Object[1][1];

    for (int i = 0; i < data.length; i++) {
      for (int j = 0; j < data[i].length; j++) {
        data[i][j] = new int[inputBatchSize];
        for (int k =0; k < inputBatchSize; k++) {
          ((int[])data[i][j])[k] = k;
        }
      }
    }
    Integer[][] baseline = new Integer[3][];
    baseline[0] = new Integer[] {};
    baseline[1] = new Integer[limitedOutputBatchSize];
    baseline[2] = new Integer[1];
    for (int i = 0; i < limitedOutputBatchSize; i++) {
      baseline[1][i] = i;
    }
    baseline[2] = new Integer[] {}; // because of kill the next batch is an empty batch

    // Create input schema
    TupleMetadata incomingSchema = new SchemaBuilder()
        .add("rowNumber", TypeProtos.MinorType.INT)
        .addArray("unnestColumn", TypeProtos.MinorType.INT).buildSchema();

    TupleMetadata[] incomingSchemas = {incomingSchema};

    RecordBatch.IterOutcome[] iterOutcomes = {RecordBatch.IterOutcome.OK};

    final long outputBatchSize = fixture.getFragmentContext().getOptions().getOption(ExecConstants
        .OUTPUT_BATCH_SIZE_VALIDATOR);
    fixture.getFragmentContext().getOptions().setLocalOption(ExecConstants.OUTPUT_BATCH_SIZE, limitedOutputBatchSizeBytes);

    try {
      testUnnest(incomingSchemas, iterOutcomes, 100, -1, data, baseline); // Limit of 100 values for unnest.
    } catch (Exception e) {
      fail("Failed due to exception: " + e.getMessage());
    } finally {
      fixture.getFragmentContext().getOptions().setLocalOption(ExecConstants.OUTPUT_BATCH_SIZE, outputBatchSize);
    }

  }

  @Test
  // Limit sends a kill. Unnest has exactly one record batch for a record when
  // the kill is sent. This test is actually useless since it tests the behaviour of
  // the mock lateral which doesn't send kill at all if it gets an EMIT. We expect limit
  // to do so, so let's keep the test to demonstrate the expected behaviour.
  public void testUnnestKillFromLimitSubquery2() {

    // similar to previous test but the size of the array fits exactly into the record batch;
    final int limitedOutputBatchSize = 1023; // one less than the power of two. See RecordBatchMemoryManager
                                             // .adjustOutputRowCount
    final int limitedOutputBatchSizeBytes = 1024*4*1; // (num rows+1) * size of int
    final int inputBatchSize = 1023;
    // single record batch with single row. The unnest column has one
    // more record than the batch size we want in the output
    Object[][] data = new Object[1][1];

    for (int i = 0; i < data.length; i++) {
      for (int j = 0; j < data[i].length; j++) {
        data[i][j] = new int[inputBatchSize];
        for (int k =0; k < inputBatchSize; k++) {
          ((int[])data[i][j])[k] = k;
        }
      }
    }
    Integer[][] baseline = new Integer[2][];
    baseline[0] = new Integer[] {};
    baseline[1] = new Integer[limitedOutputBatchSize];
    for (int i = 0; i < limitedOutputBatchSize; i++) {
      baseline[1][i] = i;
    }

    // Create input schema
    TupleMetadata incomingSchema = new SchemaBuilder()
        .add("rowNumber", TypeProtos.MinorType.INT)
        .addArray("unnestColumn", TypeProtos.MinorType.INT).buildSchema();

    TupleMetadata[] incomingSchemas = {incomingSchema};

    RecordBatch.IterOutcome[] iterOutcomes = {RecordBatch.IterOutcome.OK};

    final long outputBatchSize = fixture.getFragmentContext().getOptions().getOption(ExecConstants
        .OUTPUT_BATCH_SIZE_VALIDATOR);
    fixture.getFragmentContext().getOptions().setLocalOption(ExecConstants.OUTPUT_BATCH_SIZE, limitedOutputBatchSizeBytes);

    try {
      testUnnest(incomingSchemas, iterOutcomes, 100, -1, data, baseline); // Limit of 100 values for unnest.
    } catch (Exception e) {
      fail("Failed due to exception: " + e.getMessage());
    } finally {
      fixture.getFragmentContext().getOptions().setLocalOption(ExecConstants.OUTPUT_BATCH_SIZE, outputBatchSize);
    }

  }

  @Test
  public void testUnnestNonArrayColumn() {

    Object[][] data = {
        { (Object) new Integer (1),
            (Object) new Integer (3)},
        { (Object) new Integer (6),
            (Object) new Integer (10)}
    };

    // Create input schema
    TupleMetadata incomingSchema =
        new SchemaBuilder()
            .add("rowNumber", TypeProtos.MinorType.INT)
            .add("unnestColumn", TypeProtos.MinorType.INT)
            .buildSchema();
    TupleMetadata[] incomingSchemas = { incomingSchema, incomingSchema };

    // We expect an Exception
    Integer[][] baseline = {};

    RecordBatch.IterOutcome[] iterOutcomes = {RecordBatch.IterOutcome.OK_NEW_SCHEMA, RecordBatch.IterOutcome.OK};

    try {
      testUnnest(incomingSchemas, iterOutcomes, data, baseline);
    } catch (UserException e) {
      return; // succeeded
    } catch (Exception e) {
      fail("Failed due to exception: " + e.getMessage());
    }

  }

  // test unnest for various input conditions without invoking kill
  private <T> void testUnnest(
      TupleMetadata[] incomingSchemas,
      RecordBatch.IterOutcome[] iterOutcomes,
      T[][] data,
      T[][] baseline ) throws Exception{
    testUnnest(incomingSchemas, iterOutcomes, -1, -1, data, baseline);
  }

  // test unnest for various input conditions optionally invoking kill. if the kill or killBatch
  // parameter is greater than 0 then the record batch is sent a kill after that many batches have been processed
  private <T> void testUnnest( TupleMetadata[] incomingSchemas,
      RecordBatch.IterOutcome[] iterOutcomes,
      int unnestLimit, // kill unnest after every 'unnestLimit' number of values in every record
      int execKill, // number of batches after which to kill the execution (!)
      T[][] data,
      T[][] baseline) throws Exception {

    // Get the incoming container with dummy data for LJ
    final List<VectorContainer> incomingContainer = new ArrayList<>(data.length);

    // Create data
    ArrayList<RowSet.SingleRowSet> rowSets = new ArrayList<>();

    int rowNumber = 0;
    int batchNum = 0;
    for ( Object[] recordBatch : data) {
      RowSetBuilder rowSetBuilder = fixture.rowSetBuilder(incomingSchemas[batchNum]);
      for ( Object rowData : recordBatch) {
        rowSetBuilder.addRow(++rowNumber, rowData);
      }
      RowSet.SingleRowSet rowSet = rowSetBuilder.build();
      rowSets.add(rowSet);
      incomingContainer.add(rowSet.container());
      batchNum++;
    }

    // Get the unnest POPConfig
    final UnnestPOP unnestPopConfig = new UnnestPOP(null, new SchemaPath(new PathSegment.NameSegment("unnestColumn")));

    // Get the IterOutcomes for LJ
    final List<RecordBatch.IterOutcome> outcomes = new ArrayList<>(iterOutcomes.length);
    for(RecordBatch.IterOutcome o : iterOutcomes) {
      outcomes.add(o);
    }

    // Create incoming MockRecordBatch
    final MockRecordBatch incomingMockBatch =
        new MockRecordBatch(fixture.getFragmentContext(), operatorContext, incomingContainer, outcomes,
            incomingContainer.get(0).getSchema());

    final MockLateralJoinBatch lateralJoinBatch =
        new MockLateralJoinBatch(fixture.getFragmentContext(), operatorContext, incomingMockBatch);

    // setup Unnest record batch
    final UnnestRecordBatch unnestBatch =
        new UnnestRecordBatch(unnestPopConfig, fixture.getFragmentContext());

    // set pointer to Lateral in unnest pop config
    unnestBatch.setIncoming((LateralContract) lateralJoinBatch);

    // set backpointer to lateral join in unnest
    lateralJoinBatch.setUnnest(unnestBatch);
    lateralJoinBatch.setUnnestLimit(unnestLimit);

    // Simulate the pipeline by calling next on the incoming
    List<ValueVector> results = null;
    int batchesProcessed = 0;
    try {
      while (!isTerminal(lateralJoinBatch.next())) {
        batchesProcessed++;
        if (batchesProcessed == execKill) {
          lateralJoinBatch.getContext().getExecutorState().fail(new DrillException("Testing failure of execution."));
          lateralJoinBatch.kill(true);
        }
        // else nothing to do
      }

      // Check results against baseline
      results = lateralJoinBatch.getResultList();

      int i = 0;
      for (ValueVector vv : results) {
        int valueCount = vv.getAccessor().getValueCount();
        if (valueCount != baseline[i].length) {
          fail("Test failed in validating unnest output. Value count mismatch.");
        }
        for (int j = 0; j < valueCount; j++) {

          if (vv instanceof MapVector) {
            if (!compareMapBaseline((Object) baseline[i][j], vv.getAccessor().getObject(j))) {
              fail("Test failed in validating unnest(Map) output. Value mismatch");
            }
          } else if (vv instanceof VarCharVector) {
            Object val = vv.getAccessor().getObject(j);
            if (((String) baseline[i][j]).compareTo(val.toString()) != 0) {
              fail("Test failed in validating unnest output. Value mismatch. Baseline value[]" + i + "][" + j + "]"
                  + ": " + baseline[i][j] + "   VV.getObject(j): " + val);
            }
          } else {
            Object val = vv.getAccessor().getObject(j);
            if (!baseline[i][j].equals(val)) {
              fail(
                  "Test failed in validating unnest output. Value mismatch. Baseline value[" + i + "][" + j + "]" + ": "
                      + baseline[i][j] + "   VV.getObject(j): " + val);
            }
          }
        }
        i++;

      }

      assertTrue(((MockLateralJoinBatch) lateralJoinBatch).isCompleted());

    } catch (UserException e) {
      throw e; // Valid exception
    } catch (Exception e) {
      fail("Test failed in validating unnest output. Exception : " + e.getMessage());
    } finally {
      // Close all the resources for this test case
      unnestBatch.close();
      lateralJoinBatch.close();
      incomingMockBatch.close();

      if (results != null) {
        for (ValueVector vv : results) {
          vv.clear();
        }
      }
      for(RowSet.SingleRowSet rowSet: rowSets) {
        rowSet.clear();
      }
    }

  }

  /**
   * Build a schema with a repeated map -
   *
   *  {
   *    rowNum,
   *    mapColumn : [
   *       {
   *         colA,
   *         colB : [
   *            varcharCol
   *         ]
   *       }
   *    ]
   *  }
   *
   * @see TestResultSetLoaderMapArray TestResultSetLoaderMapArray for similar schema and data
   * @return TupleMetadata corresponding to the schema
   */
  private TupleMetadata getRepeatedMapSchema() {
    TupleMetadata schema = new SchemaBuilder()
        .add("rowNum", TypeProtos.MinorType.INT)
        .addMapArray("unnestColumn")
          .add("colA", TypeProtos.MinorType.INT)
          .addArray("colB", TypeProtos.MinorType.VARCHAR)
        .resumeSchema()
        .buildSchema();
    return schema;
  }

  private Object[][] getMapData( ) {

    Object[][] d = {
      {
          new Object[] {},
          new Object[] {
              new Object[] {11, new String[] {"1.1.1", "1.1.2" }},
              new Object[] {12, new String[] {"1.2.1", "1.2.2" }}
          },

          new Object[] {
              new Object[] {21, new String[] {"2.1.1", "2.1.2" }},
              new Object[] {22, new String[] {}},
              new Object[] {23, new String[] {"2.3.1", "2.3.2" }}
          }
      },
      {
        new Object[] {
            new Object[] {31, new String[] {"3.1.1", "3.1.2" }},
            new Object[] {32, new String[] {"3.2.1", "3.2.2" }}
        }
      }
    };

    return d;
  }

  private Object[][] getMapBaseline() {

    Object[][] d = {
        new Object[] {},    // Empty record batch returned by OK_NEW_SCHEMA
        new Object[] {},    // First incoming batch is empty
        new Object[] {
            "{\"colA\":11,\"colB\":[\"1.1.1\",\"1.1.2\"]}",
            "{\"colA\":12,\"colB\":[\"1.2.1\",\"1.2.2\"]}"
        },
        new Object[] {
            "{\"colA\":21,\"colB\":[\"2.1.1\",\"2.1.2\"]}",
            "{\"colA\":22,\"colB\":[]}",
            "{\"colA\":23,\"colB\":[\"2.3.1\",\"2.3.2\"]}"
        },
        new Object[] {
            "{\"colA\":31,\"colB\":[\"3.1.1\",\"3.1.2\"]}",
            "{\"colA\":32,\"colB\":[\"3.2.1\",\"3.2.2\"]}"
        }
    };
    return d;
  }

  private boolean compareMapBaseline(Object baselineValue, Object vector) {
    String vv = vector.toString();
    String b = (String)baselineValue;
    return vv.equalsIgnoreCase(b);
  }

  private boolean isTerminal(RecordBatch.IterOutcome outcome) {
    return (outcome == RecordBatch.IterOutcome.NONE || outcome == RecordBatch.IterOutcome.STOP) || (outcome
        == RecordBatch.IterOutcome.OUT_OF_MEMORY);
  }

}


text:
package com.yammer.dropwizard.testing.tests;

import org.codehaus.jackson.type.TypeReference;
import org.junit.Test;

import static com.yammer.dropwizard.testing.JsonHelpers.*;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;

public class JsonHelpersTest {
    private final String json = "{\"name\":\"Coda\",\"email\":\"coda@example.com\"}";

    @Test
    public void readsJsonFixturesAsJsonNodes() throws Exception {
        assertThat(jsonFixture("fixtures/person.json"),
                   is(json));
    }

    @Test
    public void convertsObjectsIntoJson() throws Exception {
        assertThat(asJson(new Person("Coda", "coda@example.com")),
                   is(jsonFixture("fixtures/person.json")));
    }

    @Test
    public void convertsJsonIntoObjects() throws Exception {
        assertThat(fromJson(jsonFixture("fixtures/person.json"), Person.class),
                   is(new Person("Coda", "coda@example.com")));

        assertThat(fromJson(jsonFixture("fixtures/person.json"), new TypeReference<Person>() {}),
                   is(new Person("Coda", "coda@example.com")));
    }
}


text:
package gin

import (
	"fmt"
	"io"
	"time"
)

var (
	green   = string([]byte{27, 91, 57, 55, 59, 52, 50, 109})
	white   = string([]byte{27, 91, 57, 48, 59, 52, 55, 109})
	yellow  = string([]byte{27, 91, 57, 55, 59, 52, 51, 109})
	red     = string([]byte{27, 91, 57, 55, 59, 52, 49, 109})
	blue    = string([]byte{27, 91, 57, 55, 59, 52, 52, 109})
	magenta = string([]byte{27, 91, 57, 55, 59, 52, 53, 109})
	cyan    = string([]byte{27, 91, 57, 55, 59, 52, 54, 109})
	reset   = string([]byte{27, 91, 48, 109})
)

func ErrorLogger() HandlerFunc {
	return ErrorLoggerT(ErrorTypeAny)
}

func ErrorLoggerT(typ ErrorType) HandlerFunc {
	return func(c *Context) {
		c.Next()
		errors := c.Errors.ByType(typ)
		if len(errors) > 0 {
			c.JSON(-1, errors)
		}
	}
}

// Logger instances a Logger middleware that will write the logs to gin.DefaultWriter
// By default gin.DefaultWriter = os.Stdout
func Logger() HandlerFunc {
	return LoggerWithWriter(DefaultWriter)
}

// LoggerWithWriter instance a Logger middleware with the specified writter buffer.
// Example: os.Stdout, a file opened in write mode, a socket...
func LoggerWithWriter(out io.Writer, notlogged ...string) HandlerFunc {
	var skip map[string]struct{}

	if length := len(notlogged); length > 0 {
		skip = make(map[string]struct{}, length)

		for _, path := range notlogged {
			skip[path] = struct{}{}
		}
	}

	return func(c *Context) {
		// Start timer
		start := time.Now()
		path := c.Request.URL.Path

		// Process request
		c.Next()

		// Log only when path is not being skipped
		if _, ok := skip[path]; !ok {
			// Stop timer
			end := time.Now()
			latency := end.Sub(start)

			clientIP := c.ClientIP()
			method := c.Request.Method
			statusCode := c.Writer.Status()
			statusColor := colorForStatus(statusCode)
			methodColor := colorForMethod(method)
			comment := c.Errors.ByType(ErrorTypePrivate).String()

			fmt.Fprintf(out, "[GIN] %v |%s %3d %s| %13v | %s |%s  %s %-7s %s\n%s",
				end.Format("2006/01/02 - 15:04:05"),
				statusColor, statusCode, reset,
				latency,
				clientIP,
				methodColor, reset, method,
				path,
				comment,
			)
		}
	}
}

func colorForStatus(code int) string {
	switch {
	case code >= 200 && code < 300:
		return green
	case code >= 300 && code < 400:
		return white
	case code >= 400 && code < 500:
		return yellow
	default:
		return red
	}
}

func colorForMethod(method string) string {
	switch method {
	case "GET":
		return blue
	case "POST":
		return cyan
	case "PUT":
		return yellow
	case "DELETE":
		return red
	case "PATCH":
		return green
	case "HEAD":
		return magenta
	case "OPTIONS":
		return white
	default:
		return reset
	}
}


text:
SYNONYM

#### According to
The Catalogue of Life, 3rd January 2011

#### Published in
A. Gray, Proc. Acad. Nat. Sci. Philadelphia 15:78. 1864

#### Original name
null

### Remarks
null


text:
import requests
import hashlib

from puke.Console import *
from puke.FileSystem import *

import urlparse, StringIO, os, ftplib

class Cache:

	@staticmethod
	def fetchHttp(url):
		id = hashlib.sha256(url).hexdigest()

		if Cache.check(id):
			return Cache.getPath(id)

		infos = urlparse.urlparse(url)
		try:
			console.debug('Cache#Fetching remote file %s' % url)

			if infos.scheme == 'ftp':
				buffer = StringIO.StringIO()

				ftp = ftplib.FTP(infos.netloc)
				ftp.login('anonymous')
				ftp.cwd(os.path.dirname(infos.path))
				ftp.retrbinary("RETR " + os.path.basename(infos.path), buffer.write)
				payload = buffer.getvalue()
				buffer.close()
			else:
				handler = requests.get(url, stream=True, verify=False)
				# try:
				# 	payload = handler.text.decode('utf-8')
				# except:
				# 	payload = handler.content
				payload = handler
				if len(handler.history):
					console.warn('Cache#Fetching http redirect : %s (%s)'% (url, handler.history))
		except Exception as error:
			console.fail('HTTP fail %s (%s)' % (url, error))
			return False

		return Cache.write(id, payload, url)

	@staticmethod
	def write(id, payload, info = None):

		writefile(join(".pukecache", "%s" % id), payload)

		if info:
			writefile(join(".pukecache", "%s.meta" % id), info)

		return Cache.getPath(id)

	@staticmethod
	def read(id):
		if not Cache.check(id):
			return None

		return readfile(join(".pukecache", "%s" % id))

	@staticmethod
	def check(id):
		return exists(join(".pukecache", "%s" % id))

	@staticmethod
	def getPath(id):
		return join(".pukecache", "%s" % id)

	@staticmethod
	def getInfo(id):
		if not exists(join(".pukecache","%s.meta" % id)):
			return ""

		return readfile(join(".pukecache", "%s.meta" % id))

	@staticmethod
	def clean():
		try:
			remove(".pukecache")
			return True
		except:
			return False


text:
This Google Cast demo application shows how to send messages from an Chrome desktop browser to a receiver using a custom namespace.

## Dependencies
* Chrome browser.

## Setup Instructions
* Just check out the code from GitHub, host chromehellotext.html on your own server and open that page in your Chrome browser
* If you don't want to use the sample App ID, you need to do the following steps
* Get a Chromecast device and get it set up for development: https://developers.google.com/cast/docs/developers#Get_started
* Register an application on the Developers Console (http://cast.google.com/publish). Select the Custom Receiver option and specify the URL to where you are hosting the receiver.html file (You can use Google Drive to host your files: https://support.google.com/drive/answer/2881970?hl=en). You will get an App ID when you finish registering your application.
* Setup the project dependencies
* Insert your App ID in the chromehellotext.html file of the project (look for applicationID in that file)
* Upload the chromehellotext.html file to your hosting server and load the URL for that file in your Chrome browser.

## References and How to report bugs
* Cast APIs: http://developers.google.com/cast
* Design Checklist (http://developers.google.com/cast/docs/design_checklist)
* If you find any issues, please open a bug here on GitHub

## How to make contributions?
Please read and follow the steps in the CONTRIBUTING.md

## License
See LICENSE

## Terms
Your use of this sample is subject to, and by using or downloading the sample files you agree to comply with, the [Google APIs Terms of Service](https://developers.google.com/terms/) and the [Google Cast SDK Additional Developer Terms of Service](https://developers.google.com/cast/docs/terms/).

## Google+
Google Cast Developers Community on Google+ [http://goo.gl/TPLDxj](http://goo.gl/TPLDxj)


text:
package com.f2prateek.rx.preferences;

import android.content.SharedPreferences;
import android.support.annotation.NonNull;

final class LongAdapter implements Preference.Adapter<Long> {
  static final LongAdapter INSTANCE = new LongAdapter();

  @Override public Long get(@NonNull String key, @NonNull SharedPreferences preferences) {
    return preferences.getLong(key, 0L);
  }

  @Override public void set(@NonNull String key, @NonNull Long value,
      @NonNull SharedPreferences.Editor editor) {
    editor.putLong(key, value);
  }
}


text:
<?php
/* @var $this ShareUploadsController */
/* @var $model ShareUploads */

$this->breadcrumbs=array(
	'Share Uploads'=>array('index'),
	'Create',
);

$this->menu=array(
	array('label'=>'List ShareUploads', 'url'=>array('index')),
	array('label'=>'Manage ShareUploads', 'url'=>array('admin')),
);
?>

Create ShareUploads

<?php echo $this->renderPartial('_form', array('model'=>$model)); ?>


text:
/*
This code uses the Button connected to P1.3 to control the LED connected on P1.0 (on the launchpad)

When the button is pressed, P1.3 is grounded and when it is not pressed, P1.3 is at high impedance state.
Hence, we use the internal pull up resistors available on the MSP430G2553 to treat this high impedance state as logical HIGH.
So when the button is pressed, P1.3 will be read as logical LOW and when the button is not pressed, the button will be read as logical HIGH.

When the button is pressed, this code turns on the LED and when it is not pressed, the LED is turned off.

No debouncing is needed for this code as it will not affect the state of the LED noticeably.

Make sure the jumper connecting the LED to pin 1.0 is connected properly (It is already connected by default)
*/
#include <msp430.h>

int main(void) {

    WDTCTL = WDTPW | WDTHOLD;	// Stop watchdog timer
    P1DIR&=~BIT3; //Set P1.3 as input
    P1REN|=BIT3; //Enable pullup/pulldown resistors for P1.3
    P1OUT|=BIT3; //Set P1.3 to have pull up resistors

    P1DIR|=BIT0; //Set P1.0 as output

    while(1) //Run the below code forever
    {
        if((P1IN&BIT3)==(BIT3)) //If P1.3 is logical HIGH
            P1OUT&=~BIT0; //Turn off the LED
        else
            P1OUT|=BIT0; //Else, turn on the LED
    }
    return 0;
}


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

<title>Appswell: Welcome</title>

<meta name="keywords" content="google, app, engine, framework, appswell, klenwell" />
<meta name="description" content="welcome to the appswell google app engine framework" />
<meta http-equiv="content-type" content="text/html; charset=utf-8" />

<link rel="stylesheet" href="/css/reset.css" type="text/css" />

Welcome to Appswell

Congratulations! Your are up and running.

This is just the beginning. Add new models, controllers, and views to your
project directory to develop your application.

The following pages have already been set up:

/usage

/auth/admin

/auth/user

/demo/services

/demo/backend

The Appswell project page can be found at
http://code.google.com/p/appswell/


text:
<?xml version="1.0" encoding="utf-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns:context="http://www.springframework.org/schema/context"
	xmlns:tx="http://www.springframework.org/schema/tx"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
				http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
				http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
  <bean id="springBeanTest" class="com.test.SpringBeanTest"></bean>
</beans>


text:
PSR 2 Coding Style Guide Example 4.2

https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md
--FILE--
<?php

namespace Vendor\Package;

class ClassName
{
    public $foo = null;
}

?>
--EXPECT--
<?php

namespace Vendor\Package;

class ClassName
{
    public $foo = null;
}

?>


text:
package com.gavin.ssm.msg.core.rabbitmq;

import lombok.extern.slf4j.Slf4j;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import java.nio.charset.StandardCharsets;
import java.util.concurrent.TimeUnit;

@Slf4j
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:spring-rabbitmq.xml")
public class AmqpTemplateTest {

    private static final String EXCHANGE = "direct_exchange";
    private static final String ROUTING_KEY = "order.create";
    private static final String QUEUE = "direct_exchange_queue";

    @Autowired
    private AmqpTemplate amqpTemplate;

    @Before
    public void setUp() {
        Assert.assertNotNull(amqpTemplate);
    }

    /**
     * <pre>{@code
     * public class MessageListener {
     *   @RabbitListener(queues = "my_queue")
     *   public void onMessage(String message) {
     *       log.info("====== {} ======", message);
     *   }
     * }
     * }</pre>
     */
    @Test
    public void testConvertAndSend1() {
        amqpTemplate.convertAndSend(QUEUE, "Hello Rabbitmq!");
    }

    @Test
    public void testConvertAndSend2() throws Exception {
        amqpTemplate.convertAndSend(EXCHANGE, ROUTING_KEY, "Hello Rabbitmq!");
        TimeUnit.SECONDS.sleep(60);
    }

    /**
     * 延迟投递需要rabbitmq-delayed-message-exchange插件支持
     */
    @Test
    public void testDelaySend() throws Exception {
        log.debug("====== 测试延迟消息 ======");
        MessageProperties props = new MessageProperties();
        props.setDelay(5000);
        props.setMessageId("MessageId1");
        props.setType("type1");
        props.setUserId("UserId1");
        props.setClusterId("ClusterId1");
        amqpTemplate.send(EXCHANGE, ROUTING_KEY, new Message("Hello Rabbitmq!".getBytes(StandardCharsets.UTF_8), props));
        Thread.currentThread().join();
    }

}


text:
/*
 * Source : http://sponge.noekeon.org/CSF-0.1.pdf
 */
#ifndef SPONGEFUNCTION_HPP
#define SPONGEFUNCTION_HPP

#include "Types.hpp"
#include "Padding.hpp"

namespace CryptoGL
{
    template <typename DataType>
    class SpongeFunction
    {
    protected:
        using DataTypeVector = Vector<DataType>;
        using DataTypeMatrix = Vector<DataTypeVector>;

        /* Constructor with output size, capacity and bitrate given as parameters. */
        SpongeFunction(const uint16_t hash_size, const uint16_t c, const uint16_t r, const uint8_t round)
            : bitrate(r), capacity(c), width(r + c), lane_width((r + c) / 25),
              block_size(200 * r / (r + c)), output_size(hash_size), rounds(round) { }

        /* Default constructor : b = 1600 => r = 1024 et c = 576. */
        SpongeFunction() : SpongeFunction(512, 576, 1024, 24) { }

        virtual ~SpongeFunction() { }

        virtual void applyAbsorbingPhase(const BytesVector &padded_message) = 0;
        virtual BytesVector applySqueezingPhase() = 0;
        virtual void F() = 0;

        /* Bitrate (or r in the spec.) : default = 1024. */
        const uint16_t bitrate;

        /* Capacity (or c in the spec.) : default = 576 bits. */
        const uint16_t capacity;

        /* width (or b in the spec.) : {25, 50, 100, 200, 400, 800, default = 1600}. */
        const uint16_t width;

        /* Calculated using width / 25. Default = 64. */
        const uint8_t lane_width;

        /* Block size is calculated using bitrate / lane_width * 8. */
        const uint8_t block_size;

        /* Possible output sizes are {224, 256, 384, 512} in bits. */
        const uint16_t output_size;

        /* Number of rounds following this formula : 2 * log_2(b / 25) + 12. */
        const uint8_t rounds;

        /* The state of the sponge construction. */
        DataTypeMatrix state;

    public:
        /* General encoding using the sponge construction. */
        BytesVector encode(BytesVector data)
        {
            state.resize(5);
            for (uint8_t x = 0; x < 5; ++x)
            {
                state[x].resize(5);
            }

            data = Padding::_10Star1(data, bitrate / 8);

            applyAbsorbingPhase(data);

            return applySqueezingPhase();
        }
    };
}

#endif


text:
=head1 NAME

Apache::FakeRequest - fake request object for debugging

=head1 Synopsis

  use Apache::FakeRequest;
  my $request = Apache::FakeRequest->new(method_name => 'value', ...);

=head1 Description

C<Apache::FakeRequest> is used to set up an empty Apache request
object that can be used for debugging.

The C<Apache::FakeRequest> methods just set internal variables of the
same name as the method and return the value of the internal
variables.  Initial values for methods can be specified when the
object is created.  The C<print> method prints to STDOUT.

Subroutines for Apache constants are also defined so that using
C<Apache::Constants> while debugging works, although the values of the
constants are hard-coded rather than extracted from the Apache source
code.

  #!/usr/bin/perl

  use Apache::FakeRequest ();
  use mymodule ();

  my $request = Apache::FakeRequest->new('get_remote_host'=>'foobar.com');
  mymodule::handler($request);

=head1 Authors

Doug MacEachern, with contributions from Andrew Ford
E<lt>A.Ford@ford-mason.co.ukE<gt>.

=cut


text:
ENT.Type 			= "anim"
ENT.Base 			= "base_gmodentity"
ENT.PrintName		= "Tiny Flamer"
ENT.Author			= "Paradukes + SlyFo"
ENT.Category		= "SBEP - Weapons"

ENT.Spawnable		= true
ENT.AdminSpawnable	= true
ENT.Owner			= nil
ENT.SPL				= nil
ENT.HPType			= "Tiny"
ENT.APPos			= Vector(0,0,0)
ENT.FTime			= 0
ENT.WInfo			= "Tiny Flamer"
ENT.Range 			= 400

function ENT:SetActive( val )
	if val ~= self.Entity:GetNetworkedBool("ClActive") then
		self.Entity:SetNetworkedBool("ClActive",val,true)
	end
end

function ENT:GetActive()
	return self.Entity:GetNetworkedBool("ClActive")
end


text:
using Contoso.Events.Data;
using Contoso.Events.Models;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Host;
using Microsoft.EntityFrameworkCore;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;

namespace Contoso.Events.Worker
{
    public static class ProcessDocuments
    {
        private static ConnectionManager _connection = new ConnectionManager();
        private static RegistrationContext _registrationsContext = _connection.GetCosmosContext();

        [FunctionName("ProcessDocuments")]
        public static async Task Run(string message, [Blob("signinsheets/output.docx", FileAccess.Write)] Stream blob, TraceWriter log)
        {
            log.Info($"Request received to generate sign-in sheet for event: {message}");

            using (MemoryStream stream = await ProcessStorageMessage(message))
            {
                byte[] byteArray = stream.ToArray();
                await blob.WriteAsync(byteArray, 0, byteArray.Length);
            }

            log.Info($"Request received to generate sign-in sheet for event: {message}");
        }

        private static async Task<MemoryStream> ProcessStorageMessage(string eventKey)
        {
            SignInDocumentGenerator documentGenerator = new SignInDocumentGenerator();

            using (EventsContext eventsContext = _connection.GetSqlContext())
            {
                await eventsContext.Database.EnsureCreatedAsync();
                await _registrationsContext.ConfigureConnectionAsync();

                Event eventEntry = await eventsContext.Events.SingleOrDefaultAsync(e => e.EventKey == eventKey);

                List<string> registrants = await _registrationsContext.GetRegistrantsForEvent(eventKey);

                MemoryStream stream = documentGenerator.CreateSignInDocument(eventEntry.Title, registrants);
                stream.Seek(0, SeekOrigin.Begin);

                eventEntry.SignInDocumentUrl = $"{eventKey}";
                await eventsContext.SaveChangesAsync();

                return stream;
            }
        }
    }
}


text:
@implementation CouponUserEntity

@end


text:
Palo Alto Networks Lambda Functions for ELB AutoScale Deployment
================================================================

The Lambda Functions implemented and published by Palo Alto Networks are
meant to work in conjunction with the ELB Auto Scaling Deployment on AWS.

At a high level, the goal of the lambda functions is to perform the initial
setup and the plumbing necessary to allow traffic from the internet (untrust
subnet) to the backend web tier (trust subnet) via the Palo Alto Networks
Next Generation Firewall. The policies on the PAN NGFW determine the traffic
that will be permitted to pass between the untrust and trust subnets.
Additionally, the lambda functions also handle the various actions required
when various events, such as autoscaling, occur which require the manipulation
of the firewalls.

Use Cases
+++++++++

1. Deploy Palo Alto Networks Next Generation Firewall in an auto scale
   configuration to handle unpredictable traffic patterns (spikes etc).

2. Deploy best practice architectures to secure multi-tier applications
   on AWS with Palo Alto Networks Next Generation Firewalls.

AWS Specific Deployment Options
+++++++++++++++++++++++++++++++

1. Palo Alto supports the ELB architecture to be deployed
   with optional NAT Gateways fronting back end infrastructure.
   The advantage of this configuration is to not require publicly
   routable IP addresses for various instances in the absence of the NAT
   gateway.

2. Alternatively, the ELB architecture can be deployed without NAT Gateways,
   in which case, public IP addresses will be created and assigned to the
   various nodes.

|
|
|

.. figure:: aws.png
    :align: center
    :alt: alternate text

    Fig 1. Palo Alto ELB Auto Scale Architecture

Lambda function objectives
++++++++++++++++++++++++++

    - Deploy ASG's and Bootstrap the Firewalls.
    - Deploy Lambda Functions to monitor the VIP's on the ILB.
    - Program the NAT rules on the PAN FW
    - Handle Auto Scale Events and take the necessary actions.
    - Handle the de-licensing of Firewalls when they are deleted.

Theory of Operation
+++++++++++++++++++

There are 4 main lambda functions that get deployed:

    - init
    - add_eni
    - sched_evt1
    - metrics

The two lambda functions that get deployed by the CFT are the first two listed above.

Init Lambda Function

    The InitLambda lambda function is responsible for the following functions:
    - deployment and configuration of the ```sched_evt1``` lambda function
    - handling creation, update and delete of the cloud formation template
    - validating the AMI-ID's of the PAN FW specified by the user

    When the init lambda function is triggered it validates that the AMI-ID of the PAN FW
    is valid and then proceeds to deploy the ```sched_evt1``` lambda function with all the
    required parameters. It should also be noted that the ```sched_evt1``` lambda function
    is configured to be triggered every minute. The rationale for the frequency is provided
    in the next section.

Sched_evt1 Lambda Function

    The primary objective of this lambda function is to probe (or describe / list) the IP addresses
    configured on the ILB, and for each and every IP address ensure that there is a corresponding
    ASG deployed. Conversely, if there exists an ASG without a corresponding IP address, the lambda function
    will delete the ASG.

    When a new ASG is created, callbacks to handle life-cycle hooks are also configured.
    Enabling the life-cycle hooks allows for the ```add_eni``` lambda function to take various
    actions depending upon the life cycle action. The specific actions taken will be described in the section
    which describes the ```add_eni``` lambda function description.

Add_ENI Lambda Function

    The ```add_eni``` lambda function gets invoked by a life-cycle hook trigger. The lambda function gets
    triggered when an instance in an ASG either launches or terminates. When handling an instance launch
    life-cycle hook action, the lambda function creates and attaches ENI's for the management and trust
    subnets. The lambda function is also responsible for the creation Elastic IP's if necessary and attaching
    the EIP's to the ENI's.

    Additionally, this lambda function also creates or deletes, as the case maybe, the ```metrics``` lambda
    function. The details of the ```metrics``` lambda function are described below.

Metrics Lambda Function

    The ```metrics``` lambda function is configured to be invoked every second. The objective of this function
    is to query the firewalls for various defined metrics via the XML API. The metrics retrieved from the firewall
    are subsequently consumed by the AWS Auto Scaling framework, in order to make decisions with regard to either
    keeping the number of firewalls constant, or increasing or decreasing the number of firewalls as the case maybe.

Availability Zones
++++++++++++++++++

The ELB Autoscale Deployments require at a minimum two availability zones to be deployed into. Consequently,
the lambda functions will spin up auto scale groups to match the desired capacities in all of the specified
availability zones.

Auto Scaling Parameters
+++++++++++++++++++++++

Autoscaling on AWS occurs by defining and advertising the parameters that will be used by the AWS framework to make
auto scaling decisions. The parameters currently defined are:

    - ActiveSessions
    - DataPlaneBufferUtilization
    - DataPlaneCPUUtilization
    - GPGatewayUtilization
    - SessionUtilization

The AWS requires users to specify a ```high``` threshold and a ```low``` threshold for each parameters. When one of the
parameters breaches the high threshold mark, a scale out event is triggered. Consequently, when one of the parameters
breaches the low threshold mark, a scale in event is triggered.

Panorama
++++++++

The use of a Panorama is optional along with the autoscaling deployment. However, it is possible to associate
a firewall with the Panorama. Panorama configuration parameters such as the IP among others can be specified
in the ```init-cfg``` file.

Logging
+++++++

The logs from the lambda functions are available as Cloud Watch Logs. Log groups are created on cloud watch,
which are prepended with the stack name.

.. note:: The logging level for the CFT stack can be modified in the following manner:

   - Create a queue on SQS, and name it with the stack name
   - Send a message with the desired logging level.

Inputs to the Lambda Functions
++++++++++++++++++++++++++++++

    Identify the various deployment artifacts such as:

    - ServiceToken
    - StackName
    - Region
    - VPCID
    - SubnetIDMgmt
    - SubnetIDUntrust
    - SubnetIDTrust
    - MgmtSecurityGroup
    - UntrustSecurityGroup
    - TrustSecurityGroup
    - VPCSecurityGroup
    - KeyName
    - ELBName
    - ILBName
    - FWInstanceType
    - SSHLocation
    - MaximumInstancesASG
    - ScaleUpThreshold
    - ScaleDownThreshold
    - ScalingParameter
    - ScalingPeriod
    - ImageID
    - LambdaENISNSTopic
    - MinInstancesASG
    - FirewallBootstrapRole
    - LambdaExecutionRole
    - ASGNotifierRole
    - ASGNotifierRolePolicy
    - MasterS3Bucket
    - PanS3BucketTpl
    - PanS3KeyTpl
    - KeyPANWFirewall
    - KeyPANWPanorama
    - NATGateway
    - SubnetIDNATGW
    - SubnetIDLambda
    - AddENILambda
    - InitLambda
    - Version
    - KeyDeLicense
    - LambdaENIQueue