text:
import React, { useState } from 'react';

import { FormClose } from 'grommet-icons';
import { Box, Button, Select, Text } from 'grommet';

const allSeasons = [
  'S01',
  'S02',
  'S03',
  'S04',
  'S05',
  'S06',
  'S07',
  'S08',
  'S09',
  'S10',
];

export const Children = () => {
  const [selected, setSelected] = useState([]);

  const onRemoveSeason = (season) => {
    const seasonIndex = allSeasons.indexOf(season);
    setSelected(
      selected.filter((selectedSeason) => selectedSeason !== seasonIndex),
    );
  };

  const renderSeason = (season) => (
    <Button
      key={`season_tag_${season}`}
      href="#"
      onClick={(event) => {
        event.preventDefault();
        event.stopPropagation();
        onRemoveSeason(season);
      }}
      onFocus={(event) => event.stopPropagation()}
    >
      <Box
        align="center"
        direction="row"
        gap="xsmall"
        pad={{ vertical: 'xsmall', horizontal: 'small' }}
        margin="xsmall"
        background="brand"
        round="large"
      >
        <Text size="small">{season}</Text>
        <Box round="full" margin={{ left: 'xsmall' }}>
          <FormClose size="small" style={{ width: '12px', height: '12px' }} />
        </Box>
      </Box>
    </Button>
  );

  const renderOption = (option, state) => (
    <Box pad="small" background={state.active ? 'active' : undefined}>
      {option}
    </Box>
  );

  return (
    // Uncomment <Grommet> lines when using outside of storybook
    // <Grommet theme={...}>
    <Box fill align="center" justify="center">
      <Select
        closeOnChange={false}
        multiple
        value={
          <Box wrap direction="row" width="small">
            {selected && selected.length ? (
              selected.map((index) => renderSeason(allSeasons[index]))
            ) : (
              <Box
                pad={{ vertical: 'xsmall', horizontal: 'small' }}
                margin="xsmall"
              >
                Select Season
              </Box>
            )}
          </Box>
        }
        options={allSeasons}
        selected={selected}
        disabled={[2, 6]}
        onChange={({ selected: nextSelected }) => {
          setSelected([...nextSelected].sort());
        }}
      >
        {renderOption}
      </Select>
    </Box>
    // </Grommet>
  );
};

Children.parameters = {
  chromatic: { disable: true },
};

Children.args = {
  full: true,
};

export default {
  title: 'Input/Select/Children',
};


text:
package com.opengamma.strata.finance.rate.deposit;

import java.io.Serializable;
import java.time.LocalDate;
import java.time.Period;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Set;

import org.joda.beans.Bean;
import org.joda.beans.BeanDefinition;
import org.joda.beans.ImmutableBean;
import org.joda.beans.ImmutableValidator;
import org.joda.beans.JodaBeanUtils;
import org.joda.beans.MetaProperty;
import org.joda.beans.Property;
import org.joda.beans.PropertyDefinition;
import org.joda.beans.impl.direct.DirectFieldsBeanBuilder;
import org.joda.beans.impl.direct.DirectMetaBean;
import org.joda.beans.impl.direct.DirectMetaProperty;
import org.joda.beans.impl.direct.DirectMetaPropertyMap;

import com.opengamma.strata.basics.BuySell;
import com.opengamma.strata.collect.ArgChecker;
import com.opengamma.strata.finance.Template;

/**
 * A template for creating a term deposit trade.
 *

 * This defines almost all the data necessary to create a {@link TermDeposit}.
 * The trade date, notional and fixed rate are required to complete the template and create the trade.
 * As such, it is often possible to get a market price for a trade based on the template.
 * The market price is typically quoted as a bid/ask on the fixed rate.
 *

 * The template is defined by three dates.
 *

 *
Trade date, the date that the trade is agreed
 *
Start date or spot date, the date on which the deposit starts, typically 2 business days after the trade date
 *
End date, the date on which the implied deposit ends, typically a number of months after the start date
 *

 */
@BeanDefinition
public final class TermDepositTemplate
    implements Template, ImmutableBean, Serializable {

  /**
   * The period between the start date and the end date.
   */
  @PropertyDefinition(validate = "notNull")
  private final Period depositPeriod;
  /**
   * The underlying term deposit convention.
   *

   * This specifies the standard convention of the term deposit to be created.
   */
  @PropertyDefinition(validate = "notNull")
  private final TermDepositConvention convention;

  //-------------------------------------------------------------------------
  @ImmutableValidator
  private void validate() {
    ArgChecker.isFalse(depositPeriod.isNegative(), "Deposit Period must not be negative");
  }

  //-------------------------------------------------------------------------
  /**
   * Creates a template based on the specified period and convention.
   *
   * @param depositPeriod  the period between the start date and the end date
   * @param convention  the market convention
   * @return the template
   */
  public static TermDepositTemplate of(Period depositPeriod, TermDepositConvention convention) {
    ArgChecker.notNull(depositPeriod, "depositPeriod");
    ArgChecker.notNull(convention, "convention");
    return TermDepositTemplate.builder()
        .depositPeriod(depositPeriod)
        .convention(convention)
        .build();
  }

  //-------------------------------------------------------------------------
  /**
   * Creates a trade based on this template.
   *

   * This returns a trade based on the specified date.
   * The notional is unsigned, with buy/sell determining the direction of the trade.
   * If buying the term deposit, the principal is paid at the start date and the
   * principal plus interest is received at the end date.
   * If selling the term deposit, the principal is received at the start date and the
   * principal plus interest is paid at the end date.
   *
   * @param tradeDate  the date of the trade
   * @param buySell  the buy/sell flag, see {@link TermDeposit#getBuySell()}
   * @param notional  the notional amount, in the payment currency of the template
   * @param rate  the fixed rate, typically derived from the market
   * @return the trade
   */
  public TermDepositTrade toTrade(LocalDate tradeDate, BuySell buySell, double notional, double rate) {
    return convention.toTrade(tradeDate, depositPeriod, buySell, notional, rate);
  }

  //------------------------- AUTOGENERATED START -------------------------
  ///CLOVER:OFF
  /**
   * The meta-bean for {@code TermDepositTemplate}.
   * @return the meta-bean, not null
   */
  public static TermDepositTemplate.Meta meta() {
    return TermDepositTemplate.Meta.INSTANCE;
  }

  static {
    JodaBeanUtils.registerMetaBean(TermDepositTemplate.Meta.INSTANCE);
  }

  /**
   * The serialization version id.
   */
  private static final long serialVersionUID = 1L;

  /**
   * Returns a builder used to create an instance of the bean.
   * @return the builder, not null
   */
  public static TermDepositTemplate.Builder builder() {
    return new TermDepositTemplate.Builder();
  }

  private TermDepositTemplate(
      Period depositPeriod,
      TermDepositConvention convention) {
    JodaBeanUtils.notNull(depositPeriod, "depositPeriod");
    JodaBeanUtils.notNull(convention, "convention");
    this.depositPeriod = depositPeriod;
    this.convention = convention;
    validate();
  }

  @Override
  public TermDepositTemplate.Meta metaBean() {
    return TermDepositTemplate.Meta.INSTANCE;
  }

  @Override
  public <R> Property<R> property(String propertyName) {
    return metaBean().<R>metaProperty(propertyName).createProperty(this);
  }

  @Override
  public Set<String> propertyNames() {
    return metaBean().metaPropertyMap().keySet();
  }

  //-----------------------------------------------------------------------
  /**
   * Gets the period between the start date and the end date.
   * @return the value of the property, not null
   */
  public Period getDepositPeriod() {
    return depositPeriod;
  }

  //-----------------------------------------------------------------------
  /**
   * Gets the underlying term deposit convention.
   *

   * This specifies the standard convention of the term deposit to be created.
   * @return the value of the property, not null
   */
  public TermDepositConvention getConvention() {
    return convention;
  }

  //-----------------------------------------------------------------------
  /**
   * Returns a builder that allows this bean to be mutated.
   * @return the mutable builder, not null
   */
  public Builder toBuilder() {
    return new Builder(this);
  }

  @Override
  public boolean equals(Object obj) {
    if (obj == this) {
      return true;
    }
    if (obj != null && obj.getClass() == this.getClass()) {
      TermDepositTemplate other = (TermDepositTemplate) obj;
      return JodaBeanUtils.equal(getDepositPeriod(), other.getDepositPeriod()) &&
          JodaBeanUtils.equal(getConvention(), other.getConvention());
    }
    return false;
  }

  @Override
  public int hashCode() {
    int hash = getClass().hashCode();
    hash = hash * 31 + JodaBeanUtils.hashCode(getDepositPeriod());
    hash = hash * 31 + JodaBeanUtils.hashCode(getConvention());
    return hash;
  }

  @Override
  public String toString() {
    StringBuilder buf = new StringBuilder(96);
    buf.append("TermDepositTemplate{");
    buf.append("depositPeriod").append('=').append(getDepositPeriod()).append(',').append(' ');
    buf.append("convention").append('=').append(JodaBeanUtils.toString(getConvention()));
    buf.append('}');
    return buf.toString();
  }

  //-----------------------------------------------------------------------
  /**
   * The meta-bean for {@code TermDepositTemplate}.
   */
  public static final class Meta extends DirectMetaBean {
    /**
     * The singleton instance of the meta-bean.
     */
    static final Meta INSTANCE = new Meta();

    /**
     * The meta-property for the {@code depositPeriod} property.
     */
    private final MetaProperty<Period> depositPeriod = DirectMetaProperty.ofImmutable(
        this, "depositPeriod", TermDepositTemplate.class, Period.class);
    /**
     * The meta-property for the {@code convention} property.
     */
    private final MetaProperty<TermDepositConvention> convention = DirectMetaProperty.ofImmutable(
        this, "convention", TermDepositTemplate.class, TermDepositConvention.class);
    /**
     * The meta-properties.
     */
    private final Map<String, MetaProperty<?>> metaPropertyMap$ = new DirectMetaPropertyMap(
        this, null,
        "depositPeriod",
        "convention");

    /**
     * Restricted constructor.
     */
    private Meta() {
    }

    @Override
    protected MetaProperty<?> metaPropertyGet(String propertyName) {
      switch (propertyName.hashCode()) {
        case 14649855:  // depositPeriod
          return depositPeriod;
        case 2039569265:  // convention
          return convention;
      }
      return super.metaPropertyGet(propertyName);
    }

    @Override
    public TermDepositTemplate.Builder builder() {
      return new TermDepositTemplate.Builder();
    }

    @Override
    public Class<? extends TermDepositTemplate> beanType() {
      return TermDepositTemplate.class;
    }

    @Override
    public Map<String, MetaProperty<?>> metaPropertyMap() {
      return metaPropertyMap$;
    }

    //-----------------------------------------------------------------------
    /**
     * The meta-property for the {@code depositPeriod} property.
     * @return the meta-property, not null
     */
    public MetaProperty<Period> depositPeriod() {
      return depositPeriod;
    }

    /**
     * The meta-property for the {@code convention} property.
     * @return the meta-property, not null
     */
    public MetaProperty<TermDepositConvention> convention() {
      return convention;
    }

    //-----------------------------------------------------------------------
    @Override
    protected Object propertyGet(Bean bean, String propertyName, boolean quiet) {
      switch (propertyName.hashCode()) {
        case 14649855:  // depositPeriod
          return ((TermDepositTemplate) bean).getDepositPeriod();
        case 2039569265:  // convention
          return ((TermDepositTemplate) bean).getConvention();
      }
      return super.propertyGet(bean, propertyName, quiet);
    }

    @Override
    protected void propertySet(Bean bean, String propertyName, Object newValue, boolean quiet) {
      metaProperty(propertyName);
      if (quiet) {
        return;
      }
      throw new UnsupportedOperationException("Property cannot be written: " + propertyName);
    }

  }

  //-----------------------------------------------------------------------
  /**
   * The bean-builder for {@code TermDepositTemplate}.
   */
  public static final class Builder extends DirectFieldsBeanBuilder<TermDepositTemplate> {

    private Period depositPeriod;
    private TermDepositConvention convention;

    /**
     * Restricted constructor.
     */
    private Builder() {
    }

    /**
     * Restricted copy constructor.
     * @param beanToCopy  the bean to copy from, not null
     */
    private Builder(TermDepositTemplate beanToCopy) {
      this.depositPeriod = beanToCopy.getDepositPeriod();
      this.convention = beanToCopy.getConvention();
    }

    //-----------------------------------------------------------------------
    @Override
    public Object get(String propertyName) {
      switch (propertyName.hashCode()) {
        case 14649855:  // depositPeriod
          return depositPeriod;
        case 2039569265:  // convention
          return convention;
        default:
          throw new NoSuchElementException("Unknown property: " + propertyName);
      }
    }

    @Override
    public Builder set(String propertyName, Object newValue) {
      switch (propertyName.hashCode()) {
        case 14649855:  // depositPeriod
          this.depositPeriod = (Period) newValue;
          break;
        case 2039569265:  // convention
          this.convention = (TermDepositConvention) newValue;
          break;
        default:
          throw new NoSuchElementException("Unknown property: " + propertyName);
      }
      return this;
    }

    @Override
    public Builder set(MetaProperty<?> property, Object value) {
      super.set(property, value);
      return this;
    }

    @Override
    public Builder setString(String propertyName, String value) {
      setString(meta().metaProperty(propertyName), value);
      return this;
    }

    @Override
    public Builder setString(MetaProperty<?> property, String value) {
      super.setString(property, value);
      return this;
    }

    @Override
    public Builder setAll(Map<String, ? extends Object> propertyValueMap) {
      super.setAll(propertyValueMap);
      return this;
    }

    @Override
    public TermDepositTemplate build() {
      return new TermDepositTemplate(
          depositPeriod,
          convention);
    }

    //-----------------------------------------------------------------------
    /**
     * Sets the period between the start date and the end date.
     * @param depositPeriod  the new value, not null
     * @return this, for chaining, not null
     */
    public Builder depositPeriod(Period depositPeriod) {
      JodaBeanUtils.notNull(depositPeriod, "depositPeriod");
      this.depositPeriod = depositPeriod;
      return this;
    }

    /**
     * Sets the underlying term deposit convention.
     *

     * This specifies the standard convention of the term deposit to be created.
     * @param convention  the new value, not null
     * @return this, for chaining, not null
     */
    public Builder convention(TermDepositConvention convention) {
      JodaBeanUtils.notNull(convention, "convention");
      this.convention = convention;
      return this;
    }

    //-----------------------------------------------------------------------
    @Override
    public String toString() {
      StringBuilder buf = new StringBuilder(96);
      buf.append("TermDepositTemplate.Builder{");
      buf.append("depositPeriod").append('=').append(JodaBeanUtils.toString(depositPeriod)).append(',').append(' ');
      buf.append("convention").append('=').append(JodaBeanUtils.toString(convention));
      buf.append('}');
      return buf.toString();
    }

  }

  ///CLOVER:ON
  //-------------------------- AUTOGENERATED END --------------------------
}

redpajama_set_name: RedPajamaGithub


text:
package org.apache.flink.connector.file.src.enumerate;

import org.apache.flink.connector.file.src.FileSourceSplit;
import org.apache.flink.connector.file.src.testutils.TestingFileSystem;
import org.apache.flink.core.fs.Path;

import org.junit.After;
import org.junit.Test;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.stream.Collectors;

import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;

/**
 * Unit tests for the {@link NonSplittingRecursiveEnumerator}.
 */
public class NonSplittingRecursiveEnumeratorTest {

	/** Testing file system reference, to be cleaned up in an @After method. That way it also gets
	 * cleaned up on a test failure, without needing finally clauses in every test. */
	protected TestingFileSystem testFs;

	@After
	public void unregisterTestFs() throws Exception {
		if (testFs != null) {
			testFs.unregister();
		}
	}

	// ------------------------------------------------------------------------

	@Test
	public void testIncludeFilesFromNestedDirectories() throws Exception {
		final Path[] testPaths = new Path[] {
				new Path("testfs:///dir/file1"),
				new Path("testfs:///dir/nested/file.out"),
				new Path("testfs:///dir/nested/anotherfile.txt")};
		testFs = TestingFileSystem.createWithFiles("testfs", testPaths);
		testFs.register();

		final NonSplittingRecursiveEnumerator enumerator = createEnumerator();
		final Collection<FileSourceSplit> splits = enumerator.enumerateSplits(
				new Path[] { new Path("testfs:///dir")}, 1);

		assertThat(toPaths(splits), containsInAnyOrder(testPaths));
	}

	@Test
	public void testDefaultHiddenFilesFilter() throws Exception {
		final Path[] testPaths = new Path[] {
				new Path("testfs:///visiblefile"),
				new Path("testfs:///.hiddenfile1"),
				new Path("testfs:///_hiddenfile2")};
		testFs = TestingFileSystem.createWithFiles("testfs", testPaths);
		testFs.register();

		final NonSplittingRecursiveEnumerator enumerator = createEnumerator();
		final Collection<FileSourceSplit> splits = enumerator.enumerateSplits(
				new Path[] { new Path("testfs:///")}, 1);

		assertEquals(Collections.singletonList(new Path("testfs:///visiblefile")), toPaths(splits));
	}

	@Test
	public void testHiddenDirectories() throws Exception {
		final Path[] testPaths = new Path[] {
				new Path("testfs:///dir/visiblefile"),
				new Path("testfs:///dir/.hiddendir/file"),
				new Path("testfs:///_notvisible/afile")};
		testFs = TestingFileSystem.createWithFiles("testfs", testPaths);
		testFs.register();

		final NonSplittingRecursiveEnumerator enumerator = createEnumerator();
		final Collection<FileSourceSplit> splits = enumerator.enumerateSplits(
				new Path[] { new Path("testfs:///")}, 1);

		assertEquals(Collections.singletonList(new Path("testfs:///dir/visiblefile")), toPaths(splits));
	}

	@Test
	public void testFilesWithNoBlockInfo() throws Exception {
		final Path testPath = new Path("testfs:///dir/file1");
		testFs = TestingFileSystem.createForFileStatus(
				"testfs",
				TestingFileSystem.TestFileStatus.forFileWithBlocks(testPath, 12345L));
		testFs.register();

		final NonSplittingRecursiveEnumerator enumerator = createEnumerator();
		final Collection<FileSourceSplit> splits = enumerator.enumerateSplits(
				new Path[] { new Path("testfs:///dir")}, 0);

		assertEquals(1, splits.size());
		assertSplitsEqual(
				new FileSourceSplit("ignoredId", testPath, 0L, 12345L),
				splits.iterator().next());
	}

	@Test
	public void testFileWithIncorrectBlocks() throws Exception {
		final Path testPath = new Path("testfs:///testdir/testfile");

		testFs = TestingFileSystem.createForFileStatus(
				"testfs",
				TestingFileSystem.TestFileStatus.forFileWithBlocks(testPath, 10000L,
						new TestingFileSystem.TestBlockLocation(0L, 1000L),
						new TestingFileSystem.TestBlockLocation(2000L, 1000L)));
		testFs.register();

		final NonSplittingRecursiveEnumerator enumerator = createEnumerator();
		final Collection<FileSourceSplit> splits = enumerator.enumerateSplits(
				new Path[] { new Path("testfs:///testdir")}, 0);

		assertEquals(1, splits.size());
		assertSplitsEqual(
				new FileSourceSplit("ignoredId", testPath, 0L, 10000L),
				splits.iterator().next());
	}

	@Test
	public void testFileWithMultipleBlocks() throws Exception {
		final Path testPath = new Path("testfs:///dir/file");
		testFs = TestingFileSystem.createForFileStatus(
				"testfs",
				TestingFileSystem.TestFileStatus.forFileWithBlocks(testPath, 1000L,
						new TestingFileSystem.TestBlockLocation(0L, 100L, "host1", "host2"),
						new TestingFileSystem.TestBlockLocation(100L, 520L, "host2", "host3"),
						new TestingFileSystem.TestBlockLocation(620L, 380L, "host3", "host4")));
		testFs.register();

		final NonSplittingRecursiveEnumerator enumerator = createEnumerator();
		final Collection<FileSourceSplit> splits = enumerator.enumerateSplits(
				new Path[] { new Path("testfs:///dir")}, 0);

		assertSplitsEqual(
				new FileSourceSplit("ignoredId", testPath, 0L, 1000L, "host1", "host2", "host3", "host4"),
				splits.iterator().next());
	}

	// ------------------------------------------------------------------------

	/**
	 * The instantiation of the enumerator is overridable so that we can reuse these tests for sub-classes.
	 */
	protected NonSplittingRecursiveEnumerator createEnumerator() {
		return new NonSplittingRecursiveEnumerator();
	}

	// ------------------------------------------------------------------------

	protected static void assertSplitsEqual(final FileSourceSplit expected, final FileSourceSplit actual) {
		assertEquals(expected.path(), actual.path());
		assertEquals(expected.offset(), actual.offset());
		assertEquals(expected.length(), actual.length());
		assertArrayEquals(expected.hostnames(), actual.hostnames());
	}

	protected static void assertSplitsEqual(
			final Collection<FileSourceSplit> expected,
			final Collection<FileSourceSplit> actual) {

		assertEquals(expected.size(), actual.size());

		final ArrayList<FileSourceSplit> expectedCopy = new ArrayList<>(expected);
		final ArrayList<FileSourceSplit> actualCopy = new ArrayList<>(expected);
		expectedCopy.sort(NonSplittingRecursiveEnumeratorTest::compareFileSourceSplit);
		actualCopy.sort(NonSplittingRecursiveEnumeratorTest::compareFileSourceSplit);

		for (int i = 0; i < expectedCopy.size(); i++) {
			assertSplitsEqual(expectedCopy.get(i), actualCopy.get(i));
		}
	}

	protected static Collection<Path> toPaths(Collection<FileSourceSplit> splits) {
		return splits.stream().map(FileSourceSplit::path).collect(Collectors.toList());
	}

	private static int compareFileSourceSplit(FileSourceSplit a, FileSourceSplit b) {
		return Long.compare(a.offset(), b.offset());
	}
}


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

using System;
using Roslyn.Utilities;

namespace Microsoft.CodeAnalysis.LanguageServer.Handler
{
    internal partial class RequestExecutionQueue
    {
        internal class RequestMetrics
        {
            private readonly string _methodName;
            private readonly SharedStopwatch _sharedStopWatch;
            private TimeSpan? _queuedDuration;

            private readonly RequestTelemetryLogger _requestTelemetryLogger;

            public RequestMetrics(string methodName, RequestTelemetryLogger requestTelemetryLogger)
            {
                _methodName = methodName;
                _requestTelemetryLogger = requestTelemetryLogger;
                _sharedStopWatch = SharedStopwatch.StartNew();
            }

            public void RecordExecutionStart()
            {
                // Request has de-queued and is starting execution.  Record the time it spent in queue.
                _queuedDuration = _sharedStopWatch.Elapsed;
            }

            public void RecordSuccess()
            {
                RecordCompletion(RequestTelemetryLogger.Result.Succeeded);
            }

            public void RecordFailure()
            {
                RecordCompletion(RequestTelemetryLogger.Result.Failed);
            }

            public void RecordCancellation()
            {
                RecordCompletion(RequestTelemetryLogger.Result.Cancelled);
            }

            private void RecordCompletion(RequestTelemetryLogger.Result result)
            {
                Contract.ThrowIfNull(_queuedDuration, "RecordExecutionStart was not called");
                var overallDuration = _sharedStopWatch.Elapsed;
                _requestTelemetryLogger.UpdateTelemetryData(_methodName, _queuedDuration.Value, overallDuration, result);
            }
        }
    }
}


text:
@implementation DRIMessageViewControllerHelper

+ (UILabel *)noRichMessageViewWithTheme:(DCUITheme *)theme {

    UILabel *noRichMessages = [UILabel autoLayoutView];
    [noRichMessages setUserInteractionEnabled:NO];
    [noRichMessages setTextColor:[theme colourForKey:kDRUIInboxNoMessagesTextColour]];
    [noRichMessages setFont:[theme fontForKey:kDRUIInboxNoMessagesFont]];
    [noRichMessages setTextAlignment:NSTextAlignmentCenter];
    [noRichMessages setNumberOfLines:0];
    [noRichMessages setText:DRichMessageLocalizedString(@"rich_inbox_no_messages_selected")];

    return noRichMessages;
}

+ (void)addBarButtonItem:(UIBarButtonItem *)buttonItem buttonSide:(DonkyMessageViewBarButtonSide)side navigationController:(UINavigationItem *)navigationItem {
    if (side == DMVLeftSide) {
        NSMutableArray *leftBarButtonItems = [[navigationItem leftBarButtonItems] mutableCopy] ? : [[NSMutableArray alloc] init];
        [leftBarButtonItems addObject:buttonItem];
        navigationItem.leftBarButtonItems = leftBarButtonItems;
    }
    else {
        NSMutableArray *rightBarButtonItems = [[navigationItem rightBarButtonItems] mutableCopy] ? : [[NSMutableArray alloc] init];
        [rightBarButtonItems addObject:buttonItem];
        navigationItem.rightBarButtonItems = rightBarButtonItems;
    }
}

+ (void)removeBarButtonItem:(UIBarButtonItem *)buttonItem buttonSide:(DonkyMessageViewBarButtonSide)side navigationItem:(UINavigationItem *)navigationItem {
    if (side == DMVLeftSide) {
        NSMutableArray *leftBarButtonItems = [[navigationItem leftBarButtonItems] mutableCopy] ? : [[NSMutableArray alloc] init];
        [leftBarButtonItems removeObject:buttonItem];
        navigationItem.leftBarButtonItems = leftBarButtonItems;
    }
    else {
        NSMutableArray *rightBarButtonItems = [[navigationItem rightBarButtonItems] mutableCopy] ? : [[NSMutableArray alloc] init];
        [rightBarButtonItems removeObject:buttonItem];
        navigationItem.rightBarButtonItems = rightBarButtonItems;
    }
}

@end


text:
import { StringValidator } from "./Validation";

export const numberRegexp = /^[0-9]+$/;

export default class ZipCodeValidator implements StringValidator {
  isAcceptable(s: string) {
    return s.length === 5 && numberRegexp.test(s)
  }
}

// 或 export statements
// class ZipCodeValidator implements StringValidator {
//   isAcceptable(s: string) {
//     return s.length === 5 && numberRegexp.test(s)
//   }
// }
// export {ZipCodeValidator};
// export {ZipCodeValidator as mainValidator};


text:
<?xml version="1.0" encoding="utf-8"?><!--
  ~ Copyright (C) 2015 The Android Open Source Project
  ~
  ~ 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.
-->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout
        android:id="@+id/admob_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:orientation="vertical" />

    <android.support.design.widget.CoordinatorLayout
        android:id="@+id/main_content"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_above="@id/admob_view"
        android:layout_alignParentTop="true"
        android:background="#fff"
        android:fitsSystemWindows="true">

        <android.support.design.widget.AppBarLayout
            android:id="@+id/appbar"
            android:layout_width="match_parent"
            android:layout_height="@dimen/news_image_size"
            android:fitsSystemWindows="true"
            android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

            <android.support.design.widget.CollapsingToolbarLayout
                android:id="@+id/collapsing_toolbar"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:fitsSystemWindows="true"
                app:contentScrim="?attr/colorPrimary"
                app:expandedTitleMarginEnd="64dp"
                app:expandedTitleMarginStart="48dp"
                app:layout_scrollFlags="scroll|exitUntilCollapsed">

                <ImageView
                    android:id="@+id/backdrop"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:fitsSystemWindows="true"
                    android:scaleType="centerCrop"
                    app:layout_collapseMode="parallax" />

                <android.support.v7.widget.Toolbar
                    android:id="@+id/toolbar"
                    android:layout_width="match_parent"
                    android:layout_height="?attr/actionBarSize"
                    app:layout_collapseMode="pin"
                    app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

            </android.support.design.widget.CollapsingToolbarLayout>

        </android.support.design.widget.AppBarLayout>

        <android.support.v4.widget.NestedScrollView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_behavior="@string/appbar_scrolling_view_behavior">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical">

                <LinearLayout
                    android:id="@+id/header_session"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:background="@color/primary"
                    android:clipChildren="false"
                    android:clipToPadding="false"
                    android:orientation="vertical"
                    android:padding="@dimen/keyline_1">

                    <!-- News title -->
                    <TextView
                        android:id="@+id/news_title"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_gravity="start"
                        android:layout_marginBottom="0dp"
                        android:ellipsize="end"
                        android:lineSpacingMultiplier="1.1"
                        android:maxLines="3"
                        android:textAppearance="@style/TextAppearance.AppCompat.Title"
                        android:textColor="@color/primary_text" />

                    <!-- News subtitle -->
                    <TextView
                        android:id="@+id/pub_date"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_gravity="start"
                        android:ellipsize="end"
                        android:singleLine="true"
                        android:textAppearance="@style/TextAppearance.AppCompat.Subhead"
                        android:textColor="@color/secondary_text" />
                </LinearLayout>

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:background="#fff"
                    android:clipToPadding="false"
                    android:orientation="vertical">

                    <TextView
                        android:id="@+id/news_content"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:padding="@dimen/keyline_1"
                        android:textAppearance="@style/TextAppearance.AppCompat.Body2"
                        android:textColor="@color/primary_text" />

                </LinearLayout>

            </LinearLayout>
        </android.support.v4.widget.NestedScrollView>

        <android.support.design.widget.FloatingActionButton
            android:id="@+id/floating_button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:clickable="true"
            android:src="@drawable/ic_send"
            app:layout_anchor="@id/appbar"
            app:layout_anchorGravity="bottom|right|end" />

    </android.support.design.widget.CoordinatorLayout>
</RelativeLayout>


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

namespace DBMigrator.Model
{
    public class DowngradeScript : MigrationScript
    {
        public UpgradeScript UpgradeScript { get; set; }

        public DowngradeScript(string fileName, int order, Feature feature) : base(fileName, order, feature)
        {
        }
    }
}


text:
<?php

class ZendX_Wsdl_Exception {

}


text:
"""
A sample code for deep learning

Copyright (C) 2017 Shunjiro Yatsuzuka
"""

__author__ = "Shunjiro Yatsuzuka"
__copyright__ = "Copyright (c) 2017 Shunjiro Yatsuzuka"
__date__ = "March.12, 2017"
__version__ = "0.1"

#======= Import Modules =======

#----- Keras -----

from keras.models import Sequential
from keras.layers import Dense, Dropout, Activation, Flatten
from keras.layers import Convolution2D, MaxPooling2D

#======= Model =======

def create_model (input_shape, output_shape):

    model = Sequential()

    model.add(Convolution2D(32, 5, 5, border_mode='same', input_shape=input_shape))
    model.add(Activation('relu'))
    model.add(MaxPooling2D(pool_size=(2, 2)))
    model.add(Dropout(0.25))

    model.add(Convolution2D(64, 5, 5, border_mode='same'))
    model.add(Activation('relu'))
    model.add(MaxPooling2D(pool_size=(2, 2)))
    model.add(Dropout(0.25))

    model.add(Convolution2D(128, 5, 5, border_mode='same'))
    model.add(Activation('relu'))
    model.add(MaxPooling2D(pool_size=(2, 2)))
    model.add(Dropout(0.25))

    model.add(Flatten())
    model.add(Dense(512))
    model.add(Activation('relu'))
    model.add(Dropout(0.5))
    model.add(Dense(output_shape))
    model.add(Activation('softmax'))

    return model


text:
/*
 * Based on the HID++ 1.0 documentation provided by Nestor Lopez Casado at:
 *   https://drive.google.com/folderview?id=0BxbRzx7vEV7eWmgwazJ3NUFfQ28&usp=sharing
 */

/*
 * for this driver to work, you need a kernel >= v3.19 or one which contains
 * 925f0f3ed24f98b40c28627e74ff3e7f9d1e28bc ("HID: logitech-dj: allow transfer
 * of HID++ reports from/to the correct dj device")
 */

#include "config.h"

#include <linux/types.h>
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>

#include "hidpp20.h"

#include "libratbag-private.h"
#include "libratbag-hidraw.h"
#include "libratbag-data.h"

#define HIDPP_CAP_RESOLUTION_2200			(1 << 0)
#define HIDPP_CAP_SWITCHABLE_RESOLUTION_2201		(1 << 1)
#define HIDPP_CAP_BUTTON_KEY_1b04			(1 << 2)
#define HIDPP_CAP_BATTERY_LEVEL_1000			(1 << 3)
#define HIDPP_CAP_KBD_REPROGRAMMABLE_KEYS_1b00		(1 << 4)
#define HIDPP_CAP_COLOR_LED_EFFECTS_8070		(1 << 5)
#define HIDPP_CAP_ONBOARD_PROFILES_8100			(1 << 6)
#define HIDPP_CAP_LED_SW_CONTROL_1300			(1 << 7)
#define HIDPP_CAP_ADJUSTIBLE_REPORT_RATE_8060		(1 << 8)
#define HIDPP_CAP_BATTERY_VOLTAGE_1001			(1 << 9)
#define HIDPP_CAP_RGB_EFFECTS_8071			(1 << 10)

#define HIDPP_HIDDEN_FEATURE				(1 << 6)

struct hidpp20drv_data {
	struct hidpp20_device *dev;
	unsigned long capabilities;
	unsigned num_sensors;
	struct hidpp20_sensor *sensors;
	unsigned num_controls;
	struct hidpp20_control_id *controls;
	struct hidpp20_profiles *profiles;
	struct hidpp20_led *leds;
	union hidpp20_generic_led_zone_info led_infos;

	unsigned int report_rates[4];
	unsigned int num_report_rates;

	unsigned int num_profiles;
	unsigned int num_resolutions;
	unsigned int num_buttons;
	unsigned int num_leds;
};

static void
hidpp20drv_read_button_1b04(struct ratbag_button *button)
{
	struct ratbag_device *device = button->profile->device;
	struct hidpp20drv_data *drv_data = ratbag_get_drv_data(device);
	struct hidpp20_control_id *control;
	const struct ratbag_button_action *action;
	uint16_t mapping;

	if (!(drv_data->capabilities & HIDPP_CAP_BUTTON_KEY_1b04))
		return;

	control = &drv_data->controls[button->index];
	mapping = control->control_id;
	if (control->reporting.remapped)
		mapping = control->reporting.remapped;
	log_raw(device->ratbag,
		  " - button%d: %s (%02x) %s%s:%d\n",
		  button->index,
		  hidpp20_1b04_get_logical_mapping_name(mapping),
		  mapping,
		  control->reporting.divert || control->reporting.persist ? "(redirected) " : "",
		  __FILE__, __LINE__);
	button->type = hidpp20_1b04_get_physical_mapping(control->task_id);
	action = hidpp20_1b04_get_logical_mapping(mapping);
	if (action)
		ratbag_button_set_action(button, action);

	ratbag_button_enable_action_type(button, RATBAG_BUTTON_ACTION_TYPE_BUTTON);
	ratbag_button_enable_action_type(button, RATBAG_BUTTON_ACTION_TYPE_KEY);
	ratbag_button_enable_action_type(button, RATBAG_BUTTON_ACTION_TYPE_SPECIAL);
}

static unsigned int
hidpp20drv_read_macro_key_8100(struct ratbag_device *device, union hidpp20_macro_data *macro)
{
	switch (macro->key.modifier) {
	case 0x01: return KEY_LEFTCTRL;
	case 0x02: return KEY_LEFTSHIFT;
	case 0x04: return KEY_LEFTALT;
	case 0x08: return KEY_LEFTMETA;
	case 0x10: return KEY_RIGHTCTRL;
	case 0x20: return KEY_RIGHTSHIFT;
	case 0x40: return KEY_RIGHTALT;
	case 0x80: return KEY_RIGHTMETA;
	}

	return ratbag_hidraw_get_keycode_from_keyboard_usage(device, macro->key.key);
}

static int
hidpp20drv_read_macro_8100(struct ratbag_button *button,
			   struct hidpp20_profile *profile,
			   union hidpp20_button_binding *binding)
{
	struct ratbag_device *device = button->profile->device;
	struct ratbag_button_macro *m;
	union hidpp20_macro_data *macro;
	unsigned int i, keycode;
	bool delay = true;

	macro = profile->macros[binding->macro.page];

	if (!macro)
		return -EINVAL;

	i = 0;

	m = ratbag_button_macro_new("macro");

	while (macro && macro->any.type != HIDPP20_MACRO_END && i < MAX_MACRO_EVENTS) {
		switch (macro->any.type) {
		case HIDPP20_MACRO_DELAY:
			ratbag_button_macro_set_event(m,
						      i++,
						      RATBAG_MACRO_EVENT_WAIT,
						      macro->delay.time);
			delay = true;
			break;
		case HIDPP20_MACRO_KEY_PRESS:
			keycode = hidpp20drv_read_macro_key_8100(device, macro);
			if (!delay)
				ratbag_button_macro_set_event(m,
							      i++,
							      RATBAG_MACRO_EVENT_WAIT,
							      1);
			ratbag_button_macro_set_event(m,
						      i++,
						      RATBAG_MACRO_EVENT_KEY_PRESSED,
						      keycode);
			delay = false;
			break;
		case HIDPP20_MACRO_KEY_RELEASE:
			keycode = hidpp20drv_read_macro_key_8100(device, macro);
			if (!delay)
				ratbag_button_macro_set_event(m,
							      i++,
							      RATBAG_MACRO_EVENT_WAIT,
							      1);
			ratbag_button_macro_set_event(m,
						      i++,
						      RATBAG_MACRO_EVENT_KEY_RELEASED,
						      keycode);
			delay = false;
			break;
		}
		macro++;
	}

	ratbag_button_copy_macro(button, m);
	ratbag_button_macro_unref(m);

	return 0;
}

static void
hidpp20drv_read_button_8100(struct ratbag_button *button)
{
	struct ratbag_device *device = button->profile->device;
	struct hidpp20drv_data *drv_data = ratbag_get_drv_data(device);
	struct hidpp20_profile *profile;
	unsigned int modifiers = 0;
	int rc;

	if (!(drv_data->capabilities & HIDPP_CAP_ONBOARD_PROFILES_8100))
		return;

	profile = &drv_data->profiles->profiles[button->profile->index];

	switch (profile->buttons[button->index].any.type) {
	case HIDPP20_BUTTON_HID_TYPE:
		switch (profile->buttons[button->index].subany.subtype) {
		case HIDPP20_BUTTON_HID_TYPE_MOUSE:
			button->action.type = RATBAG_BUTTON_ACTION_TYPE_BUTTON;
			button->action.action.button = profile->buttons[button->index].button.buttons;
			break;
		case HIDPP20_BUTTON_HID_TYPE_KEYBOARD:
			button->action.type = RATBAG_BUTTON_ACTION_TYPE_KEY;
			button->action.action.key.key = ratbag_hidraw_get_keycode_from_keyboard_usage(device,
								profile->buttons[button->index].keyboard_keys.key);
			modifiers = profile->buttons[button->index].keyboard_keys.modifier_flags;
			break;
		case HIDPP20_BUTTON_HID_TYPE_CONSUMER_CONTROL:
			button->action.type = RATBAG_BUTTON_ACTION_TYPE_KEY;
			button->action.action.key.key = ratbag_hidraw_get_keycode_from_consumer_usage(device,
								profile->buttons[button->index].consumer_control.consumer_control);
			break;
		}
		break;
	case HIDPP20_BUTTON_SPECIAL:
		button->action.type = RATBAG_BUTTON_ACTION_TYPE_SPECIAL;
		button->action.action.special = hidpp20_onboard_profiles_get_special(profile->buttons[button->index].special.special);
		break;
	case HIDPP20_BUTTON_MACRO:
		rc = hidpp20drv_read_macro_8100(button, profile, &profile->buttons[button->index]);
		if (rc)
			button->action.type = RATBAG_BUTTON_ACTION_TYPE_NONE;
		break;
	default:
		button->action.type = RATBAG_BUTTON_ACTION_TYPE_UNKNOWN;
		break;
	}

	if (button->action.type == RATBAG_BUTTON_ACTION_TYPE_KEY) {
		int rc;

		rc = ratbag_button_macro_new_from_keycode(button,
							  button->action.action.key.key,
							  modifiers);
		if (rc < 0) {
			log_error(device->ratbag,
				  "Error while reading button %d\n",
				  button->index);
			button->action.type = RATBAG_BUTTON_ACTION_TYPE_NONE;
		}
	}

	ratbag_button_enable_action_type(button, RATBAG_BUTTON_ACTION_TYPE_BUTTON);
	ratbag_button_enable_action_type(button, RATBAG_BUTTON_ACTION_TYPE_KEY);
	ratbag_button_enable_action_type(button, RATBAG_BUTTON_ACTION_TYPE_SPECIAL);
	ratbag_button_enable_action_type(button, RATBAG_BUTTON_ACTION_TYPE_MACRO);
}

static void
hidpp20drv_read_button(struct ratbag_button *button)
{
	hidpp20drv_read_button_1b04(button);
	hidpp20drv_read_button_8100(button);
}

static void
hidpp20drv_read_led_1300(struct ratbag_led *led, struct hidpp20drv_data* data)
{
	struct hidpp20_led_sw_ctrl_led_state state;
	struct hidpp20_led_sw_ctrl_led_info *info;
	int rc;

	info = &data->led_infos.leds[led->index];

	rc = hidpp20_led_sw_control_get_led_state(data->dev, led->index, &state);

	if (rc != 0)
		return;

	led->colordepth = RATBAG_LED_COLORDEPTH_MONOCHROME;

	switch (info->type)
	{
	case HIDPP20_LED_TYPE_LOGO:
		led->type = RATBAG_LED_TYPE_LOGO;
		break;
	case HIDPP20_LED_TYPE_BATTERY:
		led->type = RATBAG_LED_TYPE_BATTERY;
		break;
	case HIDPP20_LED_TYPE_DPI:
		led->type = RATBAG_LED_TYPE_DPI;
		break;
	case HIDPP20_LED_TYPE_PROFILE:
	case HIDPP20_LED_TYPE_COSMETIC:
		led->type = RATBAG_LED_TYPE_SIDE;
		break;
	}

	switch (state.mode)
	{
	case HIDPP20_LED_MODE_OFF:
		led->mode = RATBAG_LED_OFF;
		break;
	case HIDPP20_LED_MODE_ON:
		led->mode = RATBAG_LED_ON;
		break;
	case HIDPP20_LED_MODE_BREATHING:
		led->mode = RATBAG_LED_BREATHING;
		led->ms = state.breathing.period;
		led->brightness = state.breathing.brightness;
		break;
	default:
		led->mode = RATBAG_LED_ON;
	}

	if (info->caps & HIDPP20_LED_MODE_ON)
		ratbag_led_set_mode_capability(led, RATBAG_LED_ON);
	if (info->caps & HIDPP20_LED_MODE_OFF)
		ratbag_led_set_mode_capability(led, RATBAG_LED_OFF);
	if (info->caps & (HIDPP20_LED_MODE_BLINK | HIDPP20_LED_MODE_TRAVEL |
			  HIDPP20_LED_MODE_RAMP_UP | HIDPP20_LED_MODE_RAMP_DOWN |
			  HIDPP20_LED_MODE_HEARTBEAT | HIDPP20_LED_MODE_BREATHING))
		ratbag_led_set_mode_capability(led, RATBAG_LED_BREATHING);
}

static void
hidpp20drv_read_led_8070(struct ratbag_led *led, struct hidpp20drv_data* drv_data)
{
	struct hidpp20_profile *profile;
	struct hidpp20_led h_led_val;
	struct hidpp20_led *h_led = &h_led_val;
	struct hidpp20_color_led_zone_info* led_info;
	struct hidpp20_color_led_info info;
	int rc;

	led_info = &drv_data->led_infos.color_leds_8070[led->index];

	if (drv_data->capabilities & HIDPP_CAP_ONBOARD_PROFILES_8100) {
		profile = &drv_data->profiles->profiles[led->profile->index];
		h_led = &profile->leds[led->index];
	} else {
		rc = hidpp20_color_led_effects_get_zone_effect(drv_data->dev, led->index, h_led);
		if (rc) {
			log_debug(led->profile->device->ratbag,
				  "Failed to read led settings\n");
		}
	}

	switch (h_led->mode) {
	case HIDPP20_LED_ON:
		led->mode = RATBAG_LED_ON;
		break;
	case HIDPP20_LED_CYCLE:
		led->mode = RATBAG_LED_CYCLE;
		break;
	case HIDPP20_LED_BREATHING:
		led->mode = RATBAG_LED_BREATHING;
		break;
	default:
		led->mode = RATBAG_LED_OFF;
		break;
	}

	/* pre-filled, only override if unknown */
	if (led->type == RATBAG_LED_TYPE_UNKNOWN)
		led->type = hidpp20_led_get_location_mapping(led_info->location);
	led->color.red = h_led->color.red;
	led->color.green = h_led->color.green;
	led->color.blue = h_led->color.blue;
	led->ms = h_led->period;
	led->brightness = h_led->brightness * 255 / 100;

	rc = hidpp20_color_led_effects_get_info(drv_data->dev, &info);
	if (rc == 0 &&
	    info.ext_caps & HIDPP20_COLOR_LED_INFO_EXT_CAP_MONOCHROME_ONLY)
		led->colordepth = RATBAG_LED_COLORDEPTH_MONOCHROME;
	else
		led->colordepth = RATBAG_LED_COLORDEPTH_RGB_888;

	for (int i = 0; i < led_info->num_effects; i++) {
		struct hidpp20_color_led_zone_effect_info ei;
		rc = hidpp20_color_led_effect_get_zone_effect_info(drv_data->dev,
								   led_info->index,
								   i, &ei);
		if (rc < 0)
			break;

		switch (ei.effect_id) {
		case HIDPP20_COLOR_LED_ZONE_EFFECT_DISABLED:
			ratbag_led_set_mode_capability(led, RATBAG_LED_OFF);
			break;
		case HIDPP20_COLOR_LED_ZONE_EFFECT_FIXED:
			ratbag_led_set_mode_capability(led, RATBAG_LED_ON);
			break;
		case HIDPP20_COLOR_LED_ZONE_EFFECT_CYCLING:
			ratbag_led_set_mode_capability(led, RATBAG_LED_CYCLE);
			break;
		case HIDPP20_COLOR_LED_ZONE_EFFECT_WAVE:
		case HIDPP20_COLOR_LED_ZONE_EFFECT_BREATHING:
			ratbag_led_set_mode_capability(led, RATBAG_LED_BREATHING);
			break;
		default:
			log_debug(led->profile->device->ratbag,
				  "%s: Unsupported effect (%d)\n",
				  led->profile->device->name,
				  ei.effect_id);
			break;
		}
	}
}

static void
hidpp20drv_read_led_8071(struct ratbag_led *led, struct hidpp20drv_data* drv_data)
{
	struct hidpp20_profile *profile;
	struct hidpp20_led *h_led;
	struct hidpp20_rgb_device_info device_info;
	struct hidpp20_rgb_cluster_info cluster_info;
	int rc;

	hidpp20_rgb_effects_get_device_info(drv_data->dev, &device_info);
	cluster_info = drv_data->led_infos.color_leds_8071[led->index];
	profile = &drv_data->profiles->profiles[led->profile->index];
	h_led = &profile->leds[led->index];

	switch (h_led->mode) {
	case HIDPP20_LED_ON:
		led->mode = RATBAG_LED_ON;
		break;
	case HIDPP20_LED_CYCLE:
		led->mode = RATBAG_LED_CYCLE;
		break;
	case HIDPP20_LED_BREATHING:
		led->mode = RATBAG_LED_BREATHING;
		break;
	default:
		led->mode = RATBAG_LED_OFF;
		break;
	}

	/* pre-filled, only override if unknown */
	if (led->type == RATBAG_LED_TYPE_UNKNOWN)
		led->type = hidpp20_led_get_location_mapping(cluster_info.location);
	led->color.red = h_led->color.red;
	led->color.green = h_led->color.green;
	led->color.blue = h_led->color.blue;
	led->ms = h_led->period;
	led->brightness = h_led->brightness * 255 / 100;

	if (device_info.ext_caps & HIDPP20_COLOR_LED_INFO_EXT_CAP_MONOCHROME_ONLY)
		led->colordepth = RATBAG_LED_COLORDEPTH_MONOCHROME;
	else
		led->colordepth = RATBAG_LED_COLORDEPTH_RGB_888;

	for (int i = 0; i < cluster_info.num_effects; i++) {
		struct hidpp20_rgb_effect_info ei;
		rc = hidpp20_rgb_effects_get_effect_info(drv_data->dev,
							 cluster_info.index,
							 i, &ei);
		if (rc < 0)
			break;

		switch (ei.effect_id) {
		case HIDPP20_COLOR_LED_ZONE_EFFECT_DISABLED:
			ratbag_led_set_mode_capability(led, RATBAG_LED_OFF);
			break;
		case HIDPP20_COLOR_LED_ZONE_EFFECT_FIXED:
			ratbag_led_set_mode_capability(led, RATBAG_LED_ON);
			break;
		case HIDPP20_COLOR_LED_ZONE_EFFECT_CYCLING:
			ratbag_led_set_mode_capability(led, RATBAG_LED_CYCLE);
			break;
		case HIDPP20_COLOR_LED_ZONE_EFFECT_WAVE:
		case HIDPP20_COLOR_LED_ZONE_EFFECT_BREATHING:
			ratbag_led_set_mode_capability(led, RATBAG_LED_BREATHING);
			break;
		default:
			log_debug(led->profile->device->ratbag,
				  "%s: Unsupported effect (%d)\n",
				  led->profile->device->name,
				  ei.effect_id);
			break;
		}
	}
}

static void
hidpp20drv_read_led(struct ratbag_led *led)
{
	struct ratbag_device *device = led->profile->device;
	struct hidpp20drv_data *drv_data = ratbag_get_drv_data(device);

	if (drv_data->capabilities & HIDPP_CAP_COLOR_LED_EFFECTS_8070)
		hidpp20drv_read_led_8070(led, drv_data);
	else if (drv_data->capabilities & HIDPP_CAP_RGB_EFFECTS_8071)
		hidpp20drv_read_led_8071(led, drv_data);
	else if (drv_data->capabilities & HIDPP_CAP_LED_SW_CONTROL_1300)
		hidpp20drv_read_led_1300(led, drv_data);
}

static int
hidpp20drv_update_button_1b04(struct ratbag_button *button)
{
	struct ratbag_device *device = button->profile->device;
	struct hidpp20drv_data *drv_data = ratbag_get_drv_data(device);
	struct hidpp20_control_id *control;
	struct ratbag_button_action *action = &button->action;
	uint16_t mapping;
	int rc;

	if (!(drv_data->capabilities & HIDPP_CAP_BUTTON_KEY_1b04))
		return -ENOTSUP;

	control = &drv_data->controls[button->index];
	mapping = hidpp20_1b04_get_logical_control_id(action);
	if (!mapping)
		return -EINVAL;

	control->reporting.divert = 0;
	control->reporting.remapped = mapping;
	control->reporting.updated = 1;

	rc = hidpp20_special_key_mouse_set_control(drv_data->dev, control);
	if (rc)
		log_error(device->ratbag,
			  "Error while writing profile: '%s' (%d)\n",
			  strerror(-rc),
			  rc);

	return rc;
}

static int
hidpp20drv_update_button_8100(struct ratbag_button *button)
{
	struct ratbag_device *device = button->profile->device;
	struct hidpp20drv_data *drv_data = ratbag_get_drv_data(device);
	struct hidpp20_profile *profile;
	struct ratbag_button_action *action = &button->action;
	unsigned int modifiers, key;
	int rc;
	uint8_t code, type, subtype;

	if (!(drv_data->capabilities & HIDPP_CAP_ONBOARD_PROFILES_8100))
		return -ENOTSUP;

	profile = &drv_data->profiles->profiles[button->profile->index];

	switch (action->type) {
	case RATBAG_BUTTON_ACTION_TYPE_BUTTON:
		profile->buttons[button->index].button.type = HIDPP20_BUTTON_HID_TYPE;
		profile->buttons[button->index].button.subtype = HIDPP20_BUTTON_HID_TYPE_MOUSE;
		profile->buttons[button->index].button.buttons = action->action.button;
		break;
	case RATBAG_BUTTON_ACTION_TYPE_MACRO:
		type = HIDPP20_BUTTON_HID_TYPE;
		subtype = HIDPP20_BUTTON_HID_TYPE_KEYBOARD;
		rc = ratbag_action_keycode_from_macro(action,
						      &key,
						      &modifiers);
		if (rc < 0) {
			log_error(device->ratbag,
				  "Error while writing macro for button %d\n",
				  button->index);
		}

		code = ratbag_hidraw_get_keyboard_usage_from_keycode(device, key);
		if (code == 0) {
			subtype = HIDPP20_BUTTON_HID_TYPE_CONSUMER_CONTROL;
			code = ratbag_hidraw_get_consumer_usage_from_keycode(device, key);
			if (code == 0)
				return -EINVAL;
		}
		profile->buttons[button->index].subany.type = type;
		profile->buttons[button->index].subany.subtype = subtype;
		if (subtype == HIDPP20_BUTTON_HID_TYPE_KEYBOARD) {
			profile->buttons[button->index].keyboard_keys.key = code;
			profile->buttons[button->index].keyboard_keys.modifier_flags = modifiers;
		} else {
			profile->buttons[button->index].consumer_control.consumer_control = code;
		}
		break;
	case RATBAG_BUTTON_ACTION_TYPE_KEY:
		type = HIDPP20_BUTTON_HID_TYPE;
		subtype = HIDPP20_BUTTON_HID_TYPE_KEYBOARD;
		code = ratbag_hidraw_get_keyboard_usage_from_keycode(device, action->action.key.key);
		if (code == 0) {
			subtype = HIDPP20_BUTTON_HID_TYPE_CONSUMER_CONTROL;
			code = ratbag_hidraw_get_consumer_usage_from_keycode(device, action->action.key.key);
			if (code == 0)
				return -EINVAL;
		}
		profile->buttons[button->index].subany.type = type;
		profile->buttons[button->index].subany.subtype = subtype;
		if (subtype == HIDPP20_BUTTON_HID_TYPE_KEYBOARD)
			profile->buttons[button->index].keyboard_keys.key = code;
		else
			profile->buttons[button->index].consumer_control.consumer_control = code;
		break;
	case RATBAG_BUTTON_ACTION_TYPE_SPECIAL:
		code = hidpp20_onboard_profiles_get_code_from_special(action->action.special);
		if (code == 0)
			return -EINVAL;
		profile->buttons[button->index].special.type = HIDPP20_BUTTON_SPECIAL;
		profile->buttons[button->index].special.special = code;
		break;
	default:
		return -ENOTSUP;
	}

	return 0;
}

static int
hidpp20drv_update_button(struct ratbag_button *button)
{
	struct ratbag_device *device = button->profile->device;
	struct hidpp20drv_data *drv_data = ratbag_get_drv_data(device);

	if (drv_data->capabilities & HIDPP_CAP_ONBOARD_PROFILES_8100)
		return hidpp20drv_update_button_8100(button);

	if (drv_data->capabilities & HIDPP_CAP_BUTTON_KEY_1b04)
		return hidpp20drv_update_button_1b04(button);

	return -ENOTSUP;
}

static int
hidpp20drv_update_led_1300(struct ratbag_led *led, struct hidpp20drv_data *data)
{
	const uint16_t led_caps = data->led_infos.leds[led->index].caps;
	struct hidpp20_led_sw_ctrl_led_state h_led;
	int rc;

	h_led.index = led->index;

	switch(led->mode)
	{
	case RATBAG_LED_BREATHING:
		h_led.mode = HIDPP20_LED_MODE_BREATHING;
		h_led.breathing.brightness = led->brightness;
		h_led.breathing.period = led->ms;
		h_led.breathing.timeout = 300;
		break;
	case RATBAG_LED_OFF:
		h_led.mode = HIDPP20_LED_MODE_OFF;
		h_led.on.index = HIDPP20_LED_SW_CONTROL_LED_INDEX_ALL;
		break;
	case RATBAG_LED_ON:
		h_led.mode = HIDPP20_LED_MODE_ON;
		h_led.on.index = HIDPP20_LED_SW_CONTROL_LED_INDEX_ALL;
		break;
	case RATBAG_LED_CYCLE:
		return -ENOTSUP;
	}

	if (!(h_led.mode & led_caps)) {
		hidpp_log_error(&data->dev->base, "LED %d does not support effect %s(%04x), supports %04x\n",
						led->index, hidpp20_sw_led_control_get_mode_string(h_led.mode),
						h_led.mode, led_caps);
		return -ENOTSUP;
	}

	if (!hidpp20_led_sw_control_get_sw_ctrl(data->dev)) {
		rc = hidpp20_led_sw_control_set_sw_ctrl(data->dev, true);
		if (rc)
			return rc;
	}

	rc = hidpp20_led_sw_control_set_led_state(data->dev, &h_led);
	if (rc)
		return rc;

	/*
	 * We revert to HW control of the LEDs.
	 * This effectively disable the capability of changing the DPI/profile
	 * LEDs, but this allows to make them work with the internal DPI/profile
	 * switches.
	 *
	 * The net result is:
	 * - DPI/profiles can't be controlled (but who wants this?)
	 * - The logo can properly controlled
	 */
	rc = hidpp20_led_sw_control_set_sw_ctrl(data->dev, false);
	if (rc)
		return rc;

	return RATBAG_SUCCESS;
}

static int
hidpp20drv_update_led_8070_8071(struct ratbag_led *led, struct ratbag_profile* profile,
				struct hidpp20drv_data *drv_data)
{
	struct hidpp20_profile *h_profile;
	struct hidpp20_led h_led_val;
	struct hidpp20_led *h_led = &h_led_val;

	if (drv_data->capabilities & HIDPP_CAP_ONBOARD_PROFILES_8100) {
		h_profile = &drv_data->profiles->profiles[profile->index];
		h_led = &(h_profile->leds[led->index]);
	}

	if (!h_led)
		return -EINVAL;

	switch (led->mode) {
	case RATBAG_LED_ON:
		h_led->mode = HIDPP20_LED_ON;
		break;
	case RATBAG_LED_CYCLE:
		h_led->mode = HIDPP20_LED_CYCLE;
		break;
	case RATBAG_LED_BREATHING:
		h_led->mode = HIDPP20_LED_BREATHING;
		break;
	default:
		h_led->mode = HIDPP20_LED_OFF;
		break;
	}
	h_led->color.red = led->color.red;
	h_led->color.green = led->color.green;
	h_led->color.blue = led->color.blue;
	h_led->period = led->ms;
	h_led->brightness = led->brightness * 100 / 255;

	if (!(drv_data->capabilities & HIDPP_CAP_ONBOARD_PROFILES_8100)) {
		if (drv_data->capabilities & HIDPP_CAP_COLOR_LED_EFFECTS_8070)
			hidpp20_color_led_effects_set_zone_effect(drv_data->dev,
								  led->index,
								  h_led_val);
	}

	return RATBAG_SUCCESS;
}

static int
hidpp20drv_update_led(struct ratbag_led *led)
{
	struct ratbag_profile *profile = led->profile;
	struct ratbag_device *device = profile->device;
	struct hidpp20drv_data *drv_data = ratbag_get_drv_data(device);

	if ((drv_data->capabilities & HIDPP_CAP_COLOR_LED_EFFECTS_8070) |
	    (drv_data->capabilities & HIDPP_CAP_RGB_EFFECTS_8071))
		return hidpp20drv_update_led_8070_8071(led, profile, drv_data);

	if (drv_data->capabilities & HIDPP_CAP_LED_SW_CONTROL_1300)
		return hidpp20drv_update_led_1300(led, drv_data);

	return RATBAG_ERROR_CAPABILITY;
}

static int
hidpp20drv_current_profile(struct ratbag_device *device)
{
	struct hidpp20drv_data *drv_data = ratbag_get_drv_data((struct ratbag_device *)device);
	int rc;

	if (!(drv_data->capabilities & HIDPP_CAP_ONBOARD_PROFILES_8100))
		return 0;

	rc = hidpp20_onboard_profiles_get_current_profile(drv_data->dev);
	if (rc < 0)
		return rc;

	return rc - 1;
}

static int
hidpp20drv_set_current_profile(struct ratbag_device *device, unsigned int index)
{
	struct hidpp20drv_data *drv_data = ratbag_get_drv_data((struct ratbag_device *)device);
	struct hidpp20_profile *h_profile;
	int rc;

	if (!(drv_data->capabilities & HIDPP_CAP_ONBOARD_PROFILES_8100))
		return 0;

	if (index >= drv_data->num_profiles)
		return -EINVAL;

	h_profile = &drv_data->profiles->profiles[index];
	if (!h_profile->enabled) {
		h_profile->enabled = 1;
		rc = hidpp20_onboard_profiles_commit(drv_data->dev, drv_data->profiles);
		if (rc)
			return rc;
	}

	return hidpp20_onboard_profiles_set_current_profile(drv_data->dev, index);
}

static int
hidpp20drv_read_resolution_dpi_2201(struct ratbag_device *device)
{
	struct hidpp20drv_data *drv_data = ratbag_get_drv_data(device);
	struct ratbag *ratbag = device->ratbag;
	int rc;

	free(drv_data->sensors);
	drv_data->sensors = NULL;
	drv_data->num_sensors = 0;
	rc = hidpp20_adjustable_dpi_get_sensors(drv_data->dev, &drv_data->sensors);
	if (rc < 0) {
		log_error(ratbag,
			  "Error while requesting resolution: %s (%d)\n",
			  strerror(-rc), rc);
		return rc;
	} else if (rc == 0) {
		log_error(ratbag, "Error, no compatible sensors found.\n");
		return -ENODEV;
	}
	log_debug(ratbag,
		  "device is at %d dpi (variable between %d and %d).\n",
		  drv_data->sensors[0].dpi,
		  drv_data->sensors[0].dpi_min,
		  drv_data->sensors[0].dpi_max);

	drv_data->num_sensors = rc;

	/* if 0x8100 has already been enumerated we already have the supported
	 * number of resolutions and shouldn't overwrite it
	 */
	if (!(drv_data->capabilities & HIDPP_CAP_ONBOARD_PROFILES_8100))
		drv_data->num_resolutions = drv_data->num_sensors;

	return 0;
}

static int
hidpp20drv_read_report_rate_8060(struct ratbag_device *device)
{
	struct hidpp20drv_data *drv_data = ratbag_get_drv_data(device);
	struct ratbag *ratbag = device->ratbag;
	struct ratbag_profile *profile;
	uint8_t bitflags_ms;
	int nrates = 0;
	int rc;
	uint8_t rate_ms;
	unsigned rate_hz;

	rc = hidpp20_adjustable_report_rate_get_report_rate_list(drv_data->dev,
								 &bitflags_ms);
	if (rc < 0)
		return rc;

	/* We only care about 'standard' rates */
	if (bitflags_ms & 0x80)
		drv_data->report_rates[nrates++] = 125;
	if (bitflags_ms & 0x8)
		drv_data->report_rates[nrates++] = 250;
	if (bitflags_ms & 0x2)
		drv_data->report_rates[nrates++] = 500;
	if (bitflags_ms & 0x1)
		drv_data->report_rates[nrates++] = 1000;

	drv_data->num_report_rates = nrates;

	if (!hidpp20_adjustable_report_rate_get_report_rate(drv_data->dev, &rate_ms)) {
		switch (rate_ms)
		{
		case 1:
			rate_hz = 1000;
			break;
		case 2:
		case 3: /* 3ms = 333.(3)Hz, we round to 500Hz */
			rate_hz = 500;
			break;
		case 4:
		case 5: /* 5ms = 200Hz, we round to 250Hz */
			rate_hz = 250;
			break;
		case 6: /* 6ms = 166.(6)Hz, we round to 125Hz */
		case 7: /* 7ms = 142Hz, we round to 125Hz */
		case 8:
			rate_hz = 125;
			break;
		default:
			rate_hz = 0;
			break;
		}

		if (rate_hz) {
			log_debug(ratbag, "report rate is %u\n", rate_hz);
			ratbag_device_for_each_profile(device, profile)
				profile->hz = rate_hz;
		}
	}

	log_debug(ratbag, "device has %d report rates\n", nrates);

	return 0;
}

static int
hidpp20drv_read_resolution_dpi(struct ratbag_profile *profile)
{
	struct ratbag_device *device = profile->device;
	struct ratbag *ratbag = device->ratbag;
	struct hidpp20drv_data *drv_data = ratbag_get_drv_data(device);
	struct ratbag_resolution *res;
	unsigned int default_dpi = 1000;
	unsigned int default_rate = 500;
	int rc;

	if ((drv_data->capabilities & HIDPP_CAP_RESOLUTION_2200) &&
	    (drv_data->capabilities & HIDPP_CAP_SWITCHABLE_RESOLUTION_2201) == 0) {
		uint16_t resolution;
		uint8_t flags;

		rc = hidpp20_mousepointer_get_mousepointer_info(drv_data->dev, &resolution, &flags);
		if (rc) {
			log_error(ratbag,
				  "Error while requesting resolution: %s (%d)\n",
				  strerror(-rc), rc);
			return rc;
		}

		return 0;
	}

	if (drv_data->capabilities & HIDPP_CAP_SWITCHABLE_RESOLUTION_2201) {
		rc = hidpp20drv_read_resolution_dpi_2201(device);
		if (rc < 0)
			return rc;

		ratbag_profile_for_each_resolution(profile, res) {
			struct hidpp20_sensor *sensor;

			/* We only look at the first sensor. Multiple
			 * sensors is too niche to care about right now */
			sensor = &drv_data->sensors[0];

			/* FIXME: retrieve the refresh rate */
			ratbag_resolution_set_resolution(res, sensor->dpi, sensor->dpi);
			ratbag_resolution_set_dpi_list_from_range(res,
								  sensor->dpi_min,
								  sensor->dpi_max);
			/* FIXME: we mark all resolutions as active because
			 * they are from different sensors */
			res->is_active = true;
		}
	} else {
		ratbag_profile_for_each_resolution(profile, res)
			ratbag_resolution_set_dpi_list(res, &default_dpi, 1);
	}

	if (drv_data->capabilities & HIDPP_CAP_ADJUSTIBLE_REPORT_RATE_8060) {
		rc = hidpp20drv_read_report_rate_8060(device);
		if (rc < 0 && drv_data->report_rates[0] == 0)
			return rc;

		ratbag_profile_set_report_rate_list(profile,
						    drv_data->report_rates,
						    drv_data->num_report_rates);
	} else {
		ratbag_profile_set_report_rate_list(profile, &default_rate, 1);
	}

	return 0;
}

static int
hidpp20drv_update_resolution_dpi_8100(struct ratbag_resolution *resolution,
				      int dpi_x, int dpi_y)
{
	struct ratbag_profile *profile = resolution->profile;
	struct ratbag_device *device = profile->device;
	struct hidpp20drv_data *drv_data = ratbag_get_drv_data(device);
	struct hidpp20_profile *h_profile;
	int dpi = dpi_x; /* dpi_x == dpi_y if we don't have the individual resolution cap */

	h_profile = &drv_data->profiles->profiles[profile->index];
	h_profile->dpi[resolution->index] = dpi;

	if (resolution->is_default)
		h_profile->default_dpi = resolution->index;

	return RATBAG_SUCCESS;
}

static int
hidpp20drv_update_resolution_dpi(struct ratbag_resolution *resolution,
				 int dpi_x, int dpi_y)
{
	struct ratbag_profile *profile = resolution->profile;
	struct ratbag_device *device = profile->device;
	struct hidpp20drv_data *drv_data = ratbag_get_drv_data(device);
	struct hidpp20_sensor *sensor;
	int i;
	int dpi = dpi_x; /* dpi_x == dpi_y if we don't have the individual resolution cap */

	if (drv_data->capabilities & HIDPP_CAP_ONBOARD_PROFILES_8100)
		return hidpp20drv_update_resolution_dpi_8100(resolution, dpi_x, dpi_y);

	if (!(drv_data->capabilities & HIDPP_CAP_SWITCHABLE_RESOLUTION_2201))
		return -ENOTSUP;

	if (!drv_data->num_sensors)
		return -ENOTSUP;

	/* just for clarity, we use the first available sensor only */
	sensor = &drv_data->sensors[0];

	/* validate that the sensor accepts the given DPI */
	if (dpi < sensor->dpi_min || dpi > sensor->dpi_max)
		return -EINVAL;
	if (sensor->dpi_steps) {
		for (i = sensor->dpi_min; i < dpi; i += sensor->dpi_steps) {
		}
		if (i != dpi)
			return -EINVAL;
	} else {
		i = 0;
		while (sensor->dpi_list[i]) {
			if (sensor->dpi_list[i] == dpi)
				break;
		}
		if (sensor->dpi_list[i] != dpi)
			return -EINVAL;
	}

	return hidpp20_adjustable_dpi_set_sensor_dpi(drv_data->dev, sensor, dpi);
}

static int
hidpp20drv_update_report_rate_8060(struct ratbag_profile *profile, int hz)
{
	struct ratbag_device *device = profile->device;
	struct hidpp20drv_data *drv_data = ratbag_get_drv_data(device);
	int rc;

	rc = hidpp20_adjustable_report_rate_set_report_rate(drv_data->dev, 1000/hz);
	if (rc)
		return rc;

	return RATBAG_SUCCESS;
}

static int
hidpp20drv_update_report_rate_8100(struct ratbag_profile *profile, int hz)
{
	struct ratbag_device *device = profile->device;
	struct hidpp20drv_data *drv_data = ratbag_get_drv_data(device);
	struct hidpp20_profile *h_profile;

	h_profile = &drv_data->profiles->profiles[profile->index];
	h_profile->report_rate = hz;

	return RATBAG_SUCCESS;
}

static int
hidpp20drv_update_report_rate(struct ratbag_profile *profile, int hz)
{
	struct ratbag_device *device = profile->device;
	struct hidpp20drv_data *drv_data = ratbag_get_drv_data(device);
	int rc;

	if (drv_data->capabilities & HIDPP_CAP_ONBOARD_PROFILES_8100)
		return hidpp20drv_update_report_rate_8100(profile, hz);

	if (drv_data->capabilities & HIDPP_CAP_ADJUSTIBLE_REPORT_RATE_8060) {
		rc = hidpp20drv_update_report_rate_8060(profile, hz);

		/* re-populate the profile with the correct value if we fail */
		if (rc)
			hidpp20drv_read_report_rate_8060(profile->device);

		return rc;
	}

	return -ENOTSUP;
}

static int
hidpp20drv_read_special_key_mouse(struct ratbag_device *device)
{
	struct hidpp20drv_data *drv_data = ratbag_get_drv_data(device);
	int rc;

	if (!(drv_data->capabilities & HIDPP_CAP_BUTTON_KEY_1b04))
		return 0;

	free(drv_data->controls);
	drv_data->controls = NULL;
	drv_data->num_controls = 0;
	rc = hidpp20_special_key_mouse_get_controls(drv_data->dev, &drv_data->controls);
	log_raw(device->ratbag, "num_control %d\n", rc);
	if (rc > 0) {
		drv_data->num_controls = rc;
		rc = 0;
	}

	return rc;
}

static int
hidpp20drv_read_kbd_reprogrammable_key(struct ratbag_device *device)
{
	struct hidpp20drv_data *drv_data = ratbag_get_drv_data(device);
	int rc;

	if (!(drv_data->capabilities & HIDPP_CAP_KBD_REPROGRAMMABLE_KEYS_1b00))
		return 0;

	free(drv_data->controls);
	drv_data->controls = NULL;
	drv_data->num_controls = 0;
	rc = hidpp20_kbd_reprogrammable_keys_get_controls(drv_data->dev, &drv_data->controls);
	if (rc > 0) {
		drv_data->num_controls = rc;
		rc = 0;
	}

	return rc;
}

static int
hidpp20drv_read_color_leds_8070(struct hidpp20drv_data *drv_data)
{
	int rc;

	free(drv_data->led_infos.color_leds_8070);
	drv_data->led_infos.color_leds_8070 = NULL;
	drv_data->num_leds = 0;

	rc = hidpp20_color_led_effects_get_zone_infos(drv_data->dev, &drv_data->led_infos.color_leds_8070);

	if (rc > 0) {
		drv_data->num_leds = rc;
		rc = 0;
	}

	return rc;
}

static int
hidpp20drv_read_color_leds_8071(struct hidpp20drv_data *drv_data)
{
	int rc;

	free(drv_data->led_infos.color_leds_8071);
	drv_data->led_infos.color_leds_8071 = NULL;
	drv_data->num_leds = 0;

	rc = hidpp20_rgb_effects_get_cluster_infos(drv_data->dev, &drv_data->led_infos.color_leds_8071);

	if (rc > 0) {
		drv_data->num_leds = rc;
		rc = 0;
	}

	return rc;
}

static int
hidpp20drv_read_color_leds(struct ratbag_device *device)
{
	struct hidpp20drv_data *drv_data = ratbag_get_drv_data(device);

	if(drv_data->capabilities & HIDPP_CAP_COLOR_LED_EFFECTS_8070)
		return hidpp20drv_read_color_leds_8070(drv_data);
	else if (drv_data->capabilities & HIDPP_CAP_RGB_EFFECTS_8071)
		return hidpp20drv_read_color_leds_8071(drv_data);

	return 0;
}

static int
hidpp20drv_read_leds(struct ratbag_device *device)
{
	struct hidpp20drv_data *drv_data = ratbag_get_drv_data(device);
	int rc;

	if (!(drv_data->capabilities & HIDPP_CAP_LED_SW_CONTROL_1300))
		return 0;

	free(drv_data->led_infos.leds);
	drv_data->led_infos.leds = NULL;

	rc = hidpp20_led_sw_control_read_leds(drv_data->dev, &drv_data->led_infos.leds);
	if (rc > 0) {
		drv_data->num_leds = rc;
		rc = 0;
	}

	return rc;
}

static void
hidpp20drv_read_profile_8100(struct ratbag_profile *profile)
{
	struct ratbag_device *device = profile->device;
	struct hidpp20drv_data *drv_data = ratbag_get_drv_data(device);
	struct ratbag_resolution *res;
	struct hidpp20_profile *p;
	int dpi_index = 0xff;

	profile->is_enabled = drv_data->profiles->profiles[profile->index].enabled;

	profile->is_active = false;
	if ((int)profile->index == hidpp20drv_current_profile(device))
		profile->is_active = true;

	if (profile->is_active)
		dpi_index = hidpp20_onboard_profiles_get_current_dpi_index(drv_data->dev);

	if (dpi_index < 0)
		dpi_index = 0xff;

	p = &drv_data->profiles->profiles[profile->index];

	ratbag_profile_for_each_resolution(profile, res) {
		struct hidpp20_sensor *sensor;

		/* We only look at the first sensor. Multiple
		 * sensors is too niche to care about right now */
		sensor = &drv_data->sensors[0];

		ratbag_resolution_set_resolution(res,
						 p->dpi[res->index],
						 p->dpi[res->index]);

		if (profile->is_active &&
		    res->index == (unsigned int)dpi_index)
			res->is_active = true;
		if (res->index == p->default_dpi) {
			res->is_default = true;
			if (!profile->is_active || dpi_index < 0 || dpi_index > 4)
				res->is_active = true;
		}

		ratbag_resolution_set_dpi_list_from_range(res,
							  sensor->dpi_min,
							  sensor->dpi_max);
	}

	ratbag_profile_set_report_rate_list(profile,
					    drv_data->report_rates,
					    drv_data->num_report_rates);
	ratbag_profile_set_report_rate(profile, p->report_rate);
}

static int
hidpp20drv_init_leds_8070_8071(struct ratbag_device *device)
{
	struct hidpp20drv_data *drv_data = ratbag_get_drv_data(device);
	struct ratbag *ratbag = device->ratbag;

	/* we only support 0x8071 via 0x8100 */
	if (!(drv_data->capabilities & HIDPP_CAP_ONBOARD_PROFILES_8100) &&
	    drv_data->capabilities & HIDPP_CAP_RGB_EFFECTS_8071) {
		log_debug(ratbag, "disabling 0x8071 (RGB Effects) feature because the device doesn't have 0x8100 (Onboard Memory Profiles)\n");
		drv_data->capabilities &= ~HIDPP_CAP_RGB_EFFECTS_8071;
	}

	if (drv_data->capabilities & HIDPP_CAP_COLOR_LED_EFFECTS_8070 ||
	    drv_data->capabilities & HIDPP_CAP_RGB_EFFECTS_8071) {
		/* we read the profile once to get the correct number of
		 * supported leds. */
		if (hidpp20drv_read_color_leds(device))
			return 0;

		device->num_leds = drv_data->num_leds;
	}

	return 0;
}

static int
hidpp20drv_init_profile_8100(struct ratbag_device *device)
{
	struct hidpp20drv_data *drv_data = ratbag_get_drv_data(device);
	struct ratbag *ratbag = device->ratbag;
	int rc;

	log_debug(ratbag, "initializing onboard profiles\n");
	rc = hidpp20_onboard_profiles_allocate(drv_data->dev, &drv_data->profiles);
	if (rc < 0)
		return rc;

	rc = hidpp20_onboard_profiles_initialize(drv_data->dev, drv_data->profiles);
	if (rc < 0)
		return rc;

	drv_data->num_profiles = drv_data->profiles->num_profiles;
	drv_data->num_buttons = drv_data->profiles->num_buttons;

	if (drv_data->capabilities & HIDPP_CAP_SWITCHABLE_RESOLUTION_2201)
		drv_data->num_resolutions = drv_data->profiles->num_modes;
	/* We ignore the profile's num_leds and require
	* HIDPP_PAGE_COLOR_LED_EFFECTS to succeed instead
	*/

	return 0;
}

static void
hidpp20drv_read_profile(struct ratbag_profile *profile)
{
	struct ratbag_device *device = profile->device;
	struct hidpp20drv_data *drv_data = ratbag_get_drv_data(device);
	struct ratbag_led *led;
	struct ratbag_button *button;

	if (drv_data->capabilities & HIDPP_CAP_ONBOARD_PROFILES_8100) {
		hidpp20drv_read_profile_8100(profile);
		ratbag_profile_set_cap(profile, RATBAG_PROFILE_CAP_DISABLE);
	} else {
		hidpp20drv_read_resolution_dpi(profile);
		hidpp20drv_read_special_key_mouse(device);

		profile->is_active = (profile->index == 0);
	}

	ratbag_profile_for_each_led(profile, led)
		hidpp20drv_read_led(led);

	ratbag_profile_for_each_button(profile, button)
		hidpp20drv_read_button(button);
}

static int
hidpp20drv_init_feature(struct ratbag_device *device, uint16_t feature)
{
	struct hidpp20drv_data *drv_data = ratbag_get_drv_data(device);
	struct ratbag *ratbag = device->ratbag;
	int rc;
	uint8_t feature_index, feature_type, feature_version;

	rc = hidpp_root_get_feature(drv_data->dev,
				    feature,
				    &feature_index,
				    &feature_type,
				    &feature_version);
	if (rc < 0)
		return rc;

	/* check if it is a hidden feature */
	if (feature_type & HIDPP_HIDDEN_FEATURE)
		return 0;

	switch (feature) {
	case HIDPP_PAGE_ROOT:
	case HIDPP_PAGE_FEATURE_SET:
		/* these features are mandatory and already handled */
		break;
	case HIDPP_PAGE_MOUSE_POINTER_BASIC: {
		drv_data->capabilities |= HIDPP_CAP_RESOLUTION_2200;
		break;
	}
	case HIDPP_PAGE_ADJUSTABLE_DPI: {
		log_debug(ratbag, "device has adjustable dpi\n");
		/* we read the profile once to get the correct number of
		 * supported resolutions. */
		rc = hidpp20drv_read_resolution_dpi_2201(device);
		if (rc < 0)
			return 0; /* this is not a hard failure */
		drv_data->capabilities |= HIDPP_CAP_SWITCHABLE_RESOLUTION_2201;
		break;
	}
	case HIDPP_PAGE_SPECIAL_KEYS_BUTTONS: {
		log_debug(ratbag, "device has programmable keys/buttons\n");
		drv_data->capabilities |= HIDPP_CAP_BUTTON_KEY_1b04;
		/* we read the profile once to get the correct number of
		 * supported buttons. */
		if (!hidpp20drv_read_special_key_mouse(device))
			drv_data->num_buttons = drv_data->num_controls;
		break;
	}
	case HIDPP_PAGE_BATTERY_LEVEL_STATUS: {
		uint16_t level, next_level;
		enum hidpp20_battery_status status;

		rc = hidpp20_batterylevel_get_battery_level(drv_data->dev, &level, &next_level);
		if (rc < 0)
			return rc;
		status = rc;

		log_debug(ratbag, "device battery level is %d%% (next %d%%), status %d \n",
			  level, next_level, status);

		drv_data->capabilities |= HIDPP_CAP_BATTERY_LEVEL_1000;
		break;
	}
	case HIDPP_PAGE_BATTERY_VOLTAGE: {
		uint16_t voltage;
		enum hidpp20_battery_voltage_status status;

		rc = hidpp20_batteryvoltage_get_battery_voltage(drv_data->dev, &voltage);
		if (rc < 0)
			return rc;

		status = rc;

		log_debug(ratbag, "device battery voltage is %dmv, status %02x \n",
			  voltage, status);

		drv_data->capabilities |= HIDPP_CAP_BATTERY_VOLTAGE_1001;
		break;
	}
	case HIDPP_PAGE_KBD_REPROGRAMMABLE_KEYS: {
		log_debug(ratbag, "device has programmable keys/buttons\n");
		drv_data->capabilities |= HIDPP_CAP_KBD_REPROGRAMMABLE_KEYS_1b00;

		/* we read the profile once to get the correct number of
		 * supported buttons. */
		if (!hidpp20drv_read_kbd_reprogrammable_key(device))
			drv_data->num_buttons = drv_data->num_controls;
		break;
	}
	case HIDPP_PAGE_ADJUSTABLE_REPORT_RATE: {
		log_debug(ratbag, "device has adjustable report rate\n");

		/* we read the profile once to get the correct number of
		 * supported report rates. */
		rc = hidpp20drv_read_report_rate_8060(device);
		if (rc < 0)
			return 0; /* this is not a hard failure */

		drv_data->capabilities |= HIDPP_CAP_ADJUSTIBLE_REPORT_RATE_8060;
		break;
	}
	case HIDPP_PAGE_COLOR_LED_EFFECTS: {
		/* The 8070 feauture implemented in the G602 doesn't follow the spec,
		 * so we ignore it */
		if (ratbag_device_data_hidpp20_get_quirk(device->data) == HIDPP20_QUIRK_G602)
			break;

		log_debug(ratbag, "device has color effects\n");
		drv_data->capabilities |= HIDPP_CAP_COLOR_LED_EFFECTS_8070;
		break;
	}
	case HIDPP_PAGE_RGB_EFFECTS: {
		log_debug(ratbag, "device has color effects\n");
		drv_data->capabilities |= HIDPP_CAP_RGB_EFFECTS_8071;
		break;
	}
	case HIDPP_PAGE_LED_SW_CONTROL: {
		log_debug(ratbag, "device has non-rgb leds\n");
		drv_data->capabilities |= HIDPP_CAP_LED_SW_CONTROL_1300;

		if (drv_data->capabilities & HIDPP_PAGE_COLOR_LED_EFFECTS)
			return 0;

		if (hidpp20drv_read_leds(device))
			return 0;

		break;
	}
	case HIDPP_PAGE_ONBOARD_PROFILES: {
		log_debug(ratbag, "device has onboard profiles\n");
		drv_data->capabilities |= HIDPP_CAP_ONBOARD_PROFILES_8100;
		break;
	}
	case HIDPP_PAGE_MOUSE_BUTTON_SPY: {
		log_debug(ratbag, "device has configurable mouse button spy\n");
		break;
	}
	default:
		log_raw(device->ratbag, "unknown feature 0x%04x\n", feature);
	}
	return 0;
}

static int
hidpp20drv_commit(struct ratbag_device *device)
{
	struct hidpp20drv_data *drv_data = ratbag_get_drv_data(device);
	struct ratbag_profile *profile;
	struct ratbag_button *button;
	struct ratbag_led *led;
	struct ratbag_resolution *resolution;
	int rc;

	list_for_each(profile, &device->profiles, link) {
		if (!profile->dirty)
			continue;

		if (profile->rate_dirty) {
			rc = hidpp20drv_update_report_rate(profile, profile->hz);
			if (rc) {
				log_error(device->ratbag, "hidpp20: failed to update report rate (%d)\n", rc);
				return RATBAG_ERROR_DEVICE;
			}
		}

		ratbag_profile_for_each_resolution(profile, resolution) {
			rc = hidpp20drv_update_resolution_dpi(resolution,
							      resolution->dpi_x,
							      resolution->dpi_y);
			if (rc) {
				log_error(device->ratbag, "hidpp20: failed to update resolution (%d)\n", rc);
				return RATBAG_ERROR_DEVICE;
			}
		}

		list_for_each(button, &profile->buttons, link) {
			if (!button->dirty)
				continue;

			rc = hidpp20drv_update_button(button);
			if (rc) {
				log_error(device->ratbag, "hidpp20: failed to update button (%d)\n", rc);
				return RATBAG_ERROR_DEVICE;
			}
		}

		list_for_each(led, &profile->leds, link) {
			if (!led->dirty)
				continue;

			rc = hidpp20drv_update_led(led);
			if (rc) {
				log_error(device->ratbag, "hidpp20: failed to update led (%d)\n", rc);
				return RATBAG_ERROR_DEVICE;
			}
		}
	}

	if (drv_data->capabilities & HIDPP_CAP_ONBOARD_PROFILES_8100) {
		list_for_each(profile, &device->profiles, link)
			drv_data->profiles->profiles[profile->index].enabled = profile->is_enabled;

		rc = hidpp20_onboard_profiles_commit(drv_data->dev,
						     drv_data->profiles);
		if (rc) {
			log_error(device->ratbag, "hidpp20: failed to commit profile (%d)\n", rc);
			return RATBAG_ERROR_DEVICE;
		}

		list_for_each(profile, &device->profiles, link) {
			if (profile->is_active) {
				ratbag_profile_for_each_resolution(profile, resolution) {
					if (resolution->is_active)
						hidpp20_onboard_profiles_set_current_dpi_index(drv_data->dev,
											       resolution->index);
				}
			}
		}
	}

	return RATBAG_SUCCESS;
}

static int
hidpp20drv_20_probe(struct ratbag_device *device)
{
	struct hidpp20drv_data *drv_data = ratbag_get_drv_data(device);
	struct hidpp20_device *dev = drv_data->dev;
	struct hidpp20_feature *feature_list = dev->feature_list;
	unsigned int i;
	int rc;

	log_raw(device->ratbag,
		"'%s' has %d features\n",
		ratbag_device_get_name(device),
		dev->feature_count);

	for (i = 0; i < dev->feature_count; i++) {
		log_raw(device->ratbag, "Init feature %s (0x%04x) \n",
			hidpp20_feature_get_name(feature_list[i].feature),
			feature_list[i].feature);
		rc = hidpp20drv_init_feature(device, feature_list[i].feature);
		if (rc < 0)
			return rc;
	}

	/* initializations that depend on other features */
	if (drv_data->capabilities & HIDPP_CAP_COLOR_LED_EFFECTS_8070 ||
	    drv_data->capabilities & HIDPP_CAP_RGB_EFFECTS_8071) {
		rc = hidpp20drv_init_leds_8070_8071(device);
		if (rc < 0)
			return rc;
	}

	if (drv_data->capabilities & HIDPP_CAP_ONBOARD_PROFILES_8100) {
		rc = hidpp20drv_init_profile_8100(device);
		if (rc < 0)
			return rc;
	}

	return 0;
}

static int
hidpp20drv_test_hidraw(struct ratbag_device *device)
{
	return ratbag_hidraw_has_report(device, REPORT_ID_LONG);
}

static void
hidpp20_log(void *userdata, enum hidpp_log_priority priority, const char *format, va_list args)
{
	struct ratbag_device *device = userdata;

	log_msg_va(device->ratbag, (enum ratbag_log_priority)priority, format, args);
}

static void
hidpp20drv_remove(struct ratbag_device *device)
{
	struct hidpp20drv_data *drv_data;

	if (!device)
		return;

	drv_data = ratbag_get_drv_data(device);

	ratbag_close_hidraw(device);

	if (drv_data->profiles)
		hidpp20_onboard_profiles_destroy(drv_data->profiles);
	free(drv_data->led_infos.color_leds_8070);
	free(drv_data->controls);
	free(drv_data->sensors);
	free(drv_data->leds);
	if (drv_data->dev)
		hidpp20_device_destroy(drv_data->dev);
	free(drv_data);
}

static void
hidpp20drv_init_device(struct ratbag_device *device,
		       struct hidpp20drv_data *drv_data)
{
	struct ratbag_profile *profile;
	bool active_profile = false;
	int num;

	num = ratbag_device_data_hidpp20_get_led_count(device->data);
	if (num >= 0)
		drv_data->num_leds = num;

	num = ratbag_device_data_hidpp20_get_button_count(device->data);
	if (num >= 0)
		drv_data->num_buttons = num;

	num = ratbag_device_data_hidpp20_get_report_rate(device->data);
	if (num >= 0)
		drv_data->report_rates[0] = num;

	ratbag_device_init_profiles(device,
				    drv_data->num_profiles,
				    drv_data->num_resolutions,
				    drv_data->num_buttons,
				    drv_data->num_leds);

	ratbag_device_for_each_profile(device, profile)
		hidpp20drv_read_profile(profile);

	if (drv_data->capabilities & HIDPP_CAP_ONBOARD_PROFILES_8100) {
		/* Fallback to the first profile if no profile is active */
		list_for_each(profile, &device->profiles, link)
			if (profile->is_active)
				active_profile = true;

		if (!active_profile && device->num_profiles >= 1) {
			profile = ratbag_device_get_profile(device, 0);
			profile->is_active = true;
		}
	}
}

static int
hidpp20drv_probe(struct ratbag_device *device)
{
	int rc;
	struct hidpp20drv_data *drv_data;
	struct hidpp_device base;
	struct hidpp20_device *dev;
	int device_idx = HIDPP_RECEIVER_IDX;

	rc = ratbag_find_hidraw(device, hidpp20drv_test_hidraw);
	if (rc)
		return rc;

	drv_data = zalloc(sizeof(*drv_data));
	ratbag_set_drv_data(device, drv_data);
	hidpp_device_init(&base, device->hidraw[0].fd);
	hidpp_device_set_log_handler(&base, hidpp20_log, HIDPP_LOG_PRIORITY_RAW, device);

	device_idx = ratbag_device_data_hidpp20_get_index(device->data);
	if (device_idx == -1)
		device_idx = HIDPP_RECEIVER_IDX;

	/* In the general case, we can treat all devices as wired devices
	 * here. If we talk to the correct hidraw device the kernel adjusts
	 * the device index for us, so even for unifying receiver devices
	 * we can just use 0xff as device index.
	 *
	 * If there is a special need like for G900, we can add this in the
	 * device data file.
	 */
	dev = hidpp20_device_new(&base, device_idx, (struct hidpp_hid_report*) device->hidraw[0].reports, device->hidraw[0].num_reports);
	if (!dev) {
		rc = -ENODEV;
		goto err;
	}

	dev->quirk = ratbag_device_data_hidpp20_get_quirk(device->data);

	drv_data->dev = dev;

	log_debug(device->ratbag, "'%s' is using protocol v%d.%d\n", ratbag_device_get_name(device), dev->proto_major, dev->proto_minor);

	if(dev->quirk != HIDPP20_QUIRK_NONE)
		log_debug(device->ratbag, "'%s' is quirked (%s)\n", ratbag_device_get_name(device), hidpp20_get_quirk_string(dev->quirk));

	/* add some defaults that will be overwritten by the device */
	drv_data->num_profiles = 1;
	drv_data->num_resolutions = 0;
	drv_data->num_buttons = 8;
	drv_data->num_leds = 0;

	rc = hidpp20drv_20_probe(device);
	if (rc)
		goto err;

	hidpp20drv_init_device(device, drv_data);

	return rc;
err:
	hidpp20drv_remove(device);
	return rc;
}

struct ratbag_driver hidpp20_driver = {
	.name = "Logitech HID++2.0",
	.id = "hidpp20",
	.probe = hidpp20drv_probe,
	.remove = hidpp20drv_remove,
	.commit = hidpp20drv_commit,
	.set_active_profile = hidpp20drv_set_current_profile,
};


text:
<#-- Settings you need -->
<#setting date_format="dd-MM-yyyy">
<#-- The string that comes from somewhere: -->
<#assign createdOn = .now>
<#--
  1. Tell FreeMarker to convert string to real date-time value
  2. Convert date-time value to date-only value
  3. Let FreeMarker format it according the date_format setting
-->
> ### Schedule status : ${createdOn?date}
>
> -	There are a total of 34 views
> - 23 views will be delivered by 31 Aug
>   - This also includes the extra scope which will be absorbed in to the already aggressive schedule.
>       - static lookup widget and reworked static data views
> - 11 views marked ![](styles/images/label-red.png) cannot be completed at this point.
>   - These views will be developed as far as possible with placeholder code and finished based on customer compromise or changes being made to the core AMS product.
>   - We can't at the moment estimate the rework for those views marked ![](styles/images/label-red.png) thoroughly, because there is no solution in place yet to get the data.
>   - Both customer and product agreements must be made before an estimate can be provided for the additional work required


text:
package com.stockingd.cinedex.app;

import android.support.v4.app.Fragment;

import com.github.dmstocking.optional.java.util.Optional;
import com.stockingd.cinedex.CinedexApplication;
import com.stockingd.cinedex.CinedexComponent;

import javax.inject.Inject;
import javax.inject.Named;

import rx.subscriptions.CompositeSubscription;

public class BaseFragment2 extends Fragment {

    protected Optional<CinedexApplication> application() {
        return Optional.ofNullable(getActivity()).map(a -> {
                return (CinedexApplication)a.getApplicationContext();
        });
    }

    protected Optional<CinedexComponent> component() {
        return application().map(CinedexApplication::component);
    }
}


text:
package org.apache.cloudstack.framework.transport;

import java.util.Random;

public class TransportAddress {
	public final static String LOCAL_SERVICE_NODE = "";
	public final static int LOCAL_SERVICE_CONNECTION = 0;

	private String _nodeId = LOCAL_SERVICE_NODE;
	private int _connectionId = LOCAL_SERVICE_CONNECTION;
	private String _endpointId;
	private int _magic;

	public TransportAddress(String nodeId, int connectionId, String endpointId) {
		assert(nodeId != null);
		assert(endpointId != null);
		assert(nodeId.indexOf(".") < 0);
		assert(endpointId.indexOf(".") < 0);

		_nodeId = nodeId;
		_connectionId = connectionId;
		_endpointId = endpointId;
		_magic = new Random().nextInt();
	}

	public TransportAddress(String nodeId, int connectionId, String endpointId, int magic) {
		assert(nodeId != null);
		assert(endpointId != null);
		assert(nodeId.indexOf(".") < 0);
		assert(endpointId.indexOf(".") < 0);

		_nodeId = nodeId;
		_connectionId = connectionId;
		_endpointId = endpointId;
		_magic = magic;
	}

	public String getNodeId() {
		return _nodeId;
	}

	public TransportAddress setNodeId(String nodeId) {
		_nodeId = nodeId;
		return this;
	}

	public int getConnectionId() {
		return _connectionId;
	}

	public void setConnectionId(int connectionId) {
		_connectionId = connectionId;
	}

	public String getEndpointId() {
		return _endpointId;
	}

	public TransportAddress setEndpointId(String endpointId) {
		_endpointId = endpointId;
		return this;
	}

	public static TransportAddress fromAddressString(String addressString) {
		if(addressString == null || addressString.isEmpty())
			return null;

		String tokens[] = addressString.split("\\.");
		if(tokens.length != 4)
			return null;

		return new TransportAddress(tokens[0], Integer.parseInt(tokens[1]), tokens[2], Integer.parseInt(tokens[3]));
	}

	public static TransportAddress getLocalPredefinedTransportAddress(String predefinedIdentifier) {
		return new TransportAddress(LOCAL_SERVICE_NODE, LOCAL_SERVICE_CONNECTION, predefinedIdentifier, 0);
	}

	@Override
	public int hashCode() {
		int hashCode = _magic;
		hashCode = (hashCode << 3) ^ _nodeId.hashCode();
		hashCode = (hashCode << 3) ^ _connectionId;
		hashCode = (hashCode << 3) ^ _endpointId.hashCode();

		return hashCode;
	}

	@Override
	public boolean equals(Object other) {
		if(other == null)
			return false;

		if(!(other instanceof TransportAddress))
			return false;

		if(this == other)
			return true;

		return _nodeId.equals(((TransportAddress)other)._nodeId) &&
			_connectionId == (((TransportAddress)other)._connectionId) &&
			_endpointId.equals(((TransportAddress)other)._endpointId) &&
			_magic == ((TransportAddress)other)._magic;
	}

	@Override
	public String toString() {
		StringBuffer sb = new StringBuffer();
		if(_nodeId != null)
			sb.append(_nodeId);
		sb.append(".");
		sb.append(_connectionId);
		sb.append(".");
		sb.append(_endpointId);
		sb.append(".");
		sb.append(_magic);

		return sb.toString();
	}
}