text:
/*
 * 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.
 */
package com.facebook.presto.orc.reader;

import com.facebook.presto.common.Subfield;
import com.facebook.presto.common.block.Block;
import com.facebook.presto.common.block.BlockBuilder;
import com.facebook.presto.common.block.BlockLease;
import com.facebook.presto.common.block.ClosingBlockLease;
import com.facebook.presto.common.block.DictionaryBlock;
import com.facebook.presto.common.block.RunLengthEncodedBlock;
import com.facebook.presto.common.block.VariableWidthBlockBuilder;
import com.facebook.presto.common.type.BigintType;
import com.facebook.presto.common.type.IntegerType;
import com.facebook.presto.common.type.MapType;
import com.facebook.presto.common.type.SmallintType;
import com.facebook.presto.common.type.TinyintType;
import com.facebook.presto.common.type.Type;
import com.facebook.presto.orc.OrcAggregatedMemoryContext;
import com.facebook.presto.orc.OrcLocalMemoryContext;
import com.facebook.presto.orc.OrcRecordReaderOptions;
import com.facebook.presto.orc.StreamDescriptor;
import com.facebook.presto.orc.TupleDomainFilter;
import com.facebook.presto.orc.metadata.ColumnEncoding;
import com.facebook.presto.orc.metadata.DwrfSequenceEncoding;
import com.facebook.presto.orc.metadata.OrcType.OrcTypeKind;
import com.facebook.presto.orc.stream.BooleanInputStream;
import com.facebook.presto.orc.stream.InputStreamSource;
import com.facebook.presto.orc.stream.InputStreamSources;
import com.google.common.collect.ImmutableBiMap;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables;
import com.google.common.collect.Maps;
import io.airlift.slice.SizeOf;
import io.airlift.slice.Slice;
import io.airlift.slice.Slices;
import org.joda.time.DateTimeZone;
import org.openjdk.jol.info.ClassLayout;

import javax.annotation.Nullable;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.SortedMap;

import static com.facebook.presto.orc.TupleDomainFilter.IS_NOT_NULL;
import static com.facebook.presto.orc.TupleDomainFilter.IS_NULL;
import static com.facebook.presto.orc.array.Arrays.ensureCapacity;
import static com.facebook.presto.orc.metadata.Stream.StreamKind.IN_MAP;
import static com.facebook.presto.orc.metadata.Stream.StreamKind.PRESENT;
import static com.facebook.presto.orc.reader.SelectiveStreamReaders.initializeOutputPositions;
import static com.facebook.presto.orc.stream.MissingInputStreamSource.missingStreamSource;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkState;
import static com.google.common.base.Verify.verify;
import static com.google.common.collect.ImmutableList.toImmutableList;
import static com.google.common.collect.ImmutableSet.toImmutableSet;
import static io.airlift.slice.SizeOf.sizeOf;
import static java.util.Objects.requireNonNull;

public class MapFlatSelectiveStreamReader
        implements SelectiveStreamReader
{
    private static final int INSTANCE_SIZE = ClassLayout.parseClass(MapFlatSelectiveStreamReader.class).instanceSize();

    private final StreamDescriptor streamDescriptor;
    private final boolean legacyMapSubscript;

    // This is the StreamDescriptor for the value stream with sequence ID 0, it is used to derive StreamDescriptors for the
    // value streams with other sequence IDs
    private final StreamDescriptor baseValueStreamDescriptor;
    private final OrcTypeKind keyOrcTypeKind;
    private final DateTimeZone hiveStorageTimeZone;

    private final boolean nullsAllowed;
    private final boolean nonNullsAllowed;
    private final boolean outputRequired;
    @Nullable
    private final MapType outputType;
    @Nullable
    private final Set<Long> requiredLongKeys;
    @Nullable
    private final Set<String> requiredStringKeys;

    private int[] keyIndices;   // indices of the required keys in the encodings array passed to startStripe
    private int keyCount;       // number of valid entries in keyIndices array

    private final List<InputStreamSource<BooleanInputStream>> inMapStreamSources = new ArrayList<>();
    private final List<BooleanInputStream> inMapStreams = new ArrayList<>();
    private final List<SelectiveStreamReader> valueStreamReaders = new ArrayList<>();
    private final List<StreamDescriptor> valueStreamDescriptors = new ArrayList<>();

    private Block keyBlock;
    private int readOffset;
    private int[] nestedReadOffsets;

    private InputStreamSource<BooleanInputStream> presentStreamSource = missingStreamSource(BooleanInputStream.class);
    @Nullable
    private BooleanInputStream presentStream;

    private boolean rowGroupOpen;
    private int[] offsets;
    private boolean[] nulls;
    private int[] outputPositions;
    private int outputPositionCount;
    private boolean outputPositionsReadOnly;
    private boolean allNulls;
    private boolean valuesInUse;

    private int[] nestedLengths;
    private int[][] nestedPositions;
    private int[] nestedPositionCounts;
    private int[][] nestedOutputPositions;
    private boolean[][] inMap;

    private final OrcAggregatedMemoryContext systemMemoryContext;
    private final OrcLocalMemoryContext localMemoryContext;
    private final OrcRecordReaderOptions options;

    public MapFlatSelectiveStreamReader(
            StreamDescriptor streamDescriptor,
            Map<Subfield, TupleDomainFilter> filters,
            List<Subfield> requiredSubfields,
            Optional<Type> outputType,
            DateTimeZone hiveStorageTimeZone,
            OrcRecordReaderOptions options,
            boolean legacyMapSubscript,
            OrcAggregatedMemoryContext systemMemoryContext)
    {
        this.options = requireNonNull(options);
        checkArgument(filters.keySet().stream().map(Subfield::getPath).allMatch(List::isEmpty), "filters on nested columns are not supported yet");
        checkArgument(streamDescriptor.getNestedStreams().size() == 2, "there must be exactly 2 nested stream descriptor");

        this.streamDescriptor = requireNonNull(streamDescriptor, "streamDescriptor is null");
        this.legacyMapSubscript = legacyMapSubscript;
        this.keyOrcTypeKind = streamDescriptor.getNestedStreams().get(0).getOrcTypeKind();
        this.baseValueStreamDescriptor = streamDescriptor.getNestedStreams().get(1);
        this.hiveStorageTimeZone = requireNonNull(hiveStorageTimeZone, "hiveStorageTimeZone is null");

        this.systemMemoryContext = requireNonNull(systemMemoryContext, "systemMemoryContext is null");
        this.localMemoryContext = systemMemoryContext.newOrcLocalMemoryContext(MapFlatSelectiveStreamReader.class.getSimpleName());
        this.outputRequired = requireNonNull(outputType, "outputType is null").isPresent();
        this.outputType = outputType.map(MapType.class::cast).orElse(null);

        TupleDomainFilter filter = getTopLevelFilter(filters).orElse(null);
        this.nullsAllowed = filter == null || filter.testNull();
        this.nonNullsAllowed = filter == null || filter.testNonNull();

        requireNonNull(requiredSubfields, "requiredSubfields is null");
        if (requiredSubfields.stream()
                .map(Subfield::getPath)
                .map(path -> path.get(0))
                .anyMatch(Subfield.AllSubscripts.class::isInstance)) {
            requiredLongKeys = null;
            requiredStringKeys = null;
        }
        else {
            switch (keyOrcTypeKind) {
                case BYTE:
                case SHORT:
                case INT:
                case LONG:
                    requiredLongKeys = requiredSubfields.stream()
                            .map(Subfield::getPath)
                            .map(path -> path.get(0))
                            .map(Subfield.LongSubscript.class::cast)
                            .map(Subfield.LongSubscript::getIndex)
                            .collect(toImmutableSet());
                    requiredStringKeys = null;
                    return;
                case STRING:
                case BINARY:
                    requiredStringKeys = requiredSubfields.stream()
                            .map(Subfield::getPath)
                            .map(path -> path.get(0))
                            .map(Subfield.StringSubscript.class::cast)
                            .map(Subfield.StringSubscript::getIndex)
                            .collect(toImmutableSet());
                    requiredLongKeys = null;
                    return;
                default:
                    requiredStringKeys = null;
                    requiredLongKeys = null;
            }
        }
    }

    private static Optional<TupleDomainFilter> getTopLevelFilter(Map<Subfield, TupleDomainFilter> filters)
    {
        Map<Subfield, TupleDomainFilter> topLevelFilters = Maps.filterEntries(filters, entry -> entry.getKey().getPath().isEmpty());
        if (topLevelFilters.isEmpty()) {
            return Optional.empty();
        }

        checkArgument(topLevelFilters.size() == 1, "MAP column may have at most one top-level range filter");
        TupleDomainFilter filter = Iterables.getOnlyElement(topLevelFilters.values());
        checkArgument(filter == IS_NULL || filter == IS_NOT_NULL, "Top-level range filter on MAP column must be IS NULL or IS NOT NULL");
        return Optional.of(filter);
    }

    @Override
    public int read(int offset, int[] positions, int positionCount)
            throws IOException
    {
        checkState(!valuesInUse, "BlockLease hasn't been closed yet");

        if (!rowGroupOpen) {
            openRowGroup();
        }

        allNulls = false;

        if (outputRequired && nullsAllowed && presentStream != null) {
            nulls = ensureCapacity(nulls, positionCount);
        }

        outputPositions = initializeOutputPositions(outputPositions, positions, positionCount);

        if (presentStream != null && keyCount == 0) {
            readAllNulls(positions, positionCount);
        }
        else {
            readNotAllNulls(offset, positions, positionCount);
        }

        localMemoryContext.setBytes(getRetainedSizeInBytes());

        return outputPositionCount;
    }

    private void readAllNulls(int[] positions, int positionCount)
            throws IOException
    {
        presentStream.skip(positions[positionCount - 1]);

        allNulls = true;

        if (!nullsAllowed) {
            outputPositionCount = 0;
        }
        else {
            outputPositionCount = positionCount;
            outputPositions = positions;
            outputPositionsReadOnly = true;
        }
    }

    private void readNotAllNulls(int offset, int[] positions, int positionCount)
            throws IOException
    {
        int streamPosition = 0;

        int[] nonNullPositions = new int[positionCount];
        int[] nullPositions = new int[positionCount];
        int nonNullPositionCount = 0;
        int nullPositionCount = 0;
        int nonNullSkipped = 0;

        if (presentStream == null) {
            if (readOffset < offset) {
                for (int i = 0; i < keyCount; i++) {
                    nestedReadOffsets[i] += inMapStreams.get(i).countBitsSet(offset - readOffset);
                }
            }

            for (int i = 0; i < positionCount; i++) {
                int position = positions[i];
                if (position > streamPosition) {
                    nonNullSkipped += position - streamPosition;
                    streamPosition = position;
                }

                nonNullPositions[i] = i + nonNullSkipped;
                streamPosition++;
            }
            nonNullPositionCount = positionCount;
        }
        else {
            if (readOffset < offset) {
                int skipped = presentStream.countBitsSet(offset - readOffset);
                if (skipped > 0) {
                    for (int i = 0; i < keyCount; i++) {
                        nestedReadOffsets[i] += inMapStreams.get(i).countBitsSet(skipped);
                    }
                }
            }
            for (int i = 0; i < positionCount; i++) {
                int position = positions[i];
                if (position > streamPosition) {
                    nonNullSkipped += presentStream.countBitsSet(position - streamPosition);
                    streamPosition = position;
                }

                streamPosition++;
                if (presentStream.nextBit()) {
                    // not null
                    if (nullsAllowed) {
                        nulls[i] = false;
                    }
                    nonNullPositions[nonNullPositionCount] = nonNullPositionCount + nonNullSkipped;
                    nonNullPositionCount++;
                }
                else {
                    if (nullsAllowed) {
                        nulls[i] = true;
                        nullPositions[nullPositionCount] = positions[i];
                        nullPositionCount++;
                    }
                }
            }
        }

        readOffset = offset + streamPosition;

        if (!nonNullsAllowed) {
            checkState(nullPositionCount == (positionCount - nonNullPositionCount), "nullPositionCount should be equal to postitionCount - nonNullPositionCount");
            outputPositionCount = nullPositionCount;
            allNulls = true;
            System.arraycopy(nullPositions, 0, outputPositions, 0, nullPositionCount);
        }
        else {
            nestedLengths = ensureCapacity(nestedLengths, nonNullPositionCount);
            Arrays.fill(nestedLengths, 0);

            for (int keyIndex = 0; keyIndex < keyCount; keyIndex++) {
                BooleanInputStream inMapStream = inMapStreams.get(keyIndex);

                nestedPositions[keyIndex] = ensureCapacity(nestedPositions[keyIndex], nonNullPositionCount);
                inMap[keyIndex] = ensureCapacity(inMap[keyIndex], nonNullPositionCount);

                int nestedStreamPosition = 0;

                int nestedSkipped = 0;
                int nestedPositionCount = 0;
                for (int i = 0; i < nonNullPositionCount; i++) {
                    int position = nonNullPositions[i];
                    if (position > nestedStreamPosition) {
                        nestedSkipped += inMapStream.countBitsSet(position - nestedStreamPosition);
                        nestedStreamPosition = position;
                    }

                    nestedStreamPosition++;
                    if (inMapStream.nextBit()) {
                        nestedPositions[keyIndex][nestedPositionCount] = nestedPositionCount + nestedSkipped;
                        nestedPositionCount++;

                        nestedLengths[i]++;
                        inMap[keyIndex][i] = true;
                    }
                    else {
                        inMap[keyIndex][i] = false;
                    }
                }

                if (nonNullSkipped > nestedStreamPosition - nonNullPositionCount) {
                    inMapStream.skip(nonNullSkipped - (nestedStreamPosition - nonNullPositionCount));
                }

                nestedPositionCounts[keyIndex] = nestedPositionCount;

                if (nestedPositionCount > 0) {
                    int readCount = valueStreamReaders.get(keyIndex).read(nestedReadOffsets[keyIndex], nestedPositions[keyIndex], nestedPositionCount);
                    verify(readCount == nestedPositionCount);
                }
                nestedReadOffsets[keyIndex] += nestedSkipped + nestedPositionCount;
            }

            if (nullsAllowed) {
                outputPositionCount = positionCount;
            }
            else {
                System.arraycopy(nonNullPositions, 0, outputPositions, 0, nonNullPositionCount);
                outputPositionCount = nonNullPositionCount;
            }
        }

        if (outputRequired) {
            nestedOutputPositions = ensureCapacity(nestedOutputPositions, keyCount);
            for (int i = 0; i < keyCount; i++) {
                int nestedPositionCount = nestedPositionCounts[i];
                if (nestedPositionCount > 0) {
                    nestedOutputPositions[i] = ensureCapacity(nestedOutputPositions[i], nestedPositionCount);
                    System.arraycopy(nestedPositions[i], 0, nestedOutputPositions[i], 0, nestedPositionCount);
                }
            }
        }
    }

    private void openRowGroup()
            throws IOException
    {
        presentStream = presentStreamSource.openStream();

        for (int i = 0; i < keyCount; i++) {
            BooleanInputStream inMapStream = requireNonNull(inMapStreamSources.get(i).openStream(), "missing inMapStream at position " + i);
            inMapStreams.add(inMapStream);
        }

        rowGroupOpen = true;
    }

    @Override
    public int[] getReadPositions()
    {
        return outputPositions;
    }

    @Override
    public Block getBlock(int[] positions, int positionCount)
    {
        checkArgument(outputPositionCount > 0, "outputPositionCount must be greater than zero");
        checkState(outputRequired, "This stream reader doesn't produce output");
        checkState(positionCount <= outputPositionCount, "Not enough values");
        checkState(!valuesInUse, "BlockLease hasn't been closed yet");

        if (allNulls) {
            return createNullBlock(outputType, positionCount);
        }

        boolean includeNulls = nullsAllowed && presentStream != null;
        if (outputPositionCount != positionCount) {
            compactValues(positions, positionCount, includeNulls);
        }

        Block block = assembleMapBlock(includeNulls);
        nulls = null;
        offsets = null;
        return block;
    }

    private Block assembleMapBlock(boolean includeNulls)
    {
        offsets = ensureCapacity(offsets, outputPositionCount + 1);
        offsets[0] = 0;

        int offset = 0;
        int inMapIndex = 0;
        for (int i = 0; i < outputPositionCount; i++) {
            if (!includeNulls || !nulls[i]) {
                offset += nestedLengths[inMapIndex];
                inMapIndex++;
            }
            offsets[i + 1] = offset;
        }

        BlockLease[] valueBlockLeases = new BlockLease[keyCount];
        Block[] valueBlocks = new Block[keyCount];
        for (int i = 0; i < keyCount; i++) {
            if (nestedPositionCounts[i] > 0) {
                valueBlockLeases[i] = valueStreamReaders.get(i).getBlockView(nestedOutputPositions[i], nestedPositionCounts[i]);
                valueBlocks[i] = valueBlockLeases[i].get();
            }
            else {
                valueBlocks[i] = outputType.getKeyType().createBlockBuilder(null, 0).build();
            }
        }

        int[] keyIds = new int[offset];
        int count = 0;

        Type valueType = outputType.getValueType();
        BlockBuilder valueBlockBuilder = valueType.createBlockBuilder(null, offset);

        int[] valueBlockPositions = new int[keyCount];

        inMapIndex = 0;
        for (int i = 0; i < outputPositionCount; i++) {
            if (includeNulls && nulls[i]) {
                continue;
            }
            for (int keyIndex = 0; keyIndex < keyCount; keyIndex++) {
                if (inMap[keyIndex][inMapIndex]) {
                    valueType.appendTo(valueBlocks[keyIndex], valueBlockPositions[keyIndex], valueBlockBuilder);
                    valueBlockPositions[keyIndex]++;
                    keyIds[count++] = keyIndex;
                }
            }
            inMapIndex++;
        }

        for (int i = 0; i < keyCount; i++) {
            if (valueBlockLeases[i] != null) {
                valueBlockLeases[i].close();
            }
        }

        return outputType.createBlockFromKeyValue(outputPositionCount, Optional.ofNullable(includeNulls ? nulls : null), offsets, new DictionaryBlock(keyBlock, keyIds), valueBlockBuilder);
    }

    private static RunLengthEncodedBlock createNullBlock(Type type, int positionCount)
    {
        return new RunLengthEncodedBlock(type.createBlockBuilder(null, 1).appendNull().build(), positionCount);
    }

    @Override
    public BlockLease getBlockView(int[] positions, int positionCount)
    {
        checkArgument(outputPositionCount > 0, "outputPositionCount must be greater than zero");
        checkState(outputRequired, "This stream reader doesn't produce output");
        checkState(positionCount <= outputPositionCount, "Not enough values");
        checkState(!valuesInUse, "BlockLease hasn't been closed yet");

        if (allNulls) {
            return newLease(createNullBlock(outputType, positionCount));
        }

        boolean includeNulls = nullsAllowed && presentStream != null;
        if (positionCount != outputPositionCount) {
            compactValues(positions, positionCount, includeNulls);
        }

        return newLease(assembleMapBlock(includeNulls));
    }

    private BlockLease newLease(Block block)
    {
        valuesInUse = true;
        return ClosingBlockLease.newLease(block, () -> valuesInUse = false);
    }

    private void compactValues(int[] positions, int positionCount, boolean includeNulls)
    {
        if (outputPositionsReadOnly) {
            outputPositions = Arrays.copyOf(outputPositions, outputPositionCount);
            outputPositionsReadOnly = false;
        }

        int positionIndex = 0;
        int nextPosition = positions[positionIndex];

        int skipped = 0;
        int inMapSkipped = 0;
        int inMapIndex = 0;
        int[] nestedSkipped = new int[keyCount];
        int[] nestedIndex = new int[keyCount];

        for (int i = 0; i < outputPositionCount; i++) {
            if (outputPositions[i] < nextPosition) {
                // skip this position
                if (!includeNulls || !nulls[i]) {
                    // not null
                    for (int keyIndex = 0; keyIndex < keyCount; keyIndex++) {
                        if (inMap[keyIndex][inMapIndex]) {
                            nestedSkipped[keyIndex]++;
                            nestedIndex[keyIndex]++;
                        }
                    }
                    inMapSkipped++;
                    inMapIndex++;
                }
                skipped++;
                continue;
            }

            outputPositions[i - skipped] = outputPositions[i];
            if (includeNulls) {
                nulls[i - skipped] = nulls[i];
            }
            if (!includeNulls || !nulls[i]) {
                // not null
                nestedLengths[inMapIndex - inMapSkipped] = nestedLengths[inMapIndex];
                for (int keyIndex = 0; keyIndex < keyCount; keyIndex++) {
                    inMap[keyIndex][inMapIndex - inMapSkipped] = inMap[keyIndex][inMapIndex];
                    if (inMap[keyIndex][inMapIndex]) {
                        nestedOutputPositions[keyIndex][nestedIndex[keyIndex] - nestedSkipped[keyIndex]] = nestedOutputPositions[keyIndex][nestedIndex[keyIndex]];
                        nestedIndex[keyIndex]++;
                    }
                }
                inMapIndex++;
            }

            positionIndex++;
            if (positionIndex >= positionCount) {
                break;
            }

            nextPosition = positions[positionIndex];
        }

        outputPositionCount = positionCount;
        for (int keyIndex = 0; keyIndex < keyCount; keyIndex++) {
            nestedPositionCounts[keyIndex] = nestedIndex[keyIndex] - nestedSkipped[keyIndex];
        }
    }

    @Override
    public void throwAnyError(int[] positions, int positionCount)
    {
    }

    @Override
    public void close()
    {
        keyIndices = null;
        nestedReadOffsets = null;
        offsets = null;
        nulls = null;
        outputPositions = null;
        nestedLengths = null;
        nestedPositions = null;
        nestedPositionCounts = null;
        nestedOutputPositions = null;
        inMap = null;
        valueStreamReaders.stream().forEach(SelectiveStreamReader::close);

        presentStream = null;
        presentStreamSource = null;

        localMemoryContext.close();
    }

    @Override
    public void startStripe(InputStreamSources dictionaryStreamSources, Map<Integer, ColumnEncoding> encodings)
            throws IOException
    {
        presentStreamSource = missingStreamSource(BooleanInputStream.class);

        inMapStreamSources.clear();
        valueStreamDescriptors.clear();
        valueStreamReaders.clear();

        ColumnEncoding encoding = encodings.get(baseValueStreamDescriptor.getStreamId());
        // encoding.getAdditionalSequenceEncodings() may not be present when every map is empty or null
        SortedMap<Integer, DwrfSequenceEncoding> additionalSequenceEncodings = encoding.getAdditionalSequenceEncodings().orElse(Collections.emptySortedMap());

        keyIndices = ensureCapacity(keyIndices, additionalSequenceEncodings.size());
        keyCount = 0;

        // The ColumnEncoding with sequence ID 0 doesn't have any data associated with it
        int keyIndex = 0;
        for (Map.Entry<Integer, DwrfSequenceEncoding> entry : additionalSequenceEncodings.entrySet()) {
            if (!isRequiredKey(entry.getValue())) {
                keyIndex++;
                continue;
            }

            keyIndices[keyCount] = keyIndex;
            keyCount++;
            keyIndex++;

            int sequence = entry.getKey();

            inMapStreamSources.add(missingStreamSource(BooleanInputStream.class));

            StreamDescriptor valueStreamDescriptor = copyStreamDescriptorWithSequence(baseValueStreamDescriptor, sequence);
            valueStreamDescriptors.add(valueStreamDescriptor);

            SelectiveStreamReader valueStreamReader = SelectiveStreamReaders.createStreamReader(
                    valueStreamDescriptor,
                    ImmutableBiMap.of(),
                    Optional.ofNullable(outputType).map(MapType::getValueType),
                    ImmutableList.of(),
                    hiveStorageTimeZone,
                    options,
                    legacyMapSubscript,
                    systemMemoryContext.newOrcAggregatedMemoryContext());
            valueStreamReader.startStripe(dictionaryStreamSources, encodings);
            valueStreamReaders.add(valueStreamReader);
        }

        keyBlock = getKeysBlock(ImmutableList.copyOf(additionalSequenceEncodings.values()));
        readOffset = 0;

        presentStream = null;

        rowGroupOpen = false;
    }

    private boolean isRequiredKey(DwrfSequenceEncoding value)
    {
        if (requiredLongKeys != null) {
            return requiredLongKeys.isEmpty() || requiredLongKeys.contains(value.getKey().getIntKey());
        }

        return requiredStringKeys.isEmpty() || requiredStringKeys.contains(value.getKey().getBytesKey().toStringUtf8());
    }

    /**
     * Creates StreamDescriptor which is a copy of this one with the value of sequence changed to
     * the value passed in.  Recursively calls itself on the nested streams.
     */
    private static StreamDescriptor copyStreamDescriptorWithSequence(StreamDescriptor streamDescriptor, int sequence)
    {
        List<StreamDescriptor> streamDescriptors = streamDescriptor.getNestedStreams().stream()
                .map(stream -> copyStreamDescriptorWithSequence(stream, sequence))
                .collect(toImmutableList());

        return new StreamDescriptor(
                streamDescriptor.getStreamName(),
                streamDescriptor.getStreamId(),
                streamDescriptor.getFieldName(),
                streamDescriptor.getOrcType(),
                streamDescriptor.getOrcDataSource(),
                streamDescriptors,
                sequence);
    }

    private Block getKeysBlock(List<DwrfSequenceEncoding> sequenceEncodings)
    {
        switch (keyOrcTypeKind) {
            case BYTE:
            case SHORT:
            case INT:
            case LONG:
                return getIntegerKeysBlock(sequenceEncodings);
            case STRING:
            case BINARY:
                return getSliceKeysBlock(sequenceEncodings);
            default:
                throw new IllegalArgumentException("Unsupported flat map key type: " + keyOrcTypeKind);
        }
    }

    private Block getIntegerKeysBlock(List<DwrfSequenceEncoding> sequenceEncodings)
    {
        Type keyType;

        switch (keyOrcTypeKind) {
            case BYTE:
                keyType = TinyintType.TINYINT;
                break;
            case SHORT:
                keyType = SmallintType.SMALLINT;
                break;
            case INT:
                keyType = IntegerType.INTEGER;
                break;
            case LONG:
                keyType = BigintType.BIGINT;
                break;
            default:
                throw new IllegalArgumentException("Unsupported flat map key type: " + keyOrcTypeKind);
        }

        BlockBuilder blockBuilder = keyType.createBlockBuilder(null, sequenceEncodings.size());

        for (int i = 0; i < keyCount; i++) {
            keyType.writeLong(blockBuilder, sequenceEncodings.get(keyIndices[i]).getKey().getIntKey());
        }

        return blockBuilder.build();
    }

    private Block getSliceKeysBlock(List<DwrfSequenceEncoding> sequenceEncodings)
    {
        int bytes = 0;

        for (DwrfSequenceEncoding sequenceEncoding : sequenceEncodings) {
            bytes += sequenceEncoding.getKey().getBytesKey().size();
        }

        VariableWidthBlockBuilder builder = new VariableWidthBlockBuilder(null, sequenceEncodings.size(), bytes);

        for (int i = 0; i < keyCount; i++) {
            Slice key = Slices.wrappedBuffer(sequenceEncodings.get(keyIndices[i]).getKey().getBytesKey().toByteArray());
            builder.writeBytes(key, 0, key.length());
            builder.closeEntry();
        }

        return builder.build();
    }

    @Override
    public void startRowGroup(InputStreamSources dataStreamSources)
            throws IOException
    {
        presentStreamSource = dataStreamSources.getInputStreamSource(streamDescriptor, PRESENT, BooleanInputStream.class);

        for (int i = 0; i < keyCount; i++) {
            InputStreamSource<BooleanInputStream> inMapStreamSource = dataStreamSources.getInputStreamSource(valueStreamDescriptors.get(i), IN_MAP, BooleanInputStream.class);
            inMapStreamSources.set(i, inMapStreamSource);
        }

        readOffset = 0;
        nestedReadOffsets = ensureCapacity(nestedReadOffsets, keyCount);
        Arrays.fill(nestedReadOffsets, 0);

        nestedPositions = ensureCapacity(nestedPositions, keyCount);
        nestedPositionCounts = ensureCapacity(nestedPositionCounts, keyCount);
        inMap = ensureCapacity(inMap, keyCount);

        presentStream = null;
        inMapStreams.clear();

        rowGroupOpen = false;

        for (SelectiveStreamReader valueStreamReader : valueStreamReaders) {
            valueStreamReader.startRowGroup(dataStreamSources);
        }
    }

    @Override
    public long getRetainedSizeInBytes()
    {
        return INSTANCE_SIZE +
                sizeOf(keyIndices) +
                sizeOf(nestedReadOffsets) +
                sizeOf(offsets) +
                sizeOf(nulls) +
                sizeOf(outputPositions) +
                sizeOf(nestedLengths) +
                (nestedPositions != null ? Arrays.stream(nestedPositions).mapToLong(SizeOf::sizeOf).sum() : 0) +
                sizeOf(nestedPositionCounts) +
                (nestedOutputPositions != null ? Arrays.stream(nestedOutputPositions).mapToLong(SizeOf::sizeOf).sum() : 0) +
                (inMap != null ? Arrays.stream(inMap).mapToLong(SizeOf::sizeOf).sum() : 0) +
                (valueStreamReaders != null ? valueStreamReaders.stream().mapToLong(StreamReader::getRetainedSizeInBytes).sum() : 0);
    }
}


text:
CREATE TABLE ACCOUNT_LOG(
        ID BIGINT NOT NULL,
	USERNAME VARCHAR(64),
	RESULT VARCHAR(64),
	REASON VARCHAR(200),
	APPLICATION VARCHAR(200),
	LOG_TIME TIMESTAMP,
        CLIENT VARCHAR(200),
	SERVER VARCHAR(200),
	DESCRIPTION VARCHAR(200),
        CONSTRAINT PK_ACCOUNT_LOG PRIMARY KEY(ID)
) ENGINE=INNODB CHARSET=UTF8;

redpajama_set_name: RedPajamaGithub


text:
require 'fileutils'
require 'spec_helper'
require_relative '../../examples/rails'

describe ROXML, "under ActiveRecord" do
  before do
    @route = Route.from_xml(xml_for('active_record'))
  end

  it "should be parsed" do
    expect(@route).to_not eq(nil)
    expect(@route).to be_an_instance_of(Route)
  end

  describe "xml attributes" do
    it "should extract xml attributes" do
      expect(@route.totalHg).to eq("640")
      expect(@route.lonlatx).to eq("357865")
      expect(@route.lonlaty).to eq("271635")
      expect(@route.grcenter).to eq("SH 71635 57865")
      expect(@route.totalMins).to eq("235.75000000000003")
      expect(@route.totalDist).to eq("11185.321521477119")
    end
  end

  describe "xml sub-objects" do
    it "should extract xml sub-objects" do
      expect(@route.waypoints.size).to eq(6)
      @route.waypoints.each {|waypoint| expect(waypoint).to be_an_instance_of(Waypoint)}
    end
    it "should be usable as a ActiveRecord object" do
      expect(Waypoint.count).to eq(0)
      @route.save!
      expect(Waypoint.count).to eq(6)
    end
  end
end


text:
(function() {
  var mode = CodeMirror.getMode({tabSize: 4}, "markdown");
  function MT(name) { test.mode(name, mode, Array.prototype.slice.call(arguments, 1)); }

  MT("plainText",
     "foo");

  // Code blocks using 4 spaces (regardless of CodeMirror.tabSize value)
  MT("codeBlocksUsing4Spaces",
     "    [comment foo]");

  // Code blocks using 4 spaces with internal indentation
  MT("codeBlocksUsing4SpacesIndentation",
     "    [comment bar]",
     "        [comment hello]",
     "            [comment world]",
     "    [comment foo]",
     "bar");

  // Code blocks using 4 spaces with internal indentation
  MT("codeBlocksUsing4SpacesIndentation",
     " foo",
     "    [comment bar]",
     "        [comment hello]",
     "    [comment world]");

  // Code blocks using 1 tab (regardless of CodeMirror.indentWithTabs value)
  MT("codeBlocksUsing1Tab",
     "\t[comment foo]");

  // Inline code using backticks
  MT("inlineCodeUsingBackticks",
     "foo [comment `bar`]");

  // Block code using single backtick (shouldn't work)
  MT("blockCodeSingleBacktick",
     "[comment `]",
     "foo",
     "[comment `]");

  // Unclosed backticks
  // Instead of simply marking as CODE, it would be nice to have an
  // incomplete flag for CODE, that is styled slightly different.
  MT("unclosedBackticks",
     "foo [comment `bar]");

  // Per documentation: "To include a literal backtick character within a
  // code span, you can use multiple backticks as the opening and closing
  // delimiters"
  MT("doubleBackticks",
     "[comment ``foo ` bar``]");

  // Tests based on Dingus
  // http://daringfireball.net/projects/markdown/dingus
  //
  // Multiple backticks within an inline code block
  MT("consecutiveBackticks",
     "[comment `foo```bar`]");

  // Multiple backticks within an inline code block with a second code block
  MT("consecutiveBackticks",
     "[comment `foo```bar`] hello [comment `world`]");

  // Unclosed with several different groups of backticks
  MT("unclosedBackticks",
     "[comment ``foo ``` bar` hello]");

  // Closed with several different groups of backticks
  MT("closedBackticks",
     "[comment ``foo ``` bar` hello``] world");

  // atx headers
  // http://daringfireball.net/projects/markdown/syntax#header

  MT("atxH1",
     "[header # foo]");

  MT("atxH2",
     "[header ## foo]");

  MT("atxH3",
     "[header ### foo]");

  MT("atxH4",
     "[header #### foo]");

  MT("atxH5",
     "[header ##### foo]");

  MT("atxH6",
     "[header ###### foo]");

  // H6 - 7x '#' should still be H6, per Dingus
  // http://daringfireball.net/projects/markdown/dingus
  MT("atxH6NotH7",
     "[header ####### foo]");

  // Setext headers - H1, H2
  // Per documentation, "Any number of underlining ='s or -'s will work."
  // http://daringfireball.net/projects/markdown/syntax#header
  // Ideally, the text would be marked as `header` as well, but this is
  // not really feasible at the moment. So, instead, we're testing against
  // what works today, to avoid any regressions.
  //
  // Check if single underlining = works
  MT("setextH1",
     "foo",
     "[header =]");

  // Check if 3+ ='s work
  MT("setextH1",
     "foo",
     "[header ===]");

  // Check if single underlining - works
  MT("setextH2",
     "foo",
     "[header -]");

  // Check if 3+ -'s work
  MT("setextH2",
     "foo",
     "[header ---]");

  // Single-line blockquote with trailing space
  MT("blockquoteSpace",
     "[quote > foo]");

  // Single-line blockquote
  MT("blockquoteNoSpace",
     "[quote >foo]");

  // Single-line blockquote followed by normal paragraph
  MT("blockquoteThenParagraph",
     "[quote >foo]",
     "",
     "bar");

  // Multi-line blockquote (lazy mode)
  MT("multiBlockquoteLazy",
     "[quote >foo]",
     "[quote bar]");

  // Multi-line blockquote followed by normal paragraph (lazy mode)
  MT("multiBlockquoteLazyThenParagraph",
     "[quote >foo]",
     "[quote bar]",
     "",
     "hello");

  // Multi-line blockquote (non-lazy mode)
  MT("multiBlockquote",
     "[quote >foo]",
     "[quote >bar]");

  // Multi-line blockquote followed by normal paragraph (non-lazy mode)
  MT("multiBlockquoteThenParagraph",
     "[quote >foo]",
     "[quote >bar]",
     "",
     "hello");

  // Check list types

  MT("listAsterisk",
     "[string * foo]",
     "[string * bar]");

  MT("listPlus",
     "[string + foo]",
     "[string + bar]");

  MT("listDash",
     "[string - foo]",
     "[string - bar]");

  MT("listNumber",
     "[string 1. foo]",
     "[string 2. bar]");

  // Formatting in lists (*)
  MT("listAsteriskFormatting",
     "[string * ][string&em *foo*][string  bar]",
     "[string * ][string&strong **foo**][string  bar]",
     "[string * ][string&strong **][string&emstrong *foo**][string&em *][string  bar]",
     "[string * ][string&comment `foo`][string  bar]");

  // Formatting in lists (+)
  MT("listPlusFormatting",
     "[string + ][string&em *foo*][string  bar]",
     "[string + ][string&strong **foo**][string  bar]",
     "[string + ][string&strong **][string&emstrong *foo**][string&em *][string  bar]",
     "[string + ][string&comment `foo`][string  bar]");

  // Formatting in lists (-)
  MT("listDashFormatting",
     "[string - ][string&em *foo*][string  bar]",
     "[string - ][string&strong **foo**][string  bar]",
     "[string - ][string&strong **][string&emstrong *foo**][string&em *][string  bar]",
     "[string - ][string&comment `foo`][string  bar]");

  // Formatting in lists (1.)
  MT("listNumberFormatting",
     "[string 1. ][string&em *foo*][string  bar]",
     "[string 2. ][string&strong **foo**][string  bar]",
     "[string 3. ][string&strong **][string&emstrong *foo**][string&em *][string  bar]",
     "[string 4. ][string&comment `foo`][string  bar]");

  // Paragraph lists
  MT("listParagraph",
     "[string * foo]",
     "",
     "[string * bar]");

  // Multi-paragraph lists
  //
  // 4 spaces
  MT("listMultiParagraph",
     "[string * foo]",
     "",
     "[string * bar]",
     "",
     "    [string hello]");

  // 4 spaces, extra blank lines (should still be list, per Dingus)
  MT("listMultiParagraphExtra",
     "[string * foo]",
     "",
     "[string * bar]",
     "",
     "    [string hello]");

  // 4 spaces, plus 1 space (should still be list, per Dingus)
  MT("listMultiParagraphExtraSpace",
     "[string * foo]",
     "",
     "[string * bar]",
     "",
     "     [string hello]",
     "",
     "    [string world]");

  // 1 tab
  MT("listTab",
     "[string * foo]",
     "",
     "[string * bar]",
     "",
     "\t[string hello]");

  // No indent
  MT("listNoIndent",
     "[string * foo]",
     "",
     "[string * bar]",
     "",
     "hello");

  // Blockquote
  MT("blockquote",
     "[string * foo]",
     "",
     "[string * bar]",
     "",
     "    [string&quote > hello]");

  // Code block
  MT("blockquoteCode",
     "[string * foo]",
     "",
     "[string * bar]",
     "",
     "        [comment > hello]",
     "",
     "    [string world]");

  // Code block followed by text
  MT("blockquoteCodeText",
     "[string * foo]",
     "",
     "    [string bar]",
     "",
     "        [comment hello]",
     "",
     "    [string world]");

  // Nested list

  MT("listAsteriskNested",
     "[string * foo]",
     "",
     "    [string * bar]");

  MT("listPlusNested",
     "[string + foo]",
     "",
     "    [string + bar]");

  MT("listDashNested",
     "[string - foo]",
     "",
     "    [string - bar]");

  MT("listNumberNested",
     "[string 1. foo]",
     "",
     "    [string 2. bar]");

  MT("listMixed",
     "[string * foo]",
     "",
     "    [string + bar]",
     "",
     "        [string - hello]",
     "",
     "            [string 1. world]");

  MT("listBlockquote",
     "[string * foo]",
     "",
     "    [string + bar]",
     "",
     "        [quote&string > hello]");

  MT("listCode",
     "[string * foo]",
     "",
     "    [string + bar]",
     "",
     "            [comment hello]");

  // Code with internal indentation
  MT("listCodeIndentation",
     "[string * foo]",
     "",
     "        [comment bar]",
     "            [comment hello]",
     "                [comment world]",
     "        [comment foo]",
     "    [string bar]");

  // Code followed by text
  MT("listCodeText",
     "[string * foo]",
     "",
     "        [comment bar]",
     "",
     "hello");

  // Following tests directly from official Markdown documentation
  // http://daringfireball.net/projects/markdown/syntax#hr

  MT("hrSpace",
     "[hr * * *]");

  MT("hr",
     "[hr ***]");

  MT("hrLong",
     "[hr *****]");

  MT("hrSpaceDash",
     "[hr - - -]");

  MT("hrDashLong",
     "[hr ---------------------------------------]");

  // Inline link with title
  MT("linkTitle",
     "[link [[foo]]][string (http://example.com/ \"bar\")] hello");

  // Inline link without title
  MT("linkNoTitle",
     "[link [[foo]]][string (http://example.com/)] bar");

  // Inline link with image
  MT("linkImage",
     "[link [[][tag ![[foo]]][string (http://example.com/)][link ]]][string (http://example.com/)] bar");

  // Inline link with Em
  MT("linkEm",
     "[link [[][link&em *foo*][link ]]][string (http://example.com/)] bar");

  // Inline link with Strong
  MT("linkStrong",
     "[link [[][link&strong **foo**][link ]]][string (http://example.com/)] bar");

  // Inline link with EmStrong
  MT("linkEmStrong",
     "[link [[][link&strong **][link&emstrong *foo**][link&em *][link ]]][string (http://example.com/)] bar");

  // Image with title
  MT("imageTitle",
     "[tag ![[foo]]][string (http://example.com/ \"bar\")] hello");

  // Image without title
  MT("imageNoTitle",
     "[tag ![[foo]]][string (http://example.com/)] bar");

  // Image with asterisks
  MT("imageAsterisks",
     "[tag ![[*foo*]]][string (http://example.com/)] bar");

  // Not a link. Should be normal text due to square brackets being used
  // regularly in text, especially in quoted material, and no space is allowed
  // between square brackets and parentheses (per Dingus).
  MT("notALink",
     "[[foo]] (bar)");

  // Reference-style links
  MT("linkReference",
     "[link [[foo]]][string [[bar]]] hello");

  // Reference-style links with Em
  MT("linkReferenceEm",
     "[link [[][link&em *foo*][link ]]][string [[bar]]] hello");

  // Reference-style links with Strong
  MT("linkReferenceStrong",
     "[link [[][link&strong **foo**][link ]]][string [[bar]]] hello");

  // Reference-style links with EmStrong
  MT("linkReferenceEmStrong",
     "[link [[][link&strong **][link&emstrong *foo**][link&em *][link ]]][string [[bar]]] hello");

  // Reference-style links with optional space separator (per docuentation)
  // "You can optionally use a space to separate the sets of brackets"
  MT("linkReferenceSpace",
     "[link [[foo]]] [string [[bar]]] hello");

  // Should only allow a single space ("...use *a* space...")
  MT("linkReferenceDoubleSpace",
     "[[foo]]  [[bar]] hello");

  // Reference-style links with implicit link name
  MT("linkImplicit",
     "[link [[foo]]][string [[]]] hello");

  // @todo It would be nice if, at some point, the document was actually
  // checked to see if the referenced link exists

  // Link label, for reference-style links (taken from documentation)

  MT("labelNoTitle",
     "[link [[foo]]:] [string http://example.com/]");

  MT("labelIndented",
     "   [link [[foo]]:] [string http://example.com/]");

  MT("labelSpaceTitle",
     "[link [[foo bar]]:] [string http://example.com/ \"hello\"]");

  MT("labelDoubleTitle",
     "[link [[foo bar]]:] [string http://example.com/ \"hello\"] \"world\"");

  MT("labelTitleDoubleQuotes",
     "[link [[foo]]:] [string http://example.com/  \"bar\"]");

  MT("labelTitleSingleQuotes",
     "[link [[foo]]:] [string http://example.com/  'bar']");

  MT("labelTitleParenthese",
     "[link [[foo]]:] [string http://example.com/  (bar)]");

  MT("labelTitleInvalid",
     "[link [[foo]]:] [string http://example.com/] bar");

  MT("labelLinkAngleBrackets",
     "[link [[foo]]:] [string <http://example.com/>  \"bar\"]");

  MT("labelTitleNextDoubleQuotes",
     "[link [[foo]]:] [string http://example.com/]",
     "[string \"bar\"] hello");

  MT("labelTitleNextSingleQuotes",
     "[link [[foo]]:] [string http://example.com/]",
     "[string 'bar'] hello");

  MT("labelTitleNextParenthese",
     "[link [[foo]]:] [string http://example.com/]",
     "[string (bar)] hello");

  MT("labelTitleNextMixed",
     "[link [[foo]]:] [string http://example.com/]",
     "(bar\" hello");

  MT("linkWeb",
     "[link <http://example.com/>] foo");

  MT("linkEmail",
     "[link <user@example.com>] foo");

  MT("emAsterisk",
     "[em *foo*] bar");

  MT("emUnderscore",
     "[em _foo_] bar");

  MT("emInWordAsterisk",
     "foo[em *bar*]hello");

  MT("emInWordUnderscore",
     "foo[em _bar_]hello");

  // Per documentation: "...surround an * or _ with spaces, it'll be
  // treated as a literal asterisk or underscore."

  MT("emEscapedBySpaceIn",
     "foo [em _bar _ hello_] world");

  MT("emEscapedBySpaceOut",
     "foo _ bar[em _hello_]world");

  // Unclosed emphasis characters
  // Instead of simply marking as EM / STRONG, it would be nice to have an
  // incomplete flag for EM and STRONG, that is styled slightly different.
  MT("emIncompleteAsterisk",
     "foo [em *bar]");

  MT("emIncompleteUnderscore",
     "foo [em _bar]");

  MT("strongAsterisk",
     "[strong **foo**] bar");

  MT("strongUnderscore",
     "[strong __foo__] bar");

  MT("emStrongAsterisk",
     "[em *foo][emstrong **bar*][strong hello**] world");

  MT("emStrongUnderscore",
     "[em _foo][emstrong __bar_][strong hello__] world");

  // "...same character must be used to open and close an emphasis span.""
  MT("emStrongMixed",
     "[em _foo][emstrong **bar*hello__ world]");

  MT("emStrongMixed",
     "[em *foo][emstrong __bar_hello** world]");

  // These characters should be escaped:
  // \   backslash
  // `   backtick
  // *   asterisk
  // _   underscore
  // {}  curly braces
  // []  square brackets
  // ()  parentheses
  // #   hash mark
  // +   plus sign
  // -   minus sign (hyphen)
  // .   dot
  // !   exclamation mark

  MT("escapeBacktick",
     "foo \\`bar\\`");

  MT("doubleEscapeBacktick",
     "foo \\\\[comment `bar\\\\`]");

  MT("escapeAsterisk",
     "foo \\*bar\\*");

  MT("doubleEscapeAsterisk",
     "foo \\\\[em *bar\\\\*]");

  MT("escapeUnderscore",
     "foo \\_bar\\_");

  MT("doubleEscapeUnderscore",
     "foo \\\\[em _bar\\\\_]");

  MT("escapeHash",
     "\\# foo");

  MT("doubleEscapeHash",
     "\\\\# foo");
})();


text:
<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://www.eclipse.org/jetty/configure.dtd">

<!-- DO NOT COMMIT THIS FILE BEFORE SCRUBBING AUTH DATA -->
<Configure class="org.eclipse.jetty.webapp.WebAppContext">
    <New id="BrokeDS" class="org.eclipse.jetty.plus.jndi.Resource">
        <Arg></Arg>
        <Arg>jdbc/BrokeDS</Arg>
        <Arg>
            <New class="com.mchange.v2.c3p0.ComboPooledDataSource">
                <Set name="driverClass">com.mysql.Driver</Set>
                <Set name="jdbcUrl">jdbc:mysql://localhost:3306/broke</Set>
                <Set name="user">root</Set>
                <Set name="password">mtrpls12</Set>
            </New>
        </Arg>
    </New>
</Configure>


text:
/**
 *
 */

angular.module('controller.setting.radio', [])
    .factory("radioList", function RadioList($rootScope, Units, TwStorage, Util, Push) {
        var radioList = {};
        radioList.type = "";
        radioList.title = "";
        radioList.list = [];
        radioList.value;

        radioList.importData = function (newList) {
            var list = [];
            newList.forEach(function (item) {
                var obj = {};
                ['label', 'value'].forEach(function (propertyName) {
                    obj[propertyName]  = item[propertyName];
                });
                list.push(obj);
            });
            this.list = list;
        };

        /**
         * 설정이 있는 ion-side-menu는  $ionicView.enter가 발생하지 않아, rootScope에 달아둠.
         * @param value
         */
        radioList.setValue = function (value) {
            this.value = value;
            if (this.type.indexOf('Unit') >= 0) {
                if (Units.setUnit(this.type, this.value)) {
                    Units.saveUnits();
                    Push.updateUnits();

                    if (this.type === 'airUnit') {
                        $rootScope.$broadcast('changeAirUnitEvent');
                    }
                }
            }
            else if (this.type === 'startupPage' || this.type === 'refreshInterval' || this.type === 'theme') {
                $rootScope.settingsInfo[this.type] = value;
                TwStorage.set("settingsInfo", $rootScope.settingsInfo);

                if (this.type === 'refreshInterval') {
                    $rootScope.$broadcast('reloadEvent', 'setRefreshInterval');
                } else if (this.type === 'theme') {
                    $rootScope.iconsImgPath = window.theme[$rootScope.settingsInfo.theme].icons;
                    $rootScope.weatherImgPath = window.theme[$rootScope.settingsInfo.theme].weather;

                    if (window.StatusBar && ionic.Platform.isIOS()) {
                        if ($rootScope.settingsInfo.theme === 'light') {
                            StatusBar.styleDefault();
                        } else { //photo, dark, old
                            StatusBar.styleLightContent();
                        }
                    }
                }
            }
            else {
                Util.ga.trackEvent('action', 'error', 'unknown type='+this.type);
            }
        };

        radioList.getValue = function () {
            return this.value;
        };

        return radioList;
    })
    .controller('RadioCtrl', function($rootScope, $scope, $ionicHistory, Util, radioList, WeatherInfo) {
        $scope.onClose = function() {
            Util.ga.trackEvent('action', 'click', 'setting.radio back');
            $ionicHistory.goBack();
        };

        console.info(JSON.stringify(radioList));

        function _resetUpdateTimeCities() {
            console.log('reset update time');
            for (var i = 0; i < WeatherInfo.getCityCount(); i += 1) {
                WeatherInfo.reloadCity(i);
            }
            $rootScope.$broadcast('reloadEvent', 'resume');
        }

        $scope.title = radioList.title;
        $scope.list = radioList.list;
        $scope.data = {value: radioList.getValue()};
        $scope.valueChanged = function(item) {
            radioList.setValue(item.value);
            _resetUpdateTimeCities();
        };
    });


text:
class BaseUser
  attr_accessor :name

  def initialize options = {}
    @name = options[:name] || 'no name'
  end

  def role_list_value
    instance_variable_get "@role_list"
  end

  def role_value
    instance_variable_get "@#{self.class.troles_config.role_field}"
  end

  def troles_changed?
    false
  end

  def trole_changed?
    false
  end

  def save
    true
  end
  alias_method :save!, :save
end


text:
var EndGate;
(function (EndGate) {
    (function (Tweening) {
        /// <reference path="ITweeningFunction.ts" />
        (function (Functions) {
            /**
            * Defines a Quintic tweening function collection that has an EaseIn, EaseOut, and EaseInOut function that can be used with Tween's.
            */
            var Quintic = (function () {
                function Quintic() {
                }
                Object.defineProperty(Quintic, "EaseIn", {
                    get: /**
                    * Gets the Quintic EaseIn function.
                    */
                    function () {
                        return Quintic._easeIn;
                    },
                    enumerable: true,
                    configurable: true
                });

                Object.defineProperty(Quintic, "EaseOut", {
                    get: /**
                    * Gets the Quintic EaseOut function.
                    */
                    function () {
                        return Quintic._easeOut;
                    },
                    enumerable: true,
                    configurable: true
                });

                Object.defineProperty(Quintic, "EaseInOut", {
                    get: /**
                    * Gets the Quintic EaseInOut function.
                    */
                    function () {
                        return Quintic._easeInOut;
                    },
                    enumerable: true,
                    configurable: true
                });
                Quintic._easeIn = function (from, to, elapsed, duration) {
                    var change = to - from, elapsedMilliseconds = elapsed.Milliseconds;

                    return change * (elapsedMilliseconds /= duration.Milliseconds) * elapsedMilliseconds * elapsedMilliseconds * elapsedMilliseconds * elapsedMilliseconds + from;
                };
                Quintic._easeOut = function (from, to, elapsed, duration) {
                    var change = to - from, elapsedMilliseconds = elapsed.Milliseconds;

                    return change * ((elapsedMilliseconds = elapsedMilliseconds / duration.Milliseconds - 1) * elapsedMilliseconds * elapsedMilliseconds * elapsedMilliseconds * elapsedMilliseconds + 1) + from;
                };
                Quintic._easeInOut = function (from, to, elapsed, duration) {
                    var change = to - from, elapsedMilliseconds = elapsed.Milliseconds;

                    if ((elapsedMilliseconds /= duration.Milliseconds / 2) < 1) {
                        return change / 2 * elapsedMilliseconds * elapsedMilliseconds * elapsedMilliseconds * elapsedMilliseconds * elapsedMilliseconds + from;
                    }
                    return change / 2 * ((elapsedMilliseconds -= 2) * elapsedMilliseconds * elapsedMilliseconds * elapsedMilliseconds * elapsedMilliseconds + 2) + from;
                };
                return Quintic;
            })();
            Functions.Quintic = Quintic;
        })(Tweening.Functions || (Tweening.Functions = {}));
        var Functions = Tweening.Functions;
    })(EndGate.Tweening || (EndGate.Tweening = {}));
    var Tweening = EndGate.Tweening;
})(EndGate || (EndGate = {}));


text:
ACCEPTED

#### According to
Index Fungorum

#### Published in
Sydowia 8(1-6): 108 (1954)

#### Original name
Tricholoma diemii Singer

### Remarks
null


text:
package views.formdata;

import models.User;

public class Login {
    public String username;
    public String password;

    public String validate() {
        if (User.authenticate(username, password) == null) {
            return "Invalid username or password";
        }
        return null;
    }
}


text:
package pdgf.core.dataGenerator;

import java.io.IOException;

import org.apache.log4j.Level;
import org.apache.log4j.Logger;

import pdgf.core.FieldValueDTO;
import pdgf.core.RowDataDTO;
import pdgf.core.dataGenerator.scheduler.Progress;
import pdgf.core.dataGenerator.scheduler.Scheduler;
import pdgf.core.dataGenerator.scheduler.WorkUnit;
import pdgf.core.dbSchema.Field;
import pdgf.core.dbSchema.Project;
import pdgf.core.dbSchema.Table;
import pdgf.plugin.Output;
import pdgf.util.Constants;

/**
 * The worker is responsible for generating its part of the Projects data. Is
 * responsible for correctly seeding the hirachical Random Number Generators,
 * creating the Generation context an delegating generated data beween
 * generators and Output
 *
 * @author Michael Frank
 * @version 1.0 08.06.2010
 *
 */
public final class Worker extends Thread {

	private static final Logger log = Logger.getLogger(Worker.class);
	private Object waiterMutex = new Object();
	// Worker context info
	private StringBuilder progressInformation = new StringBuilder();
	private Project project;
	private DataGenerator dg;
	private Scheduler scheduler;
	private WorkUnit workUnit;
	private boolean running;

	private int workerCount;
	private int workerID;
	private Output output;

	// statistics info
	private long percentageDone = 0;
	private long timeElapsedWU = 0;
	private long timeElapsedWorker = 0;
	private long timeRemaining = 0;
	private String currentTableName = "";

	/*
	 * eager initialization and variable reusage to avoid initialization and
	 * "new Object()" overhead in inner loop's
	 */
	// inner loop variables
	private long currentRowID;
	private int currentFieldId;

	private long currentTablePartionRowCount;
	private long workUnitRows;
	private long workUnitRowStart;
	private long workUnitRowStop;

	private long workerStartTime;
	private long lastStatusOutputTime = 0;
	private long workUnitStartTime = 0;

	private Table currentTable = null;
	private RowDataDTO rowData;
	private Field[] currentFields;

	private FieldValueDTO[] fieldValues;

	GenerationContext generationContext = new GenerationContext();
	private Table lastTable = null;
	private int nodeID;
	private boolean logStatistics = true;
	private boolean finished = false;
	private long rowsPerSecWu;

	/**
	 * Create new Worker
	 *
	 * @param p
	 *            the Project this worker belongs to
	 * @param workerCount
	 *            number of threads.
	 * @param workerID
	 *            of this thread between [1, threadCount]
	 */
	public Worker(Project p, int workerCount, int workerID, Scheduler scheduler) {
		this.project = p;
		this.workerCount = workerCount;
		this.workerID = workerID;
		this.scheduler = scheduler;

	}

	public void initialize() {
		this.output = project.getOutput();
		this.nodeID = 1;
		this.rowData = new RowDataDTO();
		this.workUnit = new WorkUnit();
		workUnit.workerCount = workerCount;
		workUnit.workerId = workerID; // workerid starts at 1
		generationContext = new GenerationContext(workerID, workerCount,
				project);
		finished = false;

		// // static rngs: project, generatorTest, and row Rng
		// try {
		// localProjectRNG = RandomFactory.instance().getRNGClass(
		// project.getRngName());
		// localProjectRNG.setSeed(project.getSeed());
		//
		// localRowRNG = RandomFactory.instance().getRNGClass(
		// project.getRngName());
		//
		// } catch (ClassNotFoundException e1) {
		// // should not happen, because Rng classname was already checked
		// // at config init
		// e1.printStackTrace();
		// }

	}

	@Override
	public void run() {
		running = true;
		log.debug("Node: " + nodeID + " worker " + (workerID) + "/"
				+ workerCount + " is now running");
		workerStartTime = System.currentTimeMillis();
		workUnitStartTime = System.currentTimeMillis();
		while (running) {
			doWork();
		}

	}

	private void doWork() {
		timeElapsedWU = (System.currentTimeMillis() - workUnitStartTime);
		workUnit.lastProccessingTime = timeElapsedWU;
		scheduler.getNextWorkunit(workUnit);

		if (workUnit.pause) {

			try {
				output.flush(workerID);
			} catch (IOException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}

			if (workUnit.finished) {
				updateStatistics();
				finished = workUnit.finished;
				log.debug("Node: " + nodeID + "worker " + (workerID) + "/"
						+ workerCount + " Status: finished generation after: "
						+ timeElapsedWU + "ms ");
			} else {

				log.info("Node: " + nodeID + "worker " + (workerID) + "/"
						+ workerCount + " Status: paused workunit: "
						+ timeElapsedWU + "ms ");
			}
			synchronized (waiterMutex) {
				try {
					waiterMutex.wait();
				} catch (InterruptedException e) {
					log.debug("Node: " + nodeID + "Worker " + (workerID)
							+ " was waiting: interupped");
				}

				if (!running) {
					// TODO! save current status;
					return;
				}
			}
		} else {

			doWorkUnit();
			updateStatistics();
		}
	}

	private void doWorkUnit() {
		workUnitStartTime = System.currentTimeMillis();

		// local caching of workunit information
		currentTable = workUnit.table;
		currentTableName = currentTable.getName();
		currentFields = currentTable.getChilds();
		workUnitRowStart = workUnit.rowStart;
		workUnitRowStop = workUnit.rowStop;
		currentTablePartionRowCount = workUnit.rowCountOfWorkunit;

		// Reinitialize shared objects for new partition
		if (lastTable == null || currentTable != lastTable) {
			rowData.reset(currentTable);
			fieldValues = rowData.getFieldValuesList();
		} else {
			for (FieldValueDTO fvdto : fieldValues) {
				fvdto.setValue(null);
				fvdto.setPlainValue(null);
			}

		}

		workUnitRows = workUnit.rowStop - workUnit.rowStart + 1;
		generationContext.set(currentTablePartionRowCount, workUnit.rowStart,
				workUnit.rowStop);

		log.debug("Node: " + nodeID + "worker " + (workerID) + "/"
				+ workUnit.workerCount + " is now proccessing table: \""
				+ currentTable.getName() + "\"");

		// iterate over rows in Table Partition of this WorkerThread
		generateRows();

		// one Table Finished, print info
		if (running) {
			log.debug("Node: " + nodeID + "worker " + (workerID) + "/"
					+ workerCount
					+ " finished proccessing a workunit for table: \""
					+ currentTable.getName() + "\" with " + workUnitRows
					+ "rows in: "
					+ (System.currentTimeMillis() - workUnitStartTime) + "ms");
		}
	}

	/**
	 * iterate over rows in Table Partition of this WorkerThread
	 */
	private void generateRows() {
		// iterate over rows in Table Partition of this WorkerThread
		for (currentRowID = workUnitRowStart; currentRowID <= workUnitRowStop; currentRowID++) {
			if (!running) {
				// TODO! save current status;
				return; // break;
			}

			generateRow();

			updateWuProgressInfo();
		}// one Table Finished

	}

	private void generateRow() {
		// reseed Row Rng
		// localRowRNG.setSeed(localTableRNG.nextLong());

		// update row in shared objects
		generationContext.setCurrentRow(currentRowID);
		rowData.setRow(currentRowID);

		// most inner loop: iterate over fields in row
		for (currentFieldId = 0; currentFieldId < currentFields.length; currentFieldId++) {
			currentFields[currentFieldId].getFieldValueForRow(
					generationContext, fieldValues[currentFieldId]);
		}

		// one Row finished, write row to output
		try {
			output.write(rowData, workerID);
		} catch (IOException e) {
			// FIXME! System.exit(-1);
			running = false;
			e.printStackTrace();
			System.exit(-1);
		}
	}

	private void updateWuProgressInfo() {
		// update Progress information
		if (logStatistics) {
			if ((System.currentTimeMillis() - lastStatusOutputTime) > Constants.GENERATION_PROGRESS_UPDATE_INTERVALL) {
				updateStatistics();
				lastStatusOutputTime = System.currentTimeMillis();
				progressInformation.setLength(0); // reset
				progressInformation.append("Node: ");
				progressInformation.append(nodeID);
				progressInformation.append(" ");
				progressInformation.append((workerID));
				progressInformation.append("/");
				progressInformation.append(workerCount);
				progressInformation.append(" \"");
				progressInformation.append(currentTableName);
				progressInformation.append("\" Status cur. workunit: ");
				progressInformation.append(getPercentageDone());
				progressInformation.append("% remaining: ");
				progressInformation.append((getTimeRemaining() / 1000));
				progressInformation.append("s elapsed: ");
				progressInformation.append((getTimeElapsedWU() / 1000));
				progressInformation.append("s current row: ");
				progressInformation.append(currentRowID);
				progressInformation.append(" Overall time:");
				progressInformation.append((getTimeElapsedWorker() / 1000));
				progressInformation.append("s");
				log.info(progressInformation);
			}
		}
	}

	/**
	 * @return the percentageDone for the current table
	 */
	public long getPercentageDone() {

		return percentageDone;
	}

	/**
	 * @return the timeElapsed for the current workunit
	 */
	public long getTimeElapsedWU() {

		return timeElapsedWU;
	}

	/**
	 * @return the timeElapsed for the current table
	 */
	public long getTimeElapsedWorker() {

		return timeElapsedWorker;
	}

	public void updateStatistics(Progress p) {

		updateStatistics();
		p.set(rowsPerSecWu, workUnitRowStart, workUnitRowStop,
				timeElapsedWorker, timeElapsedWU, timeRemaining,
				percentageDone, currentTable);

	}

	/**
	 * Updates processing statistics like timeElapsedWU,
	 * timeElapsedWorker,percentageDone,timeRemaining,rowsPerSecWu If values
	 * < 1 values are set to 1 to avoid divide by zero
	 */
	public void updateStatistics() {
		// if still running update value
		if (running && !finished) {
			timeElapsedWU = (System.currentTimeMillis() - workUnitStartTime);
			timeElapsedWU = timeElapsedWU == 0 ? 1 : timeElapsedWU;
			timeElapsedWorker = (System.currentTimeMillis() - workerStartTime);
			timeElapsedWorker = timeElapsedWorker == 0 ? 1 : timeElapsedWorker;

			percentageDone = ((100 * (currentRowID - workUnitRowStart + 1)) / (workUnitRows + 1));
			percentageDone = percentageDone == 0 ? 1 : percentageDone;

			timeRemaining = (timeElapsedWU * (100 - percentageDone) / percentageDone);
			timeRemaining = timeRemaining == 0 ? 1 : timeRemaining;

			rowsPerSecWu = (currentRowID - workUnitRowStart) / timeElapsedWU
					* 1000;
			rowsPerSecWu = rowsPerSecWu == 0 ? 1 : rowsPerSecWu;
		}

	}

	/**
	 * specifies if Worker should do his own statistics logging
	 *
	 * @param doLogging
	 */
	public void logStatistics(boolean doLogging) {
		log.setLevel(Level.WARN);
		logStatistics = doLogging;
	}

	/**
	 * @return the timeRemaining for the current table
	 */
	public long getTimeRemaining() {

		return timeRemaining;
	}

	/**
	 * @return the currentTable
	 */
	public String getCurrentTable() {
		return currentTableName;
	}

	public void stopWorker() {
		running = false;
		if (!finished) {
			updateStatistics();
		}

		synchronized (waiterMutex) {
			waiterMutex.notify();
		}

	}

	public void continueWorker() {
		if (running) {
			finished = false;
			synchronized (waiterMutex) {
				waiterMutex.notify();
			}
		}

	}

	public Scheduler getScheduler() {
		return scheduler;
	}

	public void setScheduler(Scheduler scheduler) {
		this.scheduler = scheduler;
	}

	public int getWorkerCount() {
		return workerCount;
	}

	public int getWorkerID() {
		return workerID;
	}

	public boolean isRunning() {
		return running;
	}

}


text:
from swgpy.object import *

def create(kernel):
	result = Creature()

	result.template = "object/mobile/shared_gamorrean.iff"
	result.attribute_template_id = 9
	result.stfName("npc_name","gamorrean_base_male")

	#### BEGIN MODIFICATIONS ####
	####  END MODIFICATIONS  ####

	return result


text:
/*
 * Erick Torres
 * ericktorres87@gmail.com
 */

Ti.include('database/database.js');

var editNote = function(id, currentTitle, currentNote){

	var formView = Ti.UI.createView({
		width:'80%',
		height:'80%',
		backgroundColor:'#2E9AFE',
		layout:'vertical'
	});

	var titleLabel = Ti.UI.createLabel({
		text:'TÍTULO:',
		font:{ fontSize:'18dp', fontWeight:'bold'},
		color:'#FFFFFF',
		top:'30dp'
	});

	var txtTitle = Ti.UI.createTextField({
		width:'90%',
		borderRadius:'5dp',
		borderColor:'#FF8000',
		top:'5dp',
		value:currentTitle
	});

	var contentLabel = Ti.UI.createLabel({
		text:'NOTA:',
		font:{ fontSize:'18dp', fontWeight:'bold'},
		color:'#FFFFFF',
		top:'10dp'
	});

	var txtContent = Ti.UI.createTextArea({
		width:'90%',
		height:'120dp',
		borderRadius:'5dp',
		borderColor:'#FF8000',
		top:'5dp',
		value:currentNote
	});

	var saveButton = Ti.UI.createButton({
		title:'SAVE',
		width:'200dp',
		height:'50dp',
		top:'30dp',
		bottom:'30dp'
	});
	saveButton.addEventListener('click', function(e){
		var title = txtTitle.value;
		var content = txtContent.value;
		var result = Ti.UI.createAlertDialog({ title:'AVISO' });

		if(addOrEditNote(2, id, title, content)){
			result.message = 'La nota ha sido guardada con éxito.';
			result.show();
		}else{
			result.message = 'Ha ocurrido un error.';
			result.show();
		}
	});

	formView.add(titleLabel);
	formView.add(txtTitle);
	formView.add(contentLabel);
	formView.add(txtContent);
	formView.add(saveButton);

	return formView;
};

module.exports = editNote;


text:
package org.apache.logging.log4j.message;

import static org.junit.jupiter.api.Assertions.assertEquals;

import java.util.Locale;
import java.util.ResourceBundle;

import org.junit.jupiter.api.Test;

/**
 * Tests {@link LocalizedMessageFactory}.
 */
public class LocalizedMessageFactoryTest {

    @Test
    public void testMessageMarkersDataNo() {
        final LocalizedMessageFactory localizedMessageFactory = new LocalizedMessageFactory(ResourceBundle.getBundle("MF", Locale.US));
        final Message message = localizedMessageFactory.newMessage("msg1");
        assertEquals("This is test number {0} with string argument {1}.", message.getFormattedMessage());
    }

    @Test
    public void testMessageMarkersNoDataYes() {
        final LocalizedMessageFactory localizedMessageFactory = new LocalizedMessageFactory(ResourceBundle.getBundle("MF", Locale.US));
        final Message message = localizedMessageFactory.newMessage("msg1", 1, "two");
        assertEquals("This is test number 1 with string argument two.", message.getFormattedMessage());
    }

    @Test
    public void testNewMessage() {
        final LocalizedMessageFactory localizedMessageFactory = new LocalizedMessageFactory(ResourceBundle.getBundle("MF", Locale.US));
        final Message message = localizedMessageFactory.newMessage("hello_world");
        assertEquals("Hello world.", message.getFormattedMessage());
    }

    @Test
    public void testNoMatch() {
        final LocalizedMessageFactory localizedMessageFactory = new LocalizedMessageFactory(ResourceBundle.getBundle("MF", Locale.US));
        final Message message = localizedMessageFactory.newMessage("no match");
        assertEquals("no match", message.getFormattedMessage());
    }

    @Test
    public void testNoMatchPercentInMessageNoArgsNo() {
        // LOG4J2-3458 LocalizedMessage causes a lot of noise on the console
        //
        // ERROR StatusLogger Unable to format msg: C:/Program%20Files/Some%20Company/Some%20Product%20Name/
        // java.util.UnknownFormatConversionException: Conversion = 'F'
        // at java.util.Formatter$FormatSpecifier.conversion(Formatter.java:2691)
        // at java.util.Formatter$FormatSpecifier.<init>(Formatter.java:2720)
        // at java.util.Formatter.parse(Formatter.java:2560)
        // at java.util.Formatter.format(Formatter.java:2501)
        // at java.util.Formatter.format(Formatter.java:2455)
        // at java.lang.String.format(String.java:2981)
        // at org.apache.logging.log4j.message.StringFormattedMessage.formatMessage(StringFormattedMessage.java:116)
        // at org.apache.logging.log4j.message.StringFormattedMessage.getFormattedMessage(StringFormattedMessage.java:88)
        // at org.apache.logging.log4j.message.FormattedMessage.getFormattedMessage(FormattedMessage.java:178)
        // at org.apache.logging.log4j.message.LocalizedMessage.getFormattedMessage(LocalizedMessage.java:196)
        // at
        // org.apache.logging.log4j.message.LocalizedMessageFactoryTest.testNoMatchPercentInMessage(LocalizedMessageFactoryTest.java:60)
        //
        final LocalizedMessageFactory localizedMessageFactory = new LocalizedMessageFactory(ResourceBundle.getBundle("MF", Locale.US));
        final Message message = localizedMessageFactory.newMessage("C:/Program%20Files/Some%20Company/Some%20Product%20Name/");
        assertEquals("C:/Program%20Files/Some%20Company/Some%20Product%20Name/", message.getFormattedMessage());
    }

    @Test
    public void testNoMatchPercentInMessageArgsYes() {
        final LocalizedMessageFactory localizedMessageFactory = new LocalizedMessageFactory(ResourceBundle.getBundle("MF", Locale.US));
        final Message message = localizedMessageFactory.newMessage("C:/Program%20Files/Some%20Company/Some%20Product%20Name/{0}", "One");
        assertEquals("C:/Program%20Files/Some%20Company/Some%20Product%20Name/One", message.getFormattedMessage());
    }
}


text:
package com.betfair.cougar.core.api.ev;

import java.util.List;
import java.util.Set;
import java.util.concurrent.Executor;

import com.betfair.cougar.api.ExecutionContext;

/**
 * An Execution Venue (EV) is a central location where operations and their implementations can be registered for execution.
 * The abstraction of the OperationDefiniton allows registration of Executables that may not be Java classes - for
 * example, the Executable may invoke an external script, or may forward the execution to another EV.
 *
 */
public interface ExecutionVenue {

	/**
	 * Registers an OperationDefinition against an actual Executable implementation
     * @param def defines the Operation and its parameters
     * @param executable the executable implementation of the operation
     * @param recorder Provides methods for recording execution statistics
     * @param maxExecutionTime The max amount of time (in ms) that this operation should be allowed to execute before
     *                         returning a timeout. A value of zero means there will be no timeout.
     */
	public void registerOperation(String namespace, OperationDefinition def, Executable executable, ExecutionTimingRecorder recorder, long maxExecutionTime);

	/**
	 * Gets the OperationDefinition that has been registered with the EV for the provided key
	 * @param key unique values of the operation (service name, service version and operation name)
	 * @return the registered OperationDefinition
	 */
	public OperationDefinition getOperationDefinition(OperationKey key);

	/**
	 * Gets the keys for all the Operations that have been registered with this EV.
	 * @return all registered OperationKeys
	 */
	public Set<OperationKey> getOperationKeys();

	/**
	 * Execute the Executable registered for the provided OperationKey on the current thread.
	 * @param ctx Provides contextual information for execution, such as channel id, user identity, geographical location etc.
	 * @param key Defines the operation to be executed
	 * @param args The arguments to be provided to the operation
	 * @param observer The ExecutionObserver is notified of either the result of the execution, or of an exception thrown during execution.
     * @param timeConstraints External constraints on the execution time of this call. These constraints may specify a
     *                        time that this execution request expires, after which point the call may be timed out. The client
     *                        doesn't guarantee to hang around waiting for the timeout response. A value of zero indicates no timeout
     *                        has been specified by the client.
	 */
	public void execute(ExecutionContext ctx, OperationKey key, Object[] args, ExecutionObserver observer, TimeConstraints timeConstraints);

	/**
	 * Execute the Executable registered for the provided OperationKey in the provided executor
	 * @param ctx Provides contextual information for execution, such as channel id, user identity, geographical location etc.
	 * @param key Defines the operation to be executed
	 * @param args The arguments to be provided to the operation
	 * @param observer The ExecutionObserver is notified of either the result of the execution, or of an exception thrown during execution.
     * @param executor An executor to perform this request on.
     * @param timeConstraints External constraints on the execution time of this call. These constraints may specify a
     *                        time that this execution request expires, after which point the call may be timed out. The client
     *                        doesn't guarantee to hang around waiting for the timeout response. A value of zero indicates no timeout
     *                        has been specified by the client.
	 */
	public void execute(ExecutionContext ctx, OperationKey key, Object[] args, ExecutionObserver observer, Executor executor, TimeConstraints timeConstraints);

	public void setPreProcessors(List<ExecutionPreProcessor> preProcessorList);

	public void setPostProcessors(List<ExecutionPostProcessor> preProcessorList);

}


text:
<?php

namespace wulaphp\util;
/**
 * Class ObjectCaller
 * @package wulaphp\util
 * @internal
 */
class ObjectCaller {

    /**
     * 调用对像的方法,最多10个参数.
     *
     * @param object $obj
     * @param string $method
     * @param array  $args
     *
     * @return mixed
     */
    public static function callObjMethod($obj, string $method, array $args = []) {
        return $obj->{$method} (...$args);
    }

    /**
     * @param string $clz
     * @param string $method
     * @param array  $args
     *
     * @return mixed
     */
    public static function callClzMethod(string $clz, string $method, array $args = []) {
        return $clz::{$method}(...$args);
    }
}


text:
module Zuora
  module Attributes
    def self.included(base)
      base.send(:include, ActiveModel::Naming)
      base.send(:include, ActiveModel::Conversion)
      base.send(:include, ActiveModel::Dirty)
      base.extend ClassMethods
    end

    module ClassMethods
      # Due to limitations of setting up attributes via the WSDL when
      # inherited, attribute definition is defined in a block format
      # so that the attributes are available and multiple decorators
      # can be applied to those attributes.
      def define_attributes(&block)
        yield self
        class_variable_get(:@@wsdl_attributes).each do |attr|
          class_eval <<-EVAL
            @@all_attributes << "#{attr}".to_sym

            define_method "#{attr}" do
              @#{attr}
            end

            define_method "#{attr}?" do
              #{attr} ? true : false
            end

            # writable attributes with dirty support
            define_method "#{attr}=" do |value|
              return if value == @#{attr}

              #{attr}_will_change!
              @#{attr} = value
            end
          EVAL
        end

        # generate association overrides for complex object handling
        # and cache the objects so that they may be modified and updated
        class_variable_get(:@@complex_attributes).each do |var, scope|
          # set up the instance variable for the new assoc collection
          # for new records, but call the original one for existing
          # records and cache/return the result for subsequent calls.
          class_eval <<-EVAL
            def #{scope}_with_complex
              if new_record? || @#{scope}_cached
                @#{scope} ||= []
              else
                @#{scope}_cached = true
                @#{scope} = #{scope}_without_complex
              end
            end
            alias_method_chain :#{scope}, :complex
          EVAL
        end
      end

      # Store attr_accessor and their values
      def store_accessors(storage_name)
        class_eval <<-EVAL, __FILE__, __LINE__ + 1
          define_method "#{storage_name}" do
            @#{storage_name} ||= {}
          end

          define_method "#{storage_name}=" do |value|
            @#{storage_name} = value
          end

          def attr_accessor(attribute)
            super

            define_method "\#{attribute}=" do |value|
              #{storage_name}[attribute] = value
              @@all_attributes << attribute.to_sym
              super
            end
          end
        EVAL
      end

      # define read only attributes which will not be sent
      # to the server when making update and create requests.
      def read_only(*args)
        class_variable_set(:@@read_only_attributes, args)
      end
      alias_method :read_only_attributes, :read_only

      # self evident?
      def write_only(*args)
        class_variable_set(:@@write_only_attributes, args)
      end
      alias_method :write_only_attributes, :write_only

      def defer(*args)
        class_variable_set(:@@deferred_attributes, args)
      end
      alias_method :deferred_attributes, :defer

      # alias to support a cleaner DSL for generating custom fattrs
      # and tracking the default attributes for dirty support
      def defaults(*args)
        class_variable_set(:@@default_attributes, args)
      end
      alias_method :default_attributes, :defaults

      # remove complex objects from the attributes as they should
      # be handled via associations instead being queried when
      # making remote query requests.
      def complex(*args)
        class_variable_set(:@@complex_attributes, *args)
        attrs = class_variable_get(:@@wsdl_attributes)
        class_variable_set(:@@wsdl_attributes, attrs - args)
      end
      alias_method :complex_attributes, :complex

      # store restrained attributes so they aren't sent on updates
      # TODO: rename to create_only as this is more obvious
      def restrain(*args)
        class_variable_set(:@@restrain_attributes, args)
      end
      alias_method :restrain_attributes, :restrain

      def attributes
        class_variable_get(:@@all_attributes).map(&:to_sym)
      end

      # the name to use when referencing remote Zuora objects
      def remote_name
        self.name.base_name
      end

      # All Zuora::Objects::Base inherited objects will have their attributes automatically
      # generated from the provided WSDL.
      def inherited(subclass)
        super
        xpath = "//xs:complexType[@name='#{subclass.remote_name}']//xs:sequence/xs:element"
        document = Zuora::Api.instance.client.wsdl.parser.instance_variable_get('@document')
        q = document.xpath(xpath, 's0' => 'http://schemas.xmlsoap.org/wsdl/', 'xs' => 'http://www.w3.org/2001/XMLSchema')
        wsdl_attrs = (q.map{|e| e.attributes['name'].value.underscore.to_sym }) << :id
        subclass.send(:class_variable_set, :@@wsdl_attributes,  wsdl_attrs)
        subclass.send(:class_variable_set, :@@read_only_attributes, [])
        subclass.send(:class_variable_set, :@@default_attributes, {})
        subclass.send(:class_variable_set, :@@complex_attributes, {})
        subclass.send(:class_variable_set, :@@restrain_attributes, [])
        subclass.send(:class_variable_set, :@@write_only_attributes, [])
        subclass.send(:class_variable_set, :@@deferred_attributes, [])
        subclass.send(:class_variable_set, :@@all_attributes, [])

        subclass.send(:define_attribute_methods, wsdl_attrs)
      end
    end

    # returns an array of symbols for all read only attributes.
    def read_only_attributes
      return [] unless self.class.class_variable_defined?(:@@read_only_attributes)
      self.class.send(:class_variable_get, :@@read_only_attributes)
    end

    # returns an array of symbols for all write only attributes.
    def write_only_attributes
      return [] unless self.class.class_variable_defined?(:@@write_only_attributes)
      self.class.send(:class_variable_get, :@@write_only_attributes)
    end

    # returns an array of symbols for all attributes read from WSDL.
    def wsdl_attributes
      return [] unless self.class.class_variable_defined?(:@@wsdl_attributes)
      self.class.send(:class_variable_get, :@@wsdl_attributes)
    end

    # attributes with a default value
    def default_attributes
      return [] unless self.class.class_variable_defined?(:@@default_attributes)
      self.class.send(:class_variable_get, :@@default_attributes)
    end

    # complex attribute mapping
    def complex_attributes
      return [] unless self.class.class_variable_defined?(:@@complex_attributes)
      self.class.send(:class_variable_get, :@@complex_attributes)
    end

    # attribute keys which can only be created but not updated
    def restrain_attributes
      return [] unless self.class.class_variable_defined?(:@@restrain_attributes)
      self.class.send(:class_variable_get, :@@restrain_attributes)
    end

    # attribute keys which are ignored by default
    def deferred_attributes
      return [] unless self.class.class_variable_defined?(:@@deferred_attributes)
      self.class.send(:class_variable_get, :@@deferred_attributes)
    end

    # a hash representation of all attributes including their values
    def attributes
      self.class.attributes.inject({}){|h,a| h.update a.to_sym => send(a)}
    end
    alias_method :to_hash, :attributes

    # remove all dirty tracking for the object and return self for chaining.
    def clear_changed_attributes!
      @changed_attributes = {}
      self
    end

    # the name to use when referencing remote Zuora objects
    def remote_name
      self.class.name.base_name
    end
  end
end


text:
package com.google.i18n.addressinput.common;

import java.util.Collections;
import java.util.EnumMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Wraps a Map of address property data to provide the AddressVerificationData API.
 */
public final class AddressVerificationData implements DataSource {
  private final Map<String, String> propertiesMap;

  private static final Pattern KEY_VALUES_PATTERN = Pattern.compile("\"([^\"]+)\":\"([^\"]*)\"");

  private static final Pattern SEPARATOR_PATTERN = Pattern.compile("\",\"");

  /**
   * Constructs from a map of address property data.  This keeps a reference to the map.  This
   * does not mutate the map. The map should not be mutated subsequent to this call.
   */
  public AddressVerificationData(Map<String, String> propertiesMap) {
    this.propertiesMap = propertiesMap;
  }

  /**
   * This will not return null.
   */
  @Override
  public AddressVerificationNodeData getDefaultData(String key) {
    // gets country key
    if (key.split("/").length > 1) {
      String[] parts = key.split("/");
      key = parts[0] + "/" + parts[1];
    }

    AddressVerificationNodeData data = get(key);
    if (data == null) {
      throw new RuntimeException("failed to get default data with key " + key);
    }
    return data;
  }

  @Override
  public AddressVerificationNodeData get(String key) {
    String json = propertiesMap.get(key);
    if (json != null && isValidDataKey(key)) {
      return createNodeData(json);
    }
    return null;
  }

  /**
   * Returns a set of the keys for which verification data is provided.  The returned set is
   * immutable.
   */
  Set<String> keys() {
    Set<String> result = new HashSet<String>();
    for (String key : propertiesMap.keySet()) {
      if (isValidDataKey(key)) {
        result.add(key);
      }
    }
    return Collections.unmodifiableSet(result);
  }

  /**
   * Returns whether the key is a "data" key rather than an "examples" key.
   */
  private boolean isValidDataKey(String key) {
    return key.startsWith("data");
  }

  /**
   * Returns the contents of the JSON-format string as a map.
   */
  AddressVerificationNodeData createNodeData(String json) {
    // Remove leading and trailing { and }.
    json = json.substring(1, json.length() - 1);
    Map<AddressDataKey, String> map = new EnumMap<AddressDataKey, String>(AddressDataKey.class);

    // our objects are very simple so we parse manually
    // - no double quotes within strings
    // - no extra spaces
    // can't use split "," since some data has commas in it.
    Matcher sm = SEPARATOR_PATTERN.matcher(json);
    int pos = 0;
    while (pos < json.length()) {
      String pair;
      if (sm.find()) {
        pair = json.substring(pos, sm.start() + 1);
        pos = sm.start() + 2;
      } else {
        pair = json.substring(pos);
        pos = json.length();
      }

      Matcher m = KEY_VALUES_PATTERN.matcher(pair);
      if (m.matches()) {
        String value = m.group(2);

        // Remove escaped backslashes.
        // Java regex doesn't handle a replacement String consisting of
        // a single backslash, and treats a replacement String consisting of
        // two backslashes as two backslashes instead of one.  So there's
        // no way to use regex to replace a match with a single backslash,
        // apparently.
        if (value.length() > 0) {
          char[] linechars = m.group(2).toCharArray();
          int w = 1;
          for (int r = w; r < linechars.length; ++r) {
            char c = linechars[r];
            if (c == '\\' && linechars[w - 1] == '\\') {
              // don't increment w;
              continue;
            }
            linechars[w++] = c;
          }
          value = new String(linechars, 0, w);
        }

        AddressDataKey df = AddressDataKey.get(m.group(1));
        if (df == null) {
          // Skip this data - it isn't used in the Android version.
        } else {
          map.put(df, value);
        }
      } else {
        // This is a runtime data sanity check.  The data should be
        // checked when the data is built.  The JSON data string should
        // be parsable into string pairs using SEP_PAT.
        throw new RuntimeException("could not match '" + pair + "' in '" + json + "'");
      }
    }

    return new AddressVerificationNodeData(map);
  }
}


text:
using System.Collections.Generic;
using Microsoft.Practices.Prism.Logging;

namespace Microsoft.Practices.Prism.UnityExtensions.Tests.Mocks
{
    internal class MockLoggerAdapter : ILoggerFacade
    {
        public IList<string> Messages = new List<string>();

        public void Log(string message, Category category, Priority priority)
        {
            Messages.Add(message);
        }
    }
}


text:
JG=$HOME/JGroups

jgroups.sh org.jgroups.tests.perf.MPerf $*


text:
package io.jenkins.blueocean.blueocean_github_pipeline;

import hudson.Extension;
import hudson.model.Job;
import hudson.scm.ChangeLogSet;
import io.jenkins.blueocean.rest.factory.BlueIssueFactory;
import io.jenkins.blueocean.rest.model.BlueIssue;
import jenkins.branch.MultiBranchProject;
import jenkins.scm.api.SCMSource;
import org.jenkinsci.plugins.github.config.GitHubServerConfig;
import org.jenkinsci.plugins.github_branch_source.GitHubSCMSource;
import org.jenkinsci.plugins.github_branch_source.HttpsRepositoryUriResolver;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class GithubIssue extends BlueIssue {

    private static final Pattern PATTERN = Pattern.compile("((?:[\\w-.]+\\/[\\w-.]+)?#[1-9]\\d*)");

    private final String id;
    private final String url;

    public GithubIssue(String id, String url) {
        this.id = id;
        this.url = url;
    }

    @Override
    public String getId() {
        return id;
    }

    @Override
    public String getURL() {
        return url;
    }

    @Extension
    public static class FactoryImpl extends BlueIssueFactory {
        @Override
        public Collection<BlueIssue> getIssues(Job job) {
            return null; // Github branches cannot be linked to tickets
        }

        @Override
        public Collection<BlueIssue> getIssues(ChangeLogSet.Entry changeSetEntry) {
            Job job = changeSetEntry.getParent().getRun().getParent();
            if (!(job.getParent() instanceof MultiBranchProject)) {
                return null;
            }
            MultiBranchProject mbp = (MultiBranchProject)job.getParent();
            List<SCMSource> scmSources = (List<SCMSource>) mbp.getSCMSources();
            SCMSource source = scmSources.isEmpty() ? null : scmSources.get(0);
            if (source == null || !(source instanceof GitHubSCMSource)) {
                return null;
            }
            GitHubSCMSource gitHubSource = (GitHubSCMSource)source;
            String url = gitHubSource.getApiUri();
            String apiUri = (url == null) ? GitHubServerConfig.GITHUB_URL : url;
            final String repositoryUri = new HttpsRepositoryUriResolver().getRepositoryUri(apiUri, gitHubSource.getRepoOwner(), gitHubSource.getRepository());
            Collection<BlueIssue> results = new ArrayList<>();
            for (String input : findIssueKeys(changeSetEntry.getMsg())) {
                String uri = repositoryUri.substring(0, repositoryUri.length() - 4);
                results.add(new GithubIssue("#" + input, String.format("%s/issues/%s", uri, input)));
            }
            return results;
        }

    }

    static Collection<String> findIssueKeys(String input) {
        Collection<String> ids = new ArrayList<>();
        Matcher m = PATTERN.matcher(input);
        while (m.find()) {
            if (m.groupCount() >= 1) {
                String issue = m.group(1);
                ids.add(issue.substring(1, issue.length()));
            }
        }
        return ids;
    }
}


text:
The `codegen` crate contains the code to convert from MIR into LLVM IR,
and then from LLVM IR into machine code. In general it contains code
that runs towards the end of the compilation process.

For more information about how codegen works, see the [rustc guide].

[rustc guide]: https://rust-lang.github.io/rustc-guide/codegen.html


text:
var request  = require('request');
var jwt      = require('jsonwebtoken');
var crud     = require('../libs/crud');
var auth     = require('../libs/auth');
var subs     = require('../libs/subscriptions');
var config   = require('../libs/config');

var express = require('express');
var router  = express.Router();

var apiKeyExtract = new RegExp(/[a-z,0-9]{32}/m);

module.exports = function (cmd_args) {

   var admin_dash_public_key = cmd_args.auth_server_public_key.replace(/'/g, "").replace(/"/g, '').replace(/\\n/g, "\n");

   return function (req, res, next) {

      jwt.verify(req.signedCookies.session, admin_dash_public_key, function (err, decoded) {

         if ( err ) {
            res.render('/admin/login')
         }
         else {

            auth.readClients(req.signedCookies.session, function (err, body) {
               var apps = [];
               var se = [];

               if ( undefined !== body.result ) {
                  for ( var i = 0; i < body.result.length; i++ ) {
                     var e = body.result[i];
                     apps.push(e)
                  }
               }

               res.render('addSubscription', {
                  user     : decoded.user_id,
                  'session': req.signedCookies.session,
                  'clients': apps
               });

            })
         }

      });
   };
};


text:
<component name="libraryTable">
  <library name="rules-0.5">
    <CLASSES>
      <root url="file://$USER_HOME$/.android/build-cache/0ba32db1998f17aefc6866211cbf9daca39d1d8d/output/res" />
      <root url="jar://$USER_HOME$/.android/build-cache/0ba32db1998f17aefc6866211cbf9daca39d1d8d/output/jars/classes.jar!/" />
    </CLASSES>
    <JAVADOC />
    <SOURCES>
      <root url="jar:///Applications/eclipse/sdk/extras/android/m2repository/com/android/support/test/rules/0.5/rules-0.5-sources.jar!/" />
    </SOURCES>
  </library>
</component>


text:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Alfred.Shared.Standard.Extensions
{
    public static class StringExtensions
    {
        public static IEnumerable<string> SafeSplit(this string ids, char splitter = ';')
        {
            return ids.Split(new[] { splitter }, StringSplitOptions.RemoveEmptyEntries).Select(x => x.Trim());
        }
    }
}