text:
<?php
namespace RegexpTrie\Test;

use PHPUnit\Framework\TestCase;
use RegexpTrie\RegexpTrie;

/**
 * RegexpTrie Testcase
 */
class RegexpTrieTest extends TestCase
{
    public function testUnion1()
    {
        $regexpTrie = RegexpTrie::union([
            'foo', 'bar', 'baz'
        ]);
        $regexp = $regexpTrie->toRegexp();

        $this->assertEquals(1, preg_match($regexp, 'foo'));
        $this->assertEquals(1, preg_match($regexp, 'bar'));
        $this->assertEquals(1, preg_match($regexp, 'baz'));
        $this->assertEquals(0, preg_match($regexp, 'FOO'));
    }

    public function testUnion2()
    {
        $regexpTrie = RegexpTrie::union([
            'foo', 'foobar', 'foobaz',
        ]);
        $regexp = '/\b' . $regexpTrie->build() . '\b/';

        $this->assertEquals(1, preg_match($regexp, 'foo'));
        $this->assertEquals(1, preg_match($regexp, 'foobar'));
        $this->assertEquals(1, preg_match($regexp, 'foobaz'));
        $this->assertEquals(1, preg_match($regexp, 'text foo text'));
        $this->assertEquals(1, preg_match($regexp, 'text foobar text'));
        $this->assertEquals(1, preg_match($regexp, 'text foobaz text'));
        $this->assertEquals(0, preg_match($regexp, 'bar'));
        $this->assertEquals(0, preg_match($regexp, 'baz'));
        $this->assertEquals(0, preg_match($regexp, 'text foobax text'));
    }

    public function testUnionFlatten()
    {
        $regexpTrie = RegexpTrie::union([
            ["foo", "bar"],
            ["hoge", "fuga"],
        ]);
        $regexp = $regexpTrie->toRegexp();

        $this->assertEquals(1, preg_match($regexp, 'foo'));
        $this->assertEquals(1, preg_match($regexp, 'bar'));
        $this->assertEquals(1, preg_match($regexp, 'hoge'));
        $this->assertEquals(1, preg_match($regexp, 'fuga'));
    }

    public function testUnionRx()
    {
        $this->assertEquals('/a/', RegexpTrie::union(['a'])->toRegexp());
        $this->assertEquals('/aa?/', RegexpTrie::union(['a', 'aa'])->toRegexp());
        $this->assertEquals('/[ab]/', RegexpTrie::union(['a', 'b'])->toRegexp());
        $this->assertEquals('/(?:foo|bar)/', RegexpTrie::union(['foo', 'bar'])->toRegexp());
        $this->assertEquals('/(?:foo|ba[rz])/', RegexpTrie::union(['foo', 'bar', 'baz'])->toRegexp());
    }

    public function testUnion()
    {
        $this->assertEquals('a', RegexpTrie::union(['a'])->build());
        $this->assertEquals('aa?', RegexpTrie::union(['a', 'aa'])->build());
        $this->assertEquals('[ab]', RegexpTrie::union(['a', 'b'])->build());
        $this->assertEquals('(?:foo|bar)', RegexpTrie::union(['foo', 'bar'])->build());
        $this->assertEquals('(?:foo|ba[rz])', RegexpTrie::union(['foo', 'bar', 'baz'])->build());
    }

    public function testUnionEmpty()
    {
        $this->assertNull(RegexpTrie::union()->build());
    }

    public function testInstance()
    {
        $regexpTrie = new RegexpTrie();
        $regexpTrie->add('foo')->add('bar')->add('baz');

        $this->assertEquals('/(?:foo|ba[rz])/', $regexpTrie->toRegexp());
    }

    public function testInstanceAddEmpty()
    {
        try {
            $regexpTrie = new RegexpTrie();
            $regexpTrie->add('');
        } catch (\InvalidArgumentException $ex) {
            $this->assertEquals('$str must be string.', $ex->getMessage());
        }
    }

    public function testUnicodeCharacter1()
    {
        $regexpTrie = new RegexpTrie();
        $regexpTrie->add('of 1918–19');
        $regexpTrie->add('1918–19');
        $regexpTrie->add('1918');
        $regexpTrie->add('19');

        $this->assertEquals('/(?:of 1918–19|19(?:18(?:–19)?)?)/', $regexpTrie->toRegexp());
    }

    public function testUnicodeCharacter2()
    {
        $regexpTrie = new RegexpTrie();
        $regexpTrie->add('こんにちは');
        $regexpTrie->add('こんばんは');

        $this->assertEquals('/こん(?:にちは|ばんは)/', $regexpTrie->toRegexp());
    }
}


text:
The Dash2 application is made of a number of parts intended to keep it more flexible and to separate concerns so that parts can be replaced with new metadata and other engines to customize it.  Some basic information about the project and architechiture is available at [the Dash Website](https://dash.ucop.edu/stash/about), but this document focuses on getting Dash up and running for development.

## The ingredients

You'll need the following parts installed and configured on a (local) UI development server to do development on the full UI application.  Don't worry, there are more detailed installation instructions in other sections below and this is meant to give an overview of the larger dependencies to configure.

- (Recommended) A ruby version manager such as [rbenv](https://github.com/rbenv/rbenv) or [rvm](https://rvm.io/)
- The [bare dashv2 application](https://github.com/CDLUC3/dashv2) cloned from github
- The [stash](https://github.com/CDLUC3/stash) repository cloned from github
- A separate directory of configuration files called *dash2-config* which you can start by cloning [dash2-config-example](https://github.com/CDLUC3/dash2-config-example) and modifying to fit your settings.

You'll also need the following components installed either on the same server or on separate servers for all the application features to work:

- MySQL (with the database specified in the database.yml created and using utf8mb4 character set by default)
- SOLR (with a geoblacklight schema and core installed)
- A storage repository that supports SWORD will be needed to submit documents to the repository and even with SWORD support, the code may need some customization for others besides the Merritt repository.
- A DOI minting service such as EZID to mint DOIs.

The application also requires some means to log in outside of a development environment. You'd want to configure a log in method for each application tenant from these:

- Google login
- Shibboleth login
- ORCID login (coming soon and required for ORCID lookup in the metadata page)

## Installing the code and a base config

Open a (bash) shell and type these commands inside a directory where you want to work with this code. These will clone the development code and an example config.

```
git clone https://github.com/CDLUC3/dashv2
git clone https://github.com/CDLUC3/stash
git clone https://github.com/CDLUC3/dash2-config-example.git dash2-config
```

You should end up with a directory structure that looks like this one.

```
├── dash2-config
├── dashv2
└── stash
    ├── stash-harvester
    ├── stash-merritt
    ├── stash-sword
    ├── stash-wrapper
    ├── stash_datacite
    ├── stash_discovery
    └── stash_engine
```

Your config files are currently in a seperate directory from your application. It can be handy to keep them apart from the application so that you can back them up or commit them to a private repository for configuration separate from the application.  The application will need to have these configuration files symlinked into the application. to symlink the files in using a bash shell, type these commands:

```
cd dashv2
mkdir config/tenants
./symlink_config.sh
```

After you add or remove any configuration file, such as a yml file in the tenants directory, you will want to run the script above again update symlinks to config in the application.

## Installing MySQL and Solr
### MySQL

The procedure to install MySQL and Solr vary from one operating system to another, but this guide shows a way to configure it in Ubuntu linux:

```
# installing MySQL in an Ubuntu Linux distro, make note of the root password you set while installing
sudo apt-get install mysql-server mysql-client libmysqlclient-dev

# make sure MySQL is started
sudo service mysql start

# connect to mysql, note the <username> is probably root in a new installation
mysql -u <username> -p

# if the above doesn't work, try
sudo mysql -u root

# create the dash database
CREATE DATABASE dash CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

# add a user to the database
CREATE USER 'dashuser'@'%' IDENTIFIED BY '<my-password>';

# grant the user privileges on dash database
GRANT ALL PRIVILEGES ON dash . * TO 'dashuser'@'%';
FLUSH PRIVILEGES;

# To exit the MySQL client, type *exit* or press ctrl-d

```

Now edit the dash2-config/config/database.yml file to fill in the *dashuser* and password you set above in the development environment for that configuration file.

### Solr
Solr requires a Java runtime.  Try *java -version* and if it says that "java can be found in the following packages" rather than giving you a version you probably need to install java with a command like *sudo apt-get install default-jre* .

```
# Download Solr using wget
wget http://archive.apache.org/dist/lucene/solr/5.5.3/solr-5.5.3.tgz

# Extract the Solr files to a directory without the version in the name
mkdir -p solr && tar zxvf solr-5.5.3.tgz -C solr --strip 1

cd solr

# start Solr with this command, you can stop it later by using stop instead of start
bin/solr start

# create the geoblacklight core
bin/solr create -c geoblacklight

# download and copy the geoblacklight schema to the core
mkdir tmp && cd tmp
wget -L https://github.com/geoblacklight/geoblacklight-schema/archive/v0.3.2.tar.gz
tar zxvf v0.3.2.tar.gz
cp geoblacklight-schema-0.3.2/conf/* ../server/solr/geoblacklight/conf

# restart the Solr server
cd .. && bin/solr restart
```

Make sure Solr is working by going to  [http://localhost:8983](http://localhost:8983). You should see a Solr admin page.

![Solr screen](images/solr1.png)

Verify Solr is set up correctly from the Admin UI:

1. Choose the geoblacklight core from the core selector list.
![core selctor](images/solr2.png)

2. You can then click the *query* sidebar tab and scroll down to the bottom of the form to submit a blank query.  While the document will not return any results yet because there are no documents in SOLR, you should see it execute and you can verify that Solr queries are running.
![query test](images/solr3.png)

(Optional, but recommended) Add a sample record to match the sample database record (see below).

1. Click the *Documents* tab on the left side.
![Documents](images/solr4.png)

2. Find the file *dash2-config/sample\_data/sample\_record.json* in the dash2-config repo.  Open the file in a text editor, select all the text and copy it.

3. Paste the text into the *Document(s)* box on the page.
![json pasted](images/solr5.png)
4. Click *Submit Document* and be sure it shows a status of success.
![success status](images/solr6.png)

## Getting the Rails application running

I'd *strongly* recommend installing [rbenv](https://github.com/rbenv/rbenv) for a local development asenvironment as a way to manage Ruby versions.  Follow the installation instructions given on the rbenv site to install it, but make sure the `rbenv init` command is run in every shell (e.g., add it to .bashrc). Install the [Ruby build plugin](https://github.com/rbenv/ruby-build#readme) to make it easy to install different Ruby versions as needed.

*Note for OSX:* Ensure the command-line XCode utilities are installed. `xcode-select --install`

```
# make sure some basic libraries are installed that are probably required later (Ubuntu example)
sudo apt-get install libxml2 libxml2-dev patch curl

cd dashv2
rbenv install $(cat .ruby-version) # installs the ruby-version set in the .ruby-version file

# update your rubygems version
gem update --system

# install bundler to handle gem dependencies
gem install bundler

# now install the gem libraries needed for the application
bundle install

# run the migrations to set up the database tables
bundle exec rake db:migrate

# start your rails server for local development
rails s
```

If you want to view sample data, then insert a sample record into the database (recommended).

```
# connect to mysql, note the <username> is probably root in a new installation
mysql -u <username> -p

# Use the following two lines.
USE dash;
source ../dash2-config/sample_data/sample_record.sql;

# To exit the MySQL client, type *exit* or press ctrl-d
```

To configure where the search enterface draws its data from, modify the dashv2 app config/blacklight.yml to change the endpoint for the development server.  When running locally, the default server is development.

## Testing basic functionality

### Explore the datasets
Open your web browser and go to [http://localhost:3000](http://localhost:3000) to see the homepage.

The *Explore Data* link will allow you to search and view your dataset, if you imported a sample record.

![Explore Splash](images/explore1.png)

![Search Results](images/explore2.png)

![Dataset Page](images/explore3.png)

### Use the developer login

Until a tenant is configured and login methods are set up you can use the developer login to access password protected parts of the application for testing or development. The developer login is only available in the development and test environments and is a useful way to test functionality and tenant configuration without having to have a new domain name registered for each tenant (very useful on a local or development machine).  It is also useful for pre-testing a tenant and submitting test records for that tenant into a repository without having to obtain an account for the authentication method (such as Shibboleth with a campus account) that a tenant normally uses.

To use the developer login:

1. Click the *More Dash Sites* drop-down menu and then click *developer login (only development)*.
![More Dash Sites](images/dev_login1.png)

2. In the login screen enter a name, email address and a domain name.  The domain name should allow the *domain_regex* regular expression from one of your tenant configurations to match the string you enter as the test domain.
![Developer Login Page](images/dev_login2.png).
3. Until you log in again or your cookies expire, the user interface will display items specific to the tenant you entered the domain name for (such as the logo, help and other things configured for that tenant). It will also act as that tenant when submitting data to a configured repository.

### Enter dataset metadata, upload files and preview the landing page

After you log in, you will be able to start entering metadata and uploading files for a dataset by clicking the *My Datasets* menu link.

Metadata entry, file uploading and landing page preview should be functional.

We have enabled submission to a SWORD-enabled Merritt repository, but have only implemented relevant parts of the SWORD specification and not every functionality in the specification has been implemented.

## Next steps in configuration

### Repository and identifier service configuration

The Stash platform requires an implementation of the [Stash::Repo](https://github.com/CDLUC3/stash/tree/master/lib/stash/repo)
API for identifier assignment and submission to repositories.

Dash2 uses CDL's EZID service for identifier assignment and stores datasets in the [Merritt](https://merritt.cdlib.org/) repository.
The Stash::Repo implementation is provided by the [stash-merritt](https://github.com/CDLUC3/stash-merritt) gem, which is included in the application [Gemfile](../../Gemfile)
and declared by the `repository:` key in [`app_config.yml`](https://github.com/CDLUC3/dash2-config-example/blob/development/config/app_config.yml).
EZID and Merritt/SWORD must be configured for each tenant in the apporpriate `tenants/*.yml` file, e.g.

```yaml
repository: # change me: you'll probably have to change all the following indented values and only if using Merritt repo
    type: merritt
    domain: merritt-repo-dev-example.cdlib.org
    endpoint: "http://uc3-mrtsword-dev.cdlib.org:39001/mrtsword/collection/my_collection_id"
    username: "submitter_username"
    password: "submitter_password"
 identifier_service: # change me: the identifier service is EZID here, may need to change this
    shoulder: "doi:10.5072/FK2"
    account: my_account_name
    password: my_account_password
    id_scheme: doi
    owner: null
```

redpajama_set_name: RedPajamaGithub


text:
import { ProxyIdentifier } from 'vs/workbench/services/extensions/node/proxyIdentifier';
import { CharCode } from 'vs/base/common/charCode';
import { IExtHostContext } from 'vs/workbench/api/node/extHost.protocol';
import { isThenable } from 'vs/base/common/async';

export function SingleProxyRPCProtocol(thing: any): IExtHostContext {
	return {
		remoteAuthority: null!,
		getProxy<T>(): T {
			return thing;
		},
		set<T, R extends T>(identifier: ProxyIdentifier<T>, value: R): R {
			return value;
		},
		assertRegistered: undefined!
	};
}

export class TestRPCProtocol implements IExtHostContext {

	public remoteAuthority = null!;

	private _callCountValue: number = 0;
	private _idle?: Promise<any>;
	private _completeIdle: Function;

	private readonly _locals: { [id: string]: any; };
	private readonly _proxies: { [id: string]: any; };

	constructor() {
		this._locals = Object.create(null);
		this._proxies = Object.create(null);
	}

	private get _callCount(): number {
		return this._callCountValue;
	}

	private set _callCount(value: number) {
		this._callCountValue = value;
		if (this._callCountValue === 0) {
			if (this._completeIdle) {
				this._completeIdle();
			}
			this._idle = undefined;
		}
	}

	sync(): Promise<any> {
		return new Promise<any>((c) => {
			setTimeout(c, 0);
		}).then(() => {
			if (this._callCount === 0) {
				return undefined;
			}
			if (!this._idle) {
				this._idle = new Promise<any>((c, e) => {
					this._completeIdle = c;
				});
			}
			return this._idle;
		});
	}

	public getProxy<T>(identifier: ProxyIdentifier<T>): T {
		if (!this._proxies[identifier.sid]) {
			this._proxies[identifier.sid] = this._createProxy(identifier.sid);
		}
		return this._proxies[identifier.sid];
	}

	private _createProxy<T>(proxyId: string): T {
		let handler = {
			get: (target: any, name: string) => {
				if (!target[name] && name.charCodeAt(0) === CharCode.DollarSign) {
					target[name] = (...myArgs: any[]) => {
						return this._remoteCall(proxyId, name, myArgs);
					};
				}
				return target[name];
			}
		};
		return new Proxy(Object.create(null), handler);
	}

	public set<T, R extends T>(identifier: ProxyIdentifier<T>, value: R): R {
		this._locals[identifier.sid] = value;
		return value;
	}

	protected _remoteCall(proxyId: string, path: string, args: any[]): Promise<any> {
		this._callCount++;

		return new Promise<any>((c) => {
			setTimeout(c, 0);
		}).then(() => {
			const instance = this._locals[proxyId];
			// pretend the args went over the wire... (invoke .toJSON on objects...)
			const wireArgs = simulateWireTransfer(args);
			let p: Promise<any>;
			try {
				let result = (<Function>instance[path]).apply(instance, wireArgs);
				p = isThenable(result) ? result : Promise.resolve(result);
			} catch (err) {
				p = Promise.reject(err);
			}

			return p.then(result => {
				this._callCount--;
				// pretend the result went over the wire... (invoke .toJSON on objects...)
				const wireResult = simulateWireTransfer(result);
				return wireResult;
			}, err => {
				this._callCount--;
				return Promise.reject(err);
			});
		});
	}

	public assertRegistered(identifiers: ProxyIdentifier<any>[]): void {
		throw new Error('Not implemented!');
	}
}

function simulateWireTransfer<T>(obj: T): T {
	if (!obj) {
		return obj;
	}
	return JSON.parse(JSON.stringify(obj));
}


text:
package org.jnode.fs.spi;

import java.security.Principal;
import java.security.acl.Group;

import org.jnode.fs.FSAccessRights;
import org.jnode.fs.FileSystem;

import sun.security.acl.GroupImpl;

import com.sun.security.auth.UserPrincipal;

/**
 *
 * @author Fabien DUMINY (fduminy at jnode.org)
 *
 */
public class UnixFSAccessRights implements FSAccessRights {
    private final FileSystem filesystem;

    private Principal owner;
    private Group group;

    private final Rights ownerRights = new Rights(true, true, true);
    private final Rights groupRights = new Rights();
    private final Rights worldRights = new Rights();

    public UnixFSAccessRights(FileSystem filesystem) {
        if (filesystem == null) {
            throw new NullPointerException("filesystem can't be null");
        }
        this.filesystem = filesystem;

        // TODO manages users & groups in JNode
        owner = new UserPrincipal("root");
        group = new GroupImpl("admins");
        group.addMember(owner);
    }

    private Principal getUser() {
        // TODO manages users & groups in JNode
        // we should find the user from the context
        return owner;
    }

    private Rights getUserRights() {
        Principal user = getUser();

        Rights rights = worldRights;
        if (owner.equals(user)) {
            rights = ownerRights;
        } else if (group.isMember(user)) {
            rights = groupRights;
        }

        return rights;
    }

    public boolean canExecute() {
        return getUserRights().isExecute();
    }

    public boolean canRead() {
        return getUserRights().isRead();
    }

    public boolean canWrite() {
        return getUserRights().isWrite();
    }

    public Principal getOwner() {
        return owner;
    }

    public boolean setExecutable(boolean enable, boolean owneronly) {
        if (!owner.equals(getUser())) {
            return false;
        }

        ownerRights.setExecute(enable);
        if (!owneronly) {
            groupRights.setExecute(enable);
            worldRights.setExecute(enable);
        }
        return true;
    }

    public boolean setReadable(boolean enable, boolean owneronly) {
        if (!owner.equals(getUser())) {
            return false;
        }

        ownerRights.setRead(enable);
        if (!owneronly) {
            groupRights.setRead(enable);
            worldRights.setRead(enable);
        }
        return true;
    }

    public boolean setWritable(boolean enable, boolean owneronly) {
        if (!owner.equals(getUser())) {
            return false;
        }

        ownerRights.setWrite(enable);
        if (!owneronly) {
            groupRights.setWrite(enable);
            worldRights.setWrite(enable);
        }
        return true;
    }

    public FileSystem getFileSystem() {
        return filesystem;
    }

    public boolean isValid() {
        return true;
    }

    private static class Rights {
        private boolean read = false;
        private boolean write = false;
        private boolean execute = false;

        public Rights() {
            this(false, false, false);
        }

        public Rights(boolean read, boolean write, boolean execute) {
            this.read = read;
            this.write = write;
            this.execute = execute;
        }

        public boolean isRead() {
            return read;
        }

        public void setRead(boolean read) {
            this.read = read;
        }

        public boolean isWrite() {
            return write;
        }

        public void setWrite(boolean write) {
            this.write = write;
        }

        public boolean isExecute() {
            return execute;
        }

        public void setExecute(boolean execute) {
            this.execute = execute;
        }
    }
}


text:
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.Collections.Immutable;
using System.Diagnostics;
using System.IO;
using System.Reflection.Metadata;
using Microsoft.CodeAnalysis.PooledObjects;
using Microsoft.CodeAnalysis;

namespace Roslyn.Utilities
{
    /// <summary>
    /// A write-only memory stream backed by a <see cref="BlobBuilder"/>.
    /// </summary>
    internal sealed class BlobBuildingStream : Stream
    {
        private static readonly ObjectPool<BlobBuildingStream> s_pool = new ObjectPool<BlobBuildingStream>(() => new BlobBuildingStream());
        private readonly BlobBuilder _builder;

        /// <summary>
        /// The chunk size to be used by the underlying BlobBuilder.
        /// </summary>
        /// <remarks>
        /// The current single use case for this type is embedded sources in PDBs.
        ///
        /// 32 KB is:
        ///
        /// * Large enough to handle 99.6% all VB and C# files in Roslyn and CoreFX
        ///   without allocating additional chunks.
        ///
        /// * Small enough to avoid the large object heap.
        ///
        /// * Large enough to handle the files in the 0.4% case without allocating tons
        ///   of small chunks. Very large source files are often generated in build
        ///   (e.g. Syntax.xml.Generated.vb is 390KB compressed!) and those are actually
        ///   attractive candidates for embedding, so we don't want to discount the large
        ///   case too heavily.)
        ///
        /// * We pool the outer BlobBuildingStream but only retain the first allocated chunk.
        /// </remarks>
        public const int ChunkSize = 32 * 1024;

        public override bool CanWrite => true;
        public override bool CanRead => false;
        public override bool CanSeek => false;
        public override long Length => _builder.Count;

        public static BlobBuildingStream GetInstance()
        {
            return s_pool.Allocate();
        }

        private BlobBuildingStream()
        {
            // NOTE: We pool the wrapping BlobBuildingStream, but not individual chunks.
            // The first chunk will be reused, but any further chunks will be freed when we're done building blob.
            _builder = new BlobBuilder(ChunkSize);
        }

        public override void Write(byte[] buffer, int offset, int count)
        {
            _builder.WriteBytes(buffer, offset, count);
        }

        public override void WriteByte(byte value)
        {
            _builder.WriteByte(value);
        }

        public void WriteInt32(int value)
        {
            _builder.WriteInt32(value);
        }

        public Blob ReserveBytes(int byteCount)
        {
            return _builder.ReserveBytes(byteCount);
        }

        public ImmutableArray<byte> ToImmutableArray()
        {
            return _builder.ToImmutableArray();
        }

        public void Free()
        {
            _builder.Clear();  // frees all but first chunk
            s_pool.Free(this); // return first chunk to pool
        }

        public override void Flush()
        {
        }

        protected override void Dispose(bool disposing)
        {
            Debug.Assert(disposing);
            Free();
        }

        public override long Seek(long offset, SeekOrigin origin)
        {
            throw new NotSupportedException();
        }

        public override int Read(byte[] buffer, int offset, int count)
        {
            throw new NotSupportedException();
        }

        public override void SetLength(long value)
        {
            throw new NotSupportedException();
        }

        public override long Position
        {
            get { throw new NotSupportedException(); }
            set { throw new NotSupportedException(); }
        }

    }
}


text:
package org.apache.calcite.rex;

/**
 * Default implementation of {@link RexBiVisitor}, which visits each node but
 * does nothing while it's there.
 *
 * @param <R> Return type from each {@code visitXxx} method
 * @param <P> Payload type
 */
public class RexBiVisitorImpl<R, P> implements RexBiVisitor<R, P> {
  //~ Instance fields --------------------------------------------------------

  protected final boolean deep;

  //~ Constructors -----------------------------------------------------------

  protected RexBiVisitorImpl(boolean deep) {
    this.deep = deep;
  }

  //~ Methods ----------------------------------------------------------------

  public R visitInputRef(RexInputRef inputRef, P arg) {
    return null;
  }

  public R visitLocalRef(RexLocalRef localRef, P arg) {
    return null;
  }

  public R visitLiteral(RexLiteral literal, P arg) {
    return null;
  }

  public R visitOver(RexOver over, P arg) {
    R r = visitCall(over, arg);
    if (!deep) {
      return null;
    }
    final RexWindow window = over.getWindow();
    for (RexFieldCollation orderKey : window.orderKeys) {
      orderKey.left.accept(this, arg);
    }
    for (RexNode partitionKey : window.partitionKeys) {
      partitionKey.accept(this, arg);
    }
    window.getLowerBound().accept(this, arg);
    window.getUpperBound().accept(this, arg);
    return r;
  }

  public R visitCorrelVariable(RexCorrelVariable correlVariable, P arg) {
    return null;
  }

  public R visitCall(RexCall call, P arg) {
    if (!deep) {
      return null;
    }

    R r = null;
    for (RexNode operand : call.operands) {
      r = operand.accept(this, arg);
    }
    return r;
  }

  public R visitDynamicParam(RexDynamicParam dynamicParam, P arg) {
    return null;
  }

  public R visitRangeRef(RexRangeRef rangeRef, P arg) {
    return null;
  }

  public R visitFieldAccess(RexFieldAccess fieldAccess, P arg) {
    if (!deep) {
      return null;
    }
    final RexNode expr = fieldAccess.getReferenceExpr();
    return expr.accept(this, arg);
  }

  public R visitSubQuery(RexSubQuery subQuery, P arg) {
    if (!deep) {
      return null;
    }

    R r = null;
    for (RexNode operand : subQuery.operands) {
      r = operand.accept(this, arg);
    }
    return r;
  }

  @Override public R visitTableInputRef(RexTableInputRef ref, P arg) {
    return null;
  }

  @Override public R visitPatternFieldRef(RexPatternFieldRef fieldRef, P arg) {
    return null;
  }
}


text:
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics;
using System.Linq;
using Microsoft.CodeAnalysis.Text;
using Microsoft.CodeAnalysis.PooledObjects;

namespace Microsoft.CodeAnalysis
{
    /// <summary>
    /// The LineDirectiveMap is created to enable translating positions, using the #line directives
    /// in a file. The basic implementation creates an ordered array of line mapping entries, one
    /// for each #line directive in the file (plus one at the beginning). If the file has no
    /// directives, then the array has just one element in it. To map line numbers, a binary search
    /// of the mapping entries is done and nearest line mapping is applied.
    /// </summary>
    internal abstract partial class LineDirectiveMap<TDirective>
        where TDirective : SyntaxNode
    {
        internal readonly ImmutableArray<LineMappingEntry> Entries;

        // Get all active #line directives under trivia into the list, in source code order.
        protected abstract bool ShouldAddDirective(TDirective directive);

        // Given a directive and the previous entry, create a new entry.
        protected abstract LineMappingEntry GetEntry(TDirective directive, SourceText sourceText, LineMappingEntry previous);

        // Creates the first entry with language specific content
        protected abstract LineMappingEntry InitializeFirstEntry();

        protected LineDirectiveMap(SyntaxTree syntaxTree)
        {
            // Accumulate all the directives, in source code order
            var syntaxRoot = (SyntaxNodeOrToken)syntaxTree.GetRoot();
            IList<TDirective> directives = syntaxRoot.GetDirectives<TDirective>(filter: ShouldAddDirective);
            Debug.Assert(directives != null);

            // Create the entry map.
            Entries = CreateEntryMap(syntaxTree, directives);
        }

        // Given a span and a default file name, return a FileLinePositionSpan that is the mapped
        // span, taking into account line directives.
        public FileLinePositionSpan TranslateSpan(SourceText sourceText, string treeFilePath, TextSpan span)
        {
            var unmappedStartPos = sourceText.Lines.GetLinePosition(span.Start);
            var unmappedEndPos = sourceText.Lines.GetLinePosition(span.End);
            var entry = FindEntry(unmappedStartPos.Line);

            return TranslateSpan(entry, treeFilePath, unmappedStartPos, unmappedEndPos);
        }

        protected FileLinePositionSpan TranslateSpan(in LineMappingEntry entry, string treeFilePath, LinePosition unmappedStartPos, LinePosition unmappedEndPos)
        {
            string path = entry.MappedPathOpt ?? treeFilePath;
            var span = entry.State == PositionState.RemappedSpan ?
                TranslateEnhancedLineDirectiveSpan(entry, unmappedStartPos, unmappedEndPos) :
                TranslateLineDirectiveSpan(entry, unmappedStartPos, unmappedEndPos);
            return new FileLinePositionSpan(path, span, hasMappedPath: entry.MappedPathOpt != null);
        }

        private static LinePositionSpan TranslateLineDirectiveSpan(in LineMappingEntry entry, LinePosition unmappedStartPos, LinePosition unmappedEndPos)
        {
            return new LinePositionSpan(translatePosition(entry, unmappedStartPos), translatePosition(entry, unmappedEndPos));

            static LinePosition translatePosition(in LineMappingEntry entry, LinePosition unmapped)
            {
                int mappedLine = unmapped.Line - entry.UnmappedLine + entry.MappedLine;
                return (mappedLine == -1) ? new LinePosition(unmapped.Character) : new LinePosition(mappedLine, unmapped.Character);
            }
        }

        private static LinePositionSpan TranslateEnhancedLineDirectiveSpan(in LineMappingEntry entry, LinePosition unmappedStartPos, LinePosition unmappedEndPos)
        {
            // A span starting on the first line, at or before 'UnmappedCharacterOffset' is
            // mapped to the entire 'MappedSpan', regardless of the size of the unmapped span,
            // even if the unmapped span ends before 'UnmappedCharacterOffset'.
            if (unmappedStartPos.Line == entry.UnmappedLine &&
                unmappedStartPos.Character <= entry.UnmappedCharacterOffset.GetValueOrDefault())
            {
                return entry.MappedSpan;
            }

            // A span starting on the first line after 'UnmappedCharacterOffset', or starting on
            // a subseqent line, is mapped to a span of corresponding size.
            return new LinePositionSpan(translatePosition(entry, unmappedStartPos), translatePosition(entry, unmappedEndPos));

            static LinePosition translatePosition(in LineMappingEntry entry, LinePosition unmapped)
            {
                return new LinePosition(
                    unmapped.Line - entry.UnmappedLine + entry.MappedSpan.Start.Line,
                    unmapped.Line == entry.UnmappedLine ?
                        entry.MappedSpan.Start.Character + unmapped.Character - entry.UnmappedCharacterOffset.GetValueOrDefault() :
                        unmapped.Character);
            }
        }

        /// <summary>
        /// Determines whether the position is considered to be hidden from the debugger or not.
        /// </summary>
        public abstract LineVisibility GetLineVisibility(SourceText sourceText, int position);

        /// <summary>
        /// Combines TranslateSpan and IsHiddenPosition to not search the entries twice when emitting sequence points
        /// </summary>
        internal abstract FileLinePositionSpan TranslateSpanAndVisibility(SourceText sourceText, string treeFilePath, TextSpan span, out bool isHiddenPosition);

        /// <summary>
        /// Are there any hidden regions in the map?
        /// </summary>
        /// <returns>True if there's at least one hidden region in the map.</returns>
        public bool HasAnyHiddenRegions()
        {
            return this.Entries.Any(e => e.State == PositionState.Hidden);
        }

        // Find the line mapped entry with the largest unmapped line number <= lineNumber.
        protected LineMappingEntry FindEntry(int lineNumber)
        {
            int r = FindEntryIndex(lineNumber);

            return this.Entries[r];
        }

        // Find the index of the line mapped entry with the largest unmapped line number <= lineNumber.
        protected int FindEntryIndex(int lineNumber)
        {
            int r = Entries.BinarySearch(new LineMappingEntry(lineNumber));
            return r >= 0 ? r : ((~r) - 1);
        }

        // Given the ordered list of all directives in the file, return the ordered line mapping
        // entry for the file. This always starts with the null mapped that maps line 0 to line 0.
        private ImmutableArray<LineMappingEntry> CreateEntryMap(SyntaxTree tree, IList<TDirective> directives)
        {
            var entries = ArrayBuilder<LineMappingEntry>.GetInstance(directives.Count + 1);

            var current = InitializeFirstEntry();
            entries.Add(current);

            if (directives.Count > 0)
            {
                var sourceText = tree.GetText();
                foreach (var directive in directives)
                {
                    current = GetEntry(directive, sourceText, current);
                    entries.Add(current);
                }
            }

#if DEBUG
            // Make sure the entries array is correctly sorted.
            for (int i = 0; i < entries.Count - 1; ++i)
            {
                Debug.Assert(entries[i].CompareTo(entries[i + 1]) < 0);
            }
#endif

            return entries.ToImmutableAndFree();
        }

        protected abstract LineVisibility GetUnknownStateVisibility(int index);

        /// <summary>
        /// The caller is expected to not call this if <see cref="Entries"/> is empty.
        /// </summary>
        public IEnumerable<LineMapping> GetLineMappings(TextLineCollection lines)
        {
            Debug.Assert(Entries.Length > 1);

            var current = Entries[0];

            // the first entry is always initialized to unmapped:
            Debug.Assert(
                current.State is PositionState.Unmapped or PositionState.Unknown &&
                current.UnmappedLine == 0 &&
                current.MappedLine == 0 &&
                current.MappedPathOpt == null);

            for (int i = 1; i < Entries.Length; i++)
            {
                var next = Entries[i];

                int unmappedEndLine = next.UnmappedLine - 2;
                Debug.Assert(unmappedEndLine >= current.UnmappedLine - 1);

                // Skip empty spans - two consecutive #line directives or #line on the first line.
                if (unmappedEndLine >= current.UnmappedLine)
                {
                    // C#: Span ends just at the start of the line containing #line directive
                    //
                    // #line Current "file1"
                    // [|....\n
                    // ...........\n|]
                    // #line Next "file2"
                    //
                    // VB: Span starts at the beginning of the line following the #ExternalSource directive and ends at the start of the line preceding #End ExternalSource.
                    // #ExternalSource("file", 1)
                    // [|....\n
                    // ...........\n|]
                    // #End ExternalSource

                    var endLine = lines[unmappedEndLine];
                    int lineLength = endLine.EndIncludingLineBreak - endLine.Start;

                    yield return CreateLineMapping(current, unmappedEndLine, lineLength, currentIndex: i - 1);
                }

                current = next;
            }

            var lastLine = lines[^1];

            // Last span (unless the last #line/#End ExternalSource is on the last line):
            // #line Current "file1"
            // [|....\n
            // ...........\n|]
            //
            // #End ExternalSource
            // [|....\n
            // ...........\n|]
            if (current.UnmappedLine <= lastLine.LineNumber)
            {
                int lineLength = lastLine.EndIncludingLineBreak - lastLine.Start;
                int unmappedEndLine = lastLine.LineNumber;

                yield return CreateLineMapping(current, unmappedEndLine, lineLength, currentIndex: Entries.Length - 1);
            }
        }

        private LineMapping CreateLineMapping(in LineMappingEntry entry, int unmappedEndLine, int lineLength, int currentIndex)
        {
            var unmapped = new LinePositionSpan(
                new LinePosition(entry.UnmappedLine, character: 0),
                new LinePosition(unmappedEndLine, lineLength));

            if (entry.State == PositionState.Hidden ||
                entry.State == PositionState.Unknown && GetUnknownStateVisibility(currentIndex) == LineVisibility.Hidden)
            {
                return new LineMapping(unmapped, characterOffset: null, mappedSpan: default);
            }

            string path = entry.MappedPathOpt ?? string.Empty;
            bool hasMappedPath = entry.MappedPathOpt != null;

            if (entry.State == PositionState.RemappedSpan)
            {
                return new LineMapping(
                    unmapped,
                    characterOffset: entry.UnmappedCharacterOffset,
                    new FileLinePositionSpan(path, entry.MappedSpan, hasMappedPath));
            }

            var mappedSpan = new LinePositionSpan(
                new LinePosition(entry.MappedLine, character: 0),
                new LinePosition(entry.MappedLine + unmappedEndLine - entry.UnmappedLine, lineLength));
            var mapped = new FileLinePositionSpan(path, mappedSpan, hasMappedPath);
            return new LineMapping(unmapped, characterOffset: null, mapped);
        }
    }
}


text:
package finalWeb.dao;

public class LoginDao {

}


text:
'use babel'

import {CompositeDisposable} from 'atom'

import IndentationStatusView from './indentation-status-view'

export default class IndentationStatus {
  constructor (statusBar, atomEnv = global.atom, config = atomEnv.config, workspace = atomEnv.workspace) {
    this.atomEnv = atomEnv
    this.config = config
    this.workspace = workspace
    this.statusBar = statusBar
    this.editor = null
    this.editorDisposables = null

    this.observeEvents()
    this.displayTile()
  }

  destroy () {
    this.subscriptions.dispose()
    this.destroyTile()
  }

  getText () {
    if (this.editor) {
      const softTabs = this.editor.getSoftTabs()
      const length = this.editor.getTabLength()
      const separator = this.config.get('indentation-indicator.spaceAfterColon') ? ': ' : ':'

      return `${this.softTabsSettingToText(softTabs)}${separator}${length}`
    } else {
      return ''
    }
  }

  destroyTile () {
    if (this.tooltipDisposable) {
      this.tooltipDisposable.dispose()
      this.tooltipDisposable = null
    }

    if (this.view) {
      this.view.destroy()
      this.view = null
    }

    if (this.tile) {
      this.tile.destroy()
      this.tile = null
    }
  }

  displayTile () {
    const priority = 100
    this.view = new IndentationStatusView(this)

    if (this.config.get('indentation-indicator.indicatorPosition') === 'right') {
      this.tile = this.statusBar.addRightTile({item: this.view.element, priority: priority})
      this.updateTooltip()
    } else {
      this.tile = this.statusBar.addLeftTile({item: this.view.element, priority: priority})
      this.updateTooltip()
    }
  }

  observeEvents () {
    this.subscriptions = new CompositeDisposable()

    this.subscriptions.add(this.config.onDidChange('indentation-indicator.indicatorPosition', () => {
      this.destroyTile()
      this.displayTile()
    }))

    this.subscriptions.add(this.config.onDidChange('indentation-indicator.spaceAfterColon', () => {
      if (this.view) {
        this.updateView()
      }
    }))

    this.subscriptions.add(this.workspace.observeActiveTextEditor((editor) => {
      if (this.editorDisposables) {
        this.editorDisposables.dispose()
        this.editorDisposables = null
      }

      this.editor = editor

      if (this.view) {
        this.updateView()
      }

      if (this.editor) {
        this.editorDisposables = this.editor.onDidChangeGrammar(() => {
          if (this.view) {
            this.updateView()
          }
        })
      }
    }))
  }

  softTabsSettingToText (softTabs) {
    return softTabs ? 'Spaces' : 'Tabs'
  }

  updateTooltip () {
    if (this.tooltipDisposable) {
      this.tooltipDisposable.dispose()
      this.tooltipDisposable = null
    }

    if (this.editor) {
      const tooltipText = `Active editor is using ${this.editor.getTabLength()} ${this.softTabsSettingToText(this.editor.getSoftTabs())}\nfor indentation`

      this.tooltipDisposable = this.atomEnv.tooltips.add(this.view.element,
                                                         {title: tooltipText, trigger: 'hover'})
    }
  }

  async updateView () {
    await this.view.update()

    this.updateTooltip()
  }
}


text:
import React, { Component } from 'react'

import Page from '../components/page'
import Header from '../components/header'
import Loader from '../components/loader'

// Login & Register
import Auth from '../components/auth'
import {createUser, loginUser} from '../lib/auth'

import Input from '../components/input'
import ListGroupsContacts from '../components/group-contact-list'
import ListMessage from '../components/message-list'

// Add Groups
import AddGroup from '../components/add-group'
import createGroup from '../lib/create-group'

import AddContact from '../components/add-contact'

import subscribeContactsGroups from '../lib/subscribe-groups'
import subscribeMessages from '../lib/subscribe-messages'
import sendMessage from '../lib/send-message'

export default class Index extends Component {
  constructor(props) {
    super(props)
    this.state = {
      loading: true,
      item: 'general',
      items: [],
      messages: [],
      text: '',
      isMenuOpen: false,
      isLoggedIn: false,
      regexName: /^[0-9a-zA-Z_-]+$/
    }
  }

  componentDidMount() {
    const { items } = this.state
    this.items = subscribeContactsGroups(
      items => this.setState({ items }),
      err => console.error('items subscribe error', err)
    )

    this.messages = subscribeMessages(
      items,
      messages => this.setState({ messages, loading: false }),
      err => console.error(err)
    )

    this.isLoggedIn = sessionStorage.getItem('isLoggedIn')
  }

  componentWillUnmount() {
    this.items && this.items.unsubscribe()
    this.messages && this.messages.unsubscribe()
  }

  loadChat = item => {
    this.setState({ item })

    this.state.isMenuOpen && this.toggleMobileMenu()

    if (this.messages) {
      this.messages.unsubscribe()
      this.setState({ loading: true })
    }

    this.messages = subscribeMessages(
      item,
      messages => this.setState({ messages, loading: false }),
      err => console.error(err)
    )
  }

  handleInputChange = event => {
    this.setState({ text: event.target.value })
  }

  handleSubmit = event => {
    event.preventDefault()

    if (this.state.text !== '') {
      this.sendMessage()
    }
  }

  createGroup = (name, cb) => {
    if (!this.regexName.test(name) || name.length < 3) {
      alert('Invalid item name')
      return
    }

    createGroup(name, () => {
      cb()
      this.loadChat(name)
    })
  }

  // createUser
  createUser = (registerName, registerPhone, registerPassword, cb) => {
    if (!this.regexName.test(registerName) || registerName.length < 3) {
      alert('Invalid name')
      return
    }

    if (registerPhone.length < 8) {
      alert('Invalid phone number (minimum length 8 characters)')
      return
    }

    if (registerPassword.length < 6) {
      alert('Password minimum length 6 characters')
      return
    }

    createUser(registerName, registerPhone, registerPassword, () => {
      cb()
    })

  }

  // loginUser
  loginUser = (loginPhone, loginPassword, cb) => {
    if (loginPhone.length< 3 || loginPassword.length < 6) {
      alert('Invalid name or password')
      return
    }

    loginUser(loginPhone, loginPassword, (result) => {
      if (result !== true) {
        alert('Invalid name or password')
        return
      }

      cb()

      sessionStorage.setItem('isLoggedIn', !this.state.isLoggedIn)
      this.setState({ isLoggedIn: !this.state.isLoggedIn})
    })
  }

  async sendMessage() {
    const { item, text } = this.state

    try {
      await sendMessage(item, text)
      this.setState({ text: '' })
    } catch (err) {
      console.log('message not sent', err)
    }
  }

  toggleMobileMenu = () => this.setState({ isMenuOpen: !this.state.isMenuOpen })

  render() {
    const {
      items,
      item,
      messages,
      text,
      loading,
      isLoggedIn,
      isMenuOpen,
    } = this.state

    return (
      <Page
        heading={`# ${item}`}
        onMenuClick={this.toggleMobileMenu}
        isMenuOpen={isMenuOpen}
      >

      {this.isLoggedIn !== true ?
        <Auth
          isLoggedIn={this.isLoggedIn}
          onSubmitLogin={this.loginUser}
          onSubmitRegister={this.createUser}
        />
      : null }

        <div>
          <aside className={`${isMenuOpen && 'open'}`}>
            <ListGroupsContacts
              list={items}
              active={item}
              onClick={this.loadChat}
            />
            <AddGroup onSubmit={this.createGroup} />
            <AddContact onSubmit={this.createContact} />
          </aside>
          <main>
            <ListMessage messages={messages} loading={loading} />
            <Input
              placeholder="Type a message..."
              onChange={this.handleInputChange}
              onSubmit={this.handleSubmit}
              value={text}
              buttonSubmit="Send"
            />
          </main>
        </div>
        <style jsx>
          {`
            div {
              display: flex;
              flex: 1;
            }

            aside {
              border-right: 1px solid #EEEBF3;
              padding: 0 0 0 50px;
              overflow: auto;
              -webkit-overflow-scrolling: touch;
              position: absolute;
              top: 0;
              bottom: 0;
              width: 100%;
              background: #fff;
              z-index: 10;
              transform: translate3d(-100%,0,0);
              transition: transform .4s ease;
            }

            aside.open {
              transform: translate3d(0,0,0);
            }

            @media screen and (min-width: 800px) {
              aside {
                position: relative;
                top: auto;
                bottom: auto;
                transform: none;
                flex: 1;
                max-width: 400px;
              }
            }

            main {
              flex: 2;
              display flex;
              flex-direction: column;
              overflow: hidden;
            }
          `}
        </style>
      </Page>
    )
  }
}


text:
This plugin shows how to work with content constrols tags.

It is called "Example work with content controls tags" in the interface and isn't installed by default in cloud, [self-hosted](https://github.com/ONLYOFFICE/DocumentServer) and [desktop version](https://github.com/ONLYOFFICE/DesktopEditors) of ONLYOFFICE editors.

## How to use

1. Open the Plugins tab and press "Example work with content controls tags". You need to add some content controls into document (you can do it before or after the plugin was started). Also you need to set any tag for content controls.
2. In the field below you can see all content controls tags (press the "Refresh list" button).
3. Press the "Past "Test paste for document"" for paste text into selected content control.

If you need more information about how to use or write your own plugin, please see this https://api.onlyoffice.com/plugin/basic


text:
<?php

 namespace Blog\Controller;

use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;
use Blog\Service\PostServiceInterface;
use Zend\Form\FormInterface;

 class BlogController extends AbstractActionController
 {
     protected $postService;

     /**
      * @var PostFormInterface
      * its value will be null while it process index and detail action
      */
     protected $postForm;

     public function __construct(
         PostServiceInterface $postService,
         FormInterface $postForm
     ){
         $this->postService = $postService;
         $this->postForm = $postForm;
     }

     public function indexAction()
     {
        return new ViewModel(array(
            'posts' => $this->postService->findAllPosts()
        ));
     }

     /*
      * @var $flag is used to check current action is "add a post"(true)
      *      or "update a post"(default value false)
      */
     public function editAction()
     {
         $request = $this->getRequest();
         $flag = false;

         if($this->params('id')==null){
             $flag = true;
         }else{
             $post = $this->postService->findPost($this->params('id'));
             $this->postForm->bind($post);
         }

         if ($request->isPost()) {
             $this->postForm->setData($request->getPost());

             if ($this->postForm->isValid()) {
                 //\Zend\Debug\Debug::dump($this->postForm->getData());die();
                 if($flag) $post = $this->postForm->getData();
                 try {
                     $this->postService->savePost($post);

                     return $this->redirect()->toRoute('blog');
                 } catch (\Exception $e) {
                     die($e->getMessage());
                     $this->flashMessenger()
                     ->setnamespace('error')
                     ->addMessage('DB Error'.$e);
                 }
             }
         }
         return new ViewModel(array(
             'form' => $this->postForm
         ));
     }

     public function deleteAction()
     {
         try {
             $post = $this->postService->findPost($this->params('id'));
         } catch (\InvalidArgumentException $e) {
             return $this->redirect()->toRoute('blog');
         }

         $request = $this->getRequest();

         if ($request->isPost()) {
             $del = $request->getPost('delete_confirmation', 'no');

             if ($del === 'yes') {
                 $this->postService->deletePost($post);
             }

             return $this->redirect()->toRoute('blog');
         }

         return new ViewModel(array(
             'post' => $post
         ));
     }

     public function detailAction()
     {
         $id = $this->params()->fromRoute('id');

         try {
             $post = $this->postService->findPost($id);
         } catch (\InvalidArgumentException $ex) {
             $this->flashMessenger()
                  ->setnamespace('error')
                  ->addMessage('Post '.$id.' does not exist.');
             return $this->redirect()->toRoute('blog');

         }

         return new ViewModel(array(
             'post' => $post
         ));
     }
 }


text:
package com.zfgc.mappers;

import com.zfgc.dbobj.LkupMemberGroupDbObj;
import com.zfgc.dbobj.LkupMemberGroupDbObjExample;
import java.util.List;
import org.apache.ibatis.annotations.Param;

public interface LkupMemberGroupDbObjMapper {
    /**
	 * This method was generated by MyBatis Generator. This method corresponds to the database table LKUP_MEMBER_GROUP
	 * @mbggenerated  Sun Mar 17 20:30:42 EDT 2019
	 */
	int countByExample(LkupMemberGroupDbObjExample example);

	/**
	 * This method was generated by MyBatis Generator. This method corresponds to the database table LKUP_MEMBER_GROUP
	 * @mbggenerated  Sun Mar 17 20:30:42 EDT 2019
	 */
	int deleteByExample(LkupMemberGroupDbObjExample example);

	/**
	 * This method was generated by MyBatis Generator. This method corresponds to the database table LKUP_MEMBER_GROUP
	 * @mbggenerated  Sun Mar 17 20:30:42 EDT 2019
	 */
	int deleteByPrimaryKey(Integer memberGroupId);

	/**
	 * This method was generated by MyBatis Generator. This method corresponds to the database table LKUP_MEMBER_GROUP
	 * @mbggenerated  Sun Mar 17 20:30:42 EDT 2019
	 */
	int insert(LkupMemberGroupDbObj record);

	/**
	 * This method was generated by MyBatis Generator. This method corresponds to the database table LKUP_MEMBER_GROUP
	 * @mbggenerated  Sun Mar 17 20:30:42 EDT 2019
	 */
	int insertSelective(LkupMemberGroupDbObj record);

	/**
	 * This method was generated by MyBatis Generator. This method corresponds to the database table LKUP_MEMBER_GROUP
	 * @mbggenerated  Sun Mar 17 20:30:42 EDT 2019
	 */
	List<LkupMemberGroupDbObj> selectByExample(
			LkupMemberGroupDbObjExample example);

	/**
	 * This method was generated by MyBatis Generator. This method corresponds to the database table LKUP_MEMBER_GROUP
	 * @mbggenerated  Sun Mar 17 20:30:42 EDT 2019
	 */
	LkupMemberGroupDbObj selectByPrimaryKey(Integer memberGroupId);

	/**
	 * This method was generated by MyBatis Generator. This method corresponds to the database table LKUP_MEMBER_GROUP
	 * @mbggenerated  Sun Mar 17 20:30:42 EDT 2019
	 */
	int updateByExampleSelective(@Param("record") LkupMemberGroupDbObj record,
			@Param("example") LkupMemberGroupDbObjExample example);

	/**
	 * This method was generated by MyBatis Generator. This method corresponds to the database table LKUP_MEMBER_GROUP
	 * @mbggenerated  Sun Mar 17 20:30:42 EDT 2019
	 */
	int updateByExample(@Param("record") LkupMemberGroupDbObj record,
			@Param("example") LkupMemberGroupDbObjExample example);

	/**
	 * This method was generated by MyBatis Generator. This method corresponds to the database table LKUP_MEMBER_GROUP
	 * @mbggenerated  Sun Mar 17 20:30:42 EDT 2019
	 */
	int updateByPrimaryKeySelective(LkupMemberGroupDbObj record);

	/**
	 * This method was generated by MyBatis Generator. This method corresponds to the database table LKUP_MEMBER_GROUP
	 * @mbggenerated  Sun Mar 17 20:30:42 EDT 2019
	 */
	int updateByPrimaryKey(LkupMemberGroupDbObj record);
}


text:
// ----------------------------------------------------------------------------------
//
// Copyright Microsoft Corporation
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ----------------------------------------------------------------------------------

using System;
using System.Collections.Generic;
using Microsoft.Azure.Management.DataFactories.Common.Models;
using Microsoft.Azure.Management.DataFactories.Models;

namespace Microsoft.Azure.Commands.DataFactories.Models
{
    public class PSDataset
    {
        private Table dataset;

        public PSDataset()
        {
            this.dataset = new Table() {Properties = new TableProperties()};
        }

        public PSDataset(Table dataset)
        {
            if (dataset == null)
            {
                throw new ArgumentNullException("dataset");
            }

            if (dataset.Properties == null)
            {
                dataset.Properties = new TableProperties();
            }

            this.dataset = dataset;
        }

        public string DatasetName
        {
            get
            {
                return this.dataset.Name;
            }
            set
            {
                this.dataset.Name = value;
            }
        }

        public string ResourceGroupName { get; set; }

        public string DataFactoryName { get; set; }

        public Availability Availability
        {
            get
            {
                return this.dataset.Properties.Availability;
            }
            set
            {
                this.dataset.Properties.Availability = value;
            }
        }

        public TableTypeProperties Location
        {
            get
            {
                return this.dataset.Properties.TypeProperties;
            }
            set
            {
                this.dataset.Properties.TypeProperties = value;
            }
        }

        public Policy Policy
        {
            get
            {
                return this.dataset.Properties.Policy;
            }
            set
            {
                this.dataset.Properties.Policy = value;
            }
        }

        public IList<DataElement> Structure
        {
            get
            {
                return this.dataset.Properties.Structure;
            }
            set
            {
                this.dataset.Properties.Structure = value;
            }
        }

        public TableProperties Properties
        {
            get
            {
                return this.dataset.Properties;
            }
            set
            {
                this.dataset.Properties = value;
            }
        }

        public string ProvisioningState
        {
            get { return Properties == null ? string.Empty : Properties.ProvisioningState; }
        }
    }
}


text:
package buildcontext

import (
	"context"
	"errors"
	"net/url"
	"os"
	"path/filepath"
	"strings"

	"github.com/Azure/azure-storage-blob-go/azblob"
	kConfig "github.com/GoogleContainerTools/kaniko/pkg/config"
	"github.com/GoogleContainerTools/kaniko/pkg/constants"
	"github.com/GoogleContainerTools/kaniko/pkg/util"
)

// AzureBlob struct for Azure Blob Storage processing
type AzureBlob struct {
	context string
}

// Download context file from given azure blob storage url and unpack it to BuildContextDir
func (b *AzureBlob) UnpackTarFromBuildContext() (string, error) {

	// Get Azure_STORAGE_ACCESS_KEY from environment variables
	accountKey := os.Getenv("AZURE_STORAGE_ACCESS_KEY")
	if len(accountKey) == 0 {
		return "", errors.New("AZURE_STORAGE_ACCESS_KEY environment variable is not set")
	}

	// Get storage accountName for Azure Blob Storage
	u, _ := url.Parse(b.context)
	parts := azblob.NewBlobURLParts(*u)
	accountName := strings.Split(parts.Host, ".")[0]

	// Generate credential with accountName and accountKey
	credential, err := azblob.NewSharedKeyCredential(accountName, accountKey)
	if err != nil {
		return parts.Host, err
	}

	// Create directory and target file for downloading the context file
	directory := kConfig.BuildContextDir
	tarPath := filepath.Join(directory, constants.ContextTar)
	file, err := util.CreateTargetTarfile(tarPath)
	if err != nil {
		return tarPath, err
	}

	// Downloading context file from Azure Blob Storage
	p := azblob.NewPipeline(credential, azblob.PipelineOptions{})
	blobURL := azblob.NewBlobURL(*u, p)
	ctx := context.Background()

	if err := azblob.DownloadBlobToFile(ctx, blobURL, 0, 0, file, azblob.DownloadFromBlobOptions{}); err != nil {
		return parts.Host, err
	}

	if err := util.UnpackCompressedTar(tarPath, directory); err != nil {
		return tarPath, err
	}
	// Remove the tar so it doesn't interfere with subsequent commands
	return directory, os.Remove(tarPath)
}


text:
package org.apache.spark.sql.kafka010

import java.{util => ju}

import org.apache.kafka.common.TopicPartition

import org.apache.spark.SparkContext
import org.apache.spark.internal.Logging
import org.apache.spark.internal.config.Network.NETWORK_TIMEOUT
import org.apache.spark.scheduler.ExecutorCacheTaskLocation
import org.apache.spark.sql._
import org.apache.spark.sql.catalyst.InternalRow
import org.apache.spark.sql.catalyst.util.CaseInsensitiveMap
import org.apache.spark.sql.connector.read.streaming
import org.apache.spark.sql.connector.read.streaming.{Offset => _, _}
import org.apache.spark.sql.execution.streaming._
import org.apache.spark.sql.kafka010.KafkaSourceProvider._
import org.apache.spark.sql.types._
import org.apache.spark.util.{Clock, SystemClock, Utils}

/**
 * A [[Source]] that reads data from Kafka using the following design.
 *
 * - The [[KafkaSourceOffset]] is the custom [[Offset]] defined for this source that contains
 *   a map of TopicPartition -> offset. Note that this offset is 1 + (available offset). For
 *   example if the last record in a Kafka topic "t", partition 2 is offset 5, then
 *   KafkaSourceOffset will contain TopicPartition("t", 2) -> 6. This is done keep it consistent
 *   with the semantics of `KafkaConsumer.position()`.
 *
 * - The [[KafkaSource]] written to do the following.
 *
 *  - As soon as the source is created, the pre-configured [[KafkaOffsetReader]]
 *    is used to query the initial offsets that this source should
 *    start reading from. This is used to create the first batch.
 *
 *   - `getOffset()` uses the [[KafkaOffsetReader]] to query the latest
 *      available offsets, which are returned as a [[KafkaSourceOffset]].
 *
 *   - `getBatch()` returns a DF that reads from the 'start offset' until the 'end offset' in
 *     for each partition. The end offset is excluded to be consistent with the semantics of
 *     [[KafkaSourceOffset]] and `KafkaConsumer.position()`.
 *
 *   - The DF returned is based on [[KafkaSourceRDD]] which is constructed such that the
 *     data from Kafka topic + partition is consistently read by the same executors across
 *     batches, and cached KafkaConsumers in the executors can be reused efficiently. See the
 *     docs on [[KafkaSourceRDD]] for more details.
 *
 * Zero data lost is not guaranteed when topics are deleted. If zero data lost is critical, the user
 * must make sure all messages in a topic have been processed when deleting a topic.
 *
 * There is a known issue caused by KAFKA-1894: the query using KafkaSource maybe cannot be stopped.
 * To avoid this issue, you should make sure stopping the query before stopping the Kafka brokers
 * and not use wrong broker addresses.
 */
private[kafka010] class KafkaSource(
    sqlContext: SQLContext,
    kafkaReader: KafkaOffsetReader,
    executorKafkaParams: ju.Map[String, Object],
    sourceOptions: CaseInsensitiveMap[String],
    metadataPath: String,
    startingOffsets: KafkaOffsetRangeLimit,
    failOnDataLoss: Boolean)
  extends SupportsTriggerAvailableNow with Source with Logging {

  private val sc = sqlContext.sparkContext

  private val pollTimeoutMs =
    sourceOptions.getOrElse(CONSUMER_POLL_TIMEOUT, (sc.conf.get(NETWORK_TIMEOUT) * 1000L).toString)
      .toLong

  private val maxOffsetsPerTrigger =
    sourceOptions.get(MAX_OFFSET_PER_TRIGGER).map(_.toLong)

  private[kafka010] val minOffsetPerTrigger =
    sourceOptions.get(MIN_OFFSET_PER_TRIGGER).map(_.toLong)

  private[kafka010] val maxTriggerDelayMs =
    Utils.timeStringAsMs(sourceOptions.get(MAX_TRIGGER_DELAY).getOrElse(DEFAULT_MAX_TRIGGER_DELAY))

  // this allows us to mock system clock for testing purposes
  private[kafka010] val clock: Clock = if (sourceOptions.contains(MOCK_SYSTEM_TIME)) {
    new MockedSystemClock
  } else {
    new SystemClock
  }

  private val includeHeaders =
    sourceOptions.getOrElse(INCLUDE_HEADERS, "false").toBoolean

  private var lastTriggerMillis = 0L

  private var allDataForTriggerAvailableNow: PartitionOffsetMap = _

  /**
   * Lazily initialize `initialPartitionOffsets` to make sure that `KafkaConsumer.poll` is only
   * called in StreamExecutionThread. Otherwise, interrupting a thread while running
   * `KafkaConsumer.poll` may hang forever (KAFKA-1894).
   */
  private lazy val initialPartitionOffsets = {
    val metadataLog = new KafkaSourceInitialOffsetWriter(sqlContext.sparkSession, metadataPath)
    metadataLog.get(0).getOrElse {
      val offsets = startingOffsets match {
        case EarliestOffsetRangeLimit => KafkaSourceOffset(kafkaReader.fetchEarliestOffsets())
        case LatestOffsetRangeLimit => KafkaSourceOffset(kafkaReader.fetchLatestOffsets(None))
        case SpecificOffsetRangeLimit(p) => kafkaReader.fetchSpecificOffsets(p, reportDataLoss)
        case SpecificTimestampRangeLimit(p, strategy) =>
          kafkaReader.fetchSpecificTimestampBasedOffsets(p, isStartingOffsets = true, strategy)
        case GlobalTimestampRangeLimit(ts, strategy) =>
          kafkaReader.fetchGlobalTimestampBasedOffsets(ts, isStartingOffsets = true, strategy)
      }
      metadataLog.add(0, offsets)
      logInfo(s"Initial offsets: $offsets")
      offsets
    }.partitionToOffsets
  }

  override def getDefaultReadLimit: ReadLimit = {
    if (minOffsetPerTrigger.isDefined && maxOffsetsPerTrigger.isDefined) {
      ReadLimit.compositeLimit(Array(
        ReadLimit.minRows(minOffsetPerTrigger.get, maxTriggerDelayMs),
        ReadLimit.maxRows(maxOffsetsPerTrigger.get)))
    } else if (minOffsetPerTrigger.isDefined) {
      ReadLimit.minRows(minOffsetPerTrigger.get, maxTriggerDelayMs)
    } else {
      // TODO (SPARK-37973) Directly call super.getDefaultReadLimit when scala issue 12523 is fixed
      maxOffsetsPerTrigger.map(ReadLimit.maxRows).getOrElse(ReadLimit.allAvailable())
    }
  }

  // The offsets for each topic-partition currently read to process. Note this maybe not necessarily
  // to be latest offsets because we possibly apply a read limit.
  private var currentPartitionOffsets: Option[Map[TopicPartition, Long]] = None

  // The latest offsets for each topic-partition.
  private var latestPartitionOffsets: Option[Map[TopicPartition, Long]] = None

  private val converter = new KafkaRecordToRowConverter()

  override def schema: StructType = KafkaRecordToRowConverter.kafkaSchema(includeHeaders)

  /** Returns the maximum available offset for this source. */
  override def getOffset: Option[Offset] = {
    throw new UnsupportedOperationException(
      "latestOffset(Offset, ReadLimit) should be called instead of this method")
  }

  override def reportLatestOffset(): streaming.Offset = {
    latestPartitionOffsets.map(KafkaSourceOffset(_)).getOrElse(null)
  }

  override def latestOffset(startOffset: streaming.Offset, limit: ReadLimit): streaming.Offset = {
    // Make sure initialPartitionOffsets is initialized
    initialPartitionOffsets
    val currentOffsets = currentPartitionOffsets.orElse(Some(initialPartitionOffsets))

    // Use the pre-fetched list of partition offsets when Trigger.AvailableNow is enabled.
    val latest = if (allDataForTriggerAvailableNow != null) {
      allDataForTriggerAvailableNow
    } else {
      kafkaReader.fetchLatestOffsets(currentOffsets)
    }

    latestPartitionOffsets = Some(latest)

    val limits: Seq[ReadLimit] = limit match {
      case rows: CompositeReadLimit => rows.getReadLimits
      case rows => Seq(rows)
    }

    val offsets = if (limits.exists(_.isInstanceOf[ReadAllAvailable])) {
      // ReadAllAvailable has the highest priority
      latest
    } else {
      val lowerLimit = limits.find(_.isInstanceOf[ReadMinRows]).map(_.asInstanceOf[ReadMinRows])
      val upperLimit = limits.find(_.isInstanceOf[ReadMaxRows]).map(_.asInstanceOf[ReadMaxRows])

      lowerLimit.flatMap { limit =>
        // checking if we need to skip batch based on minOffsetPerTrigger criteria
        val skipBatch = delayBatch(
          limit.minRows, latest, currentOffsets.get, limit.maxTriggerDelayMs)
        if (skipBatch) {
          logDebug(
            s"Delaying batch as number of records available is less than minOffsetsPerTrigger")
          // Pass same current offsets as output to skip trigger
          Some(currentOffsets.get)
        } else {
          None
        }
      }.orElse {
        // checking if we need to adjust a range of offsets based on maxOffsetPerTrigger criteria
        upperLimit.map { limit =>
          rateLimit(limit.maxRows, currentPartitionOffsets.getOrElse(initialPartitionOffsets),
            latest)
        }
      }.getOrElse(latest)
    }
    currentPartitionOffsets = Some(offsets)
    logDebug(s"GetOffset: ${offsets.toSeq.map(_.toString).sorted}")
    KafkaSourceOffset(offsets)
  }

  /** Checks if we need to skip this trigger based on minOffsetsPerTrigger & maxTriggerDelay */
  private def delayBatch(
      minLimit: Long,
      latestOffsets: Map[TopicPartition, Long],
      currentOffsets: Map[TopicPartition, Long],
      maxTriggerDelayMs: Long): Boolean = {
    // Checking first if the maxbatchDelay time has passed
    if ((clock.getTimeMillis() - lastTriggerMillis) >= maxTriggerDelayMs) {
      logDebug("Maximum wait time is passed, triggering batch")
      lastTriggerMillis = clock.getTimeMillis()
      false
    } else {
      val newRecords = latestOffsets.flatMap {
        case (topic, offset) =>
          Some(topic -> (offset - currentOffsets.getOrElse(topic, 0L)))
      }.values.sum.toDouble
      if (newRecords < minLimit) true else {
        lastTriggerMillis = clock.getTimeMillis()
        false
      }
    }
  }

  /** Proportionally distribute limit number of offsets among topicpartitions */
  private def rateLimit(
      limit: Long,
      from: Map[TopicPartition, Long],
      until: Map[TopicPartition, Long]): Map[TopicPartition, Long] = {
    lazy val fromNew = kafkaReader.fetchEarliestOffsets(until.keySet.diff(from.keySet).toSeq)
    val sizes = until.flatMap {
      case (tp, end) =>
        // If begin isn't defined, something's wrong, but let alert logic in getBatch handle it
        from.get(tp).orElse(fromNew.get(tp)).flatMap { begin =>
          val size = end - begin
          logDebug(s"rateLimit $tp size is $size")
          if (size > 0) Some(tp -> size) else None
        }
    }
    val total = sizes.values.sum.toDouble
    if (total < 1) {
      until
    } else {
      until.map {
        case (tp, end) =>
          tp -> sizes.get(tp).map { size =>
            val begin = from.getOrElse(tp, fromNew(tp))
            val prorate = limit * (size / total)
            logDebug(s"rateLimit $tp prorated amount is $prorate")
            // Don't completely starve small topicpartitions
            val prorateLong = (if (prorate < 1) Math.ceil(prorate) else Math.floor(prorate)).toLong
            // need to be careful of integer overflow
            // therefore added canary checks where to see if off variable could be overflowed
            // refer to [https://issues.apache.org/jira/browse/SPARK-26718]
            val off = if (prorateLong > Long.MaxValue - begin) {
              Long.MaxValue
            } else {
              begin + prorateLong
            }
            logDebug(s"rateLimit $tp new offset is $off")
            // Paranoia, make sure not to return an offset that's past end
            Math.min(end, off)
          }.getOrElse(end)
      }
    }
  }

  /**
   * Returns the data that is between the offsets
   * [`start.get.partitionToOffsets`, `end.partitionToOffsets`), i.e. end.partitionToOffsets is
   * exclusive.
   */
  override def getBatch(start: Option[Offset], end: Offset): DataFrame = {
    // Make sure initialPartitionOffsets is initialized
    initialPartitionOffsets

    logInfo(s"GetBatch called with start = $start, end = $end")
    val untilPartitionOffsets = KafkaSourceOffset.getPartitionOffsets(end)
    // On recovery, getBatch will get called before getOffset
    if (currentPartitionOffsets.isEmpty) {
      currentPartitionOffsets = Some(untilPartitionOffsets)
    }
    if (start.isDefined && start.get == end) {
      return sqlContext.internalCreateDataFrame(
        sqlContext.sparkContext.emptyRDD[InternalRow].setName("empty"), schema, isStreaming = true)
    }
    val fromPartitionOffsets = start match {
      case Some(prevBatchEndOffset) =>
        KafkaSourceOffset.getPartitionOffsets(prevBatchEndOffset)
      case None =>
        initialPartitionOffsets
    }

    val offsetRanges = kafkaReader.getOffsetRangesFromResolvedOffsets(
      fromPartitionOffsets,
      untilPartitionOffsets,
      reportDataLoss)

    // Create an RDD that reads from Kafka and get the (key, value) pair as byte arrays.
    val rdd = if (includeHeaders) {
      new KafkaSourceRDD(
        sc, executorKafkaParams, offsetRanges, pollTimeoutMs, failOnDataLoss)
        .map(converter.toInternalRowWithHeaders)
    } else {
      new KafkaSourceRDD(
        sc, executorKafkaParams, offsetRanges, pollTimeoutMs, failOnDataLoss)
        .map(converter.toInternalRowWithoutHeaders)
    }

    logInfo("GetBatch generating RDD of offset range: " +
      offsetRanges.sortBy(_.topicPartition.toString).mkString(", "))

    sqlContext.internalCreateDataFrame(rdd.setName("kafka"), schema, isStreaming = true)
  }

  /** Stop this source and free any resources it has allocated. */
  override def stop(): Unit = synchronized {
    kafkaReader.close()
  }

  override def toString(): String = s"KafkaSourceV1[$kafkaReader]"

  /**
   * If `failOnDataLoss` is true, this method will throw an `IllegalStateException`.
   * Otherwise, just log a warning.
   */
  private def reportDataLoss(message: String): Unit = {
    if (failOnDataLoss) {
      throw new IllegalStateException(message + s". $INSTRUCTION_FOR_FAIL_ON_DATA_LOSS_TRUE")
    } else {
      logWarning(message + s". $INSTRUCTION_FOR_FAIL_ON_DATA_LOSS_FALSE")
    }
  }

  override def prepareForTriggerAvailableNow(): Unit = {
    allDataForTriggerAvailableNow = kafkaReader.fetchLatestOffsets(Some(initialPartitionOffsets))
  }
}

/** Companion object for the [[KafkaSource]]. */
private[kafka010] object KafkaSource {
  def getSortedExecutorList(sc: SparkContext): Array[String] = {
    val bm = sc.env.blockManager
    bm.master.getPeers(bm.blockManagerId).toArray
      .map(x => ExecutorCacheTaskLocation(x.host, x.executorId))
      .sortWith(compare)
      .map(_.toString)
  }

  private def compare(a: ExecutorCacheTaskLocation, b: ExecutorCacheTaskLocation): Boolean = {
    if (a.host == b.host) { a.executorId > b.executorId } else { a.host > b.host }
  }

}