text:
package siarhei.luskanau.gps.tracker.free.ui.settings;

import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.graphics.drawable.VectorDrawableCompat;
import android.support.v7.preference.ListPreference;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceFragmentCompat;
import android.support.v7.preference.SwitchPreferenceCompat;

import siarhei.luskanau.gps.tracker.free.R;
import siarhei.luskanau.gps.tracker.free.settings.AppSettings;

public class InternetSettingsFragment extends PreferenceFragmentCompat {

    @Override
    public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
        addPreferencesFromResource(R.xml.preference_internet);

        onInternetTypePreferenceCreate();
        onSendToServerIntervalPreferenceCreate();
        onBatteryLowPreferenceCreate();
        onBatteryOkPreferenceCreate();
        onChargerDisconnectedPreferenceCreate();
        onChargerConnectedPreferenceCreate();
    }

    private void onInternetTypePreferenceCreate() {
        ListPreference listPreference = (ListPreference) findPreference(getString(R.string.preference_key_internet_type));
        listPreference.setIcon(getIcon(R.drawable.ic_public_24dp));
        CharSequence[] entries = listPreference.getEntries();
        AppSettings.State state = AppSettings.getAppSettingsEntity(getContext());
        switch (state.internetSettingsEntity.internetType) {
            default:
            case ANY_TYPE: {
                listPreference.setValueIndex(0);
                listPreference.setSummary(entries[0]);
                break;
            }
            case WIFI_TYPE: {
                listPreference.setValueIndex(1);
                listPreference.setSummary(entries[1]);
                break;
            }
            case OFFLINE_TYPE: {
                listPreference.setValueIndex(2);
                listPreference.setSummary(entries[2]);
                break;
            }
        }
        listPreference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
            @Override
            public boolean onPreferenceChange(Preference preference, Object newValue) {
                ListPreference listPreference = (ListPreference) findPreference(getString(R.string.preference_key_internet_type));
                listPreference.setSummary(newValue.toString());
                AppSettings.State state = AppSettings.getAppSettingsEntity(getContext());
                switch (listPreference.findIndexOfValue(newValue.toString())) {
                    case 0: {
                        state.internetSettingsEntity.internetType = AppSettings.InternetType.ANY_TYPE;
                        break;
                    }
                    case 1: {
                        state.internetSettingsEntity.internetType = AppSettings.InternetType.WIFI_TYPE;
                        break;
                    }
                    case 2: {
                        state.internetSettingsEntity.internetType = AppSettings.InternetType.OFFLINE_TYPE;
                        break;
                    }
                }
                AppSettings.setAppSettingsEntity(getContext(), state);
                return true;
            }
        });
    }

    private void onSendToServerIntervalPreferenceCreate() {
        ListPreference listPreference = (ListPreference) findPreference(getString(R.string.preference_key_send_to_server_interval));
        listPreference.setIcon(getIcon(R.drawable.ic_timer_24dp));
        CharSequence[] entries = listPreference.getEntries();
        AppSettings.State state = AppSettings.getAppSettingsEntity(getContext());
        switch (state.internetSettingsEntity.sendToServerInterval) {
            default:
            case AppSettings.SendToServerInterval.IMMEDIATELY: {
                listPreference.setValueIndex(0);
                listPreference.setSummary(entries[0]);
                break;
            }
            case AppSettings.SendToServerInterval.MINUTES_1: {
                listPreference.setValueIndex(1);
                listPreference.setSummary(entries[1]);
                break;
            }
            case AppSettings.SendToServerInterval.MINUTES_10: {
                listPreference.setValueIndex(2);
                listPreference.setSummary(entries[2]);
                break;
            }
            case AppSettings.SendToServerInterval.MINUTES_60: {
                listPreference.setValueIndex(3);
                listPreference.setSummary(entries[3]);
                break;
            }
            case AppSettings.SendToServerInterval.MANUAL: {
                listPreference.setValueIndex(4);
                listPreference.setSummary(entries[4]);
                break;
            }
        }
        listPreference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
            @Override
            public boolean onPreferenceChange(Preference preference, Object newValue) {
                ListPreference listPreference = (ListPreference) findPreference(getString(R.string.preference_key_send_to_server_interval));
                listPreference.setSummary(newValue.toString());
                AppSettings.State state = AppSettings.getAppSettingsEntity(getContext());
                switch (listPreference.findIndexOfValue(newValue.toString())) {
                    case 0: {
                        state.internetSettingsEntity.sendToServerInterval = AppSettings.SendToServerInterval.IMMEDIATELY;
                        break;
                    }
                    case 1: {
                        state.internetSettingsEntity.sendToServerInterval = AppSettings.SendToServerInterval.MINUTES_1;
                        break;
                    }
                    case 2: {
                        state.internetSettingsEntity.sendToServerInterval = AppSettings.SendToServerInterval.MINUTES_10;
                        break;
                    }
                    case 3: {
                        state.internetSettingsEntity.sendToServerInterval = AppSettings.SendToServerInterval.MINUTES_60;
                        break;
                    }
                    case 4: {
                        state.internetSettingsEntity.sendToServerInterval = AppSettings.SendToServerInterval.MANUAL;
                        break;
                    }
                }
                AppSettings.setAppSettingsEntity(getContext(), state);
                return true;
            }
        });
    }

    private void onBatteryLowPreferenceCreate() {
        SwitchPreferenceCompat switchPreferenceCompat = (SwitchPreferenceCompat) findPreference(getString(R.string.preference_key_stop_if_battery_low));
        switchPreferenceCompat.setIcon(getIcon(R.drawable.ic_battery_20_24dp));
        AppSettings.State state = AppSettings.getAppSettingsEntity(getContext());
        switchPreferenceCompat.setChecked(state.batterySettings.stopIfBatteryLow);
        switchPreferenceCompat.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
            @Override
            public boolean onPreferenceChange(Preference preference, Object newValue) {
                AppSettings.State state = AppSettings.getAppSettingsEntity(getContext());
                state.batterySettings.stopIfBatteryLow = Boolean.parseBoolean(newValue.toString());
                AppSettings.setAppSettingsEntity(getContext(), state);
                return true;
            }
        });
    }

    private void onBatteryOkPreferenceCreate() {
        SwitchPreferenceCompat switchPreferenceCompat = (SwitchPreferenceCompat) findPreference(getString(R.string.preference_key_start_if_battery_ok));
        switchPreferenceCompat.setIcon(getIcon(R.drawable.ic_battery_90_24dp));
        AppSettings.State state = AppSettings.getAppSettingsEntity(getContext());
        switchPreferenceCompat.setChecked(state.batterySettings.startIfBatteryOk);
        switchPreferenceCompat.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
            @Override
            public boolean onPreferenceChange(Preference preference, Object newValue) {
                AppSettings.State state = AppSettings.getAppSettingsEntity(getContext());
                state.batterySettings.startIfBatteryOk = Boolean.parseBoolean(newValue.toString());
                AppSettings.setAppSettingsEntity(getContext(), state);
                return true;
            }
        });
    }

    private void onChargerDisconnectedPreferenceCreate() {
        SwitchPreferenceCompat switchPreferenceCompat = (SwitchPreferenceCompat) findPreference(getString(R.string.preference_key_stop_if_charger_disconnected));
        switchPreferenceCompat.setIcon(getIcon(R.drawable.ic_battery_charging_20_24dp));
        AppSettings.State state = AppSettings.getAppSettingsEntity(getContext());
        switchPreferenceCompat.setChecked(state.batterySettings.stopIfChargerDisconnected);
        switchPreferenceCompat.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
            @Override
            public boolean onPreferenceChange(Preference preference, Object newValue) {
                AppSettings.State state = AppSettings.getAppSettingsEntity(getContext());
                state.batterySettings.stopIfChargerDisconnected = Boolean.parseBoolean(newValue.toString());
                AppSettings.setAppSettingsEntity(getContext(), state);
                return true;
            }
        });
    }

    private void onChargerConnectedPreferenceCreate() {
        SwitchPreferenceCompat switchPreferenceCompat = (SwitchPreferenceCompat) findPreference(getString(R.string.preference_key_start_if_charger_connected));
        switchPreferenceCompat.setIcon(getIcon(R.drawable.ic_battery_charging_90_24dp));
        AppSettings.State state = AppSettings.getAppSettingsEntity(getContext());
        switchPreferenceCompat.setChecked(state.batterySettings.startIfChargerConnected);
        switchPreferenceCompat.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
            @Override
            public boolean onPreferenceChange(Preference preference, Object newValue) {
                AppSettings.State state = AppSettings.getAppSettingsEntity(getContext());
                state.batterySettings.startIfChargerConnected = Boolean.parseBoolean(newValue.toString());
                AppSettings.setAppSettingsEntity(getContext(), state);
                return true;
            }
        });
    }

    private Drawable getIcon(int resId) {
        return VectorDrawableCompat.create(getResources(), resId, null);
    }

}


text:
NS_ROOT

// GCC prior the 5.0 does not support std::atomic_exchange(std::shared_ptr<T>*, std::shared_ptr<T>)
#if !defined(__GNUC__) || (__GNUC__ >= 5)
template<typename T>
class atomic_shared_ptr_helper {
  #if defined(IRESEARCH_VALGRIND) // suppress valgrind false-positives related to std::atomic_*
   public:
    // for compatibility 'std::mutex' is not moveable
    atomic_shared_ptr_helper() = default;
    atomic_shared_ptr_helper(atomic_shared_ptr_helper&&) NOEXCEPT { }
    atomic_shared_ptr_helper& operator=(atomic_shared_ptr_helper&&) NOEXCEPT { return *this; }

    std::shared_ptr<T> atomic_exchange(std::shared_ptr<T>* p, std::shared_ptr<T> r) const NOEXCEPT {
      SCOPED_LOCK(mutex_);
      return std::atomic_exchange(p, r);
    }

    void atomic_store(std::shared_ptr<T>* p, std::shared_ptr<T> r) const NOEXCEPT {
      SCOPED_LOCK(mutex_);
      std::atomic_store(p, r);
    }

    std::shared_ptr<T> atomic_load(const std::shared_ptr<T>* p) const NOEXCEPT {
      SCOPED_LOCK(mutex_);
      return std::atomic_load(p);
    }

   private:
    mutable std::mutex mutex_;
  #else
   public:
    static std::shared_ptr<T> atomic_exchange(std::shared_ptr<T>* p, std::shared_ptr<T> r) NOEXCEPT {
      return std::atomic_exchange(p, r);
    }

    static void atomic_store(std::shared_ptr<T>* p, std::shared_ptr<T> r) NOEXCEPT {
      std::atomic_store(p, r);
    }

    static std::shared_ptr<T> atomic_load(const std::shared_ptr<T>* p) NOEXCEPT {
      return std::atomic_load(p);
    }
  #endif // defined(IRESEARCH_VALGRIND)
}; // atomic_shared_ptr_helper
#else
template<typename T>
class atomic_shared_ptr_helper {
 public:
  // for compatibility 'std::mutex' is not moveable
  atomic_shared_ptr_helper() = default;
  atomic_shared_ptr_helper(atomic_shared_ptr_helper&&) NOEXCEPT { }
  atomic_shared_ptr_helper& operator=(atomic_shared_ptr_helper&&) NOEXCEPT { return *this; }

  std::shared_ptr<T> atomic_exchange(std::shared_ptr<T>* p, std::shared_ptr<T> r) const NOEXCEPT {
    SCOPED_LOCK(mutex_);
    p->swap(r);
    return r;
  }

  void atomic_store(std::shared_ptr<T>* p, std::shared_ptr<T> r) const NOEXCEPT {
    SCOPED_LOCK(mutex_);
    *p = r;
  }

  std::shared_ptr<T> atomic_load(const std::shared_ptr<T>* p) const NOEXCEPT {
    SCOPED_LOCK(mutex_);
    return *p;
  }

 private:
  mutable std::mutex mutex_;
}; // atomic_shared_ptr_helper
#endif

//////////////////////////////////////////////////////////////////////////////
/// @class concurrent_stack
/// @brief lock-free single linked list
//////////////////////////////////////////////////////////////////////////////
template<typename T>
class concurrent_stack : private util::noncopyable {
 public:
  typedef T element_type;

  struct node_type {
    element_type value{};
    node_type* next{};
  };

  explicit concurrent_stack(node_type* head = nullptr) NOEXCEPT
    : head_(head) {
  }

  concurrent_stack(concurrent_stack&& rhs) NOEXCEPT
    : head_(nullptr) {
    if (this != &rhs) {
      auto rhshead = rhs.head_.load();
      while (!rhs.head_.compare_exchange_weak(rhshead, head_));
      head_.store(rhshead);
    }
  }

  concurrent_stack& operator=(concurrent_stack&& rhs) NOEXCEPT {
    if (this != &rhs) {
      auto rhshead = rhs.head_.load();
      const concurrent_node empty;
      while (!rhs.head_.compare_exchange_weak(rhshead, empty));
      head_.store(rhshead);
    }
    return *this;
  }

  bool empty() const NOEXCEPT {
    VALGRIND_ONLY(SCOPED_LOCK(mutex_);) // suppress valgrind false-positives related to std::atomic_*
    return nullptr == head_.load().node;
  }

  node_type* pop() NOEXCEPT {
    VALGRIND_ONLY(SCOPED_LOCK(mutex_);) // suppress valgrind false-positives related to std::atomic_*
    concurrent_node head = head_.load();
    concurrent_node new_head;

    do {
      if (!head.node) {
        return nullptr;
      }

      new_head.node = head.node->next;
      new_head.version = head.version + 1;
    } while (!head_.compare_exchange_weak(head, new_head));

    return head.node;
  }

  void push(node_type& new_node) NOEXCEPT {
    VALGRIND_ONLY(SCOPED_LOCK(mutex_);) // suppress valgrind false-positives related to std::atomic_*
    concurrent_node head = head_.load();
    concurrent_node new_head;

    do {
      new_node.next = head.node;

      new_head.node = &new_node;
      new_head.version = head.version + 1;
    } while (!head_.compare_exchange_weak(head, new_head));
  }

 private:
  // CMPXCHG16B requires that the destination
  // (memory) operand be 16-byte aligned
  struct ALIGNAS(IRESEARCH_CMPXCHG16B_ALIGNMENT) concurrent_node {
    concurrent_node(node_type* node = nullptr) NOEXCEPT
      : version(0), node(node) {
    }

    uintptr_t version; // avoid aba problem
    node_type* node;
  }; // concurrent_node

  static_assert(
    IRESEARCH_CMPXCHG16B_ALIGNMENT == ALIGNOF(concurrent_node),
    "invalid alignment"
  );

  std::atomic<concurrent_node> head_;
  VALGRIND_ONLY(mutable std::mutex mutex_;)
}; // concurrent_stack

// -----------------------------------------------------------------------------
// --SECTION--                                                      bounded pool
// -----------------------------------------------------------------------------

//////////////////////////////////////////////////////////////////////////////
/// @brief a fixed size pool of objects
///        if the pool is empty then a new object is created via make(...)
///        if an object is available in a pool then in is returned but tracked
///        by the pool
///        when the object is released it is placed back into the pool
/// @note object 'ptr' that evaluate to false after make(...) are not considered
///       part of the pool
//////////////////////////////////////////////////////////////////////////////
template<typename T>
class bounded_object_pool {
 private:
  struct slot_t : util::noncopyable {
    bounded_object_pool* owner;
    typename T::ptr ptr;
  }; // slot_t

  typedef concurrent_stack<slot_t> stack;
  typedef typename stack::node_type node_type;

 public:
  typedef typename T::ptr::element_type element_type;

  /////////////////////////////////////////////////////////////////////////////
  /// @class ptr
  /// @brief represents a control object of bounded_object_pool with
  ///        semantic similar to smart pointers
  /////////////////////////////////////////////////////////////////////////////
  class ptr : util::noncopyable {
   private:
    static node_type EMPTY_SLOT;

   public:
    ptr() NOEXCEPT
      : slot_(&EMPTY_SLOT) {
    }

    explicit ptr(node_type& slot) NOEXCEPT
      : slot_(&slot) {
    }

    ptr(ptr&& rhs) NOEXCEPT
      : slot_(rhs.slot_) {
      rhs.slot_ = &EMPTY_SLOT; // take ownership
    }

    ptr& operator=(ptr&& rhs) NOEXCEPT {
      if (this != &rhs) {
        slot_ = rhs.slot_;
        rhs.slot_ = &EMPTY_SLOT; // take ownership
      }
      return *this;
    }

    ~ptr() NOEXCEPT {
      reset();
    }

    FORCE_INLINE void reset() NOEXCEPT {
      reset_impl(slot_);
    }

    std::shared_ptr<element_type> release() {
      auto* raw = get();
      auto* slot = slot_;
      slot_ = &EMPTY_SLOT; // moved

      // in case if exception occurs
      // destructor will be called
      return std::shared_ptr<element_type>(
        raw,
        [slot] (element_type*) mutable NOEXCEPT {
          reset_impl(slot);
      });
    }

    operator bool() const NOEXCEPT { return &EMPTY_SLOT != slot_; }
    element_type& operator*() const NOEXCEPT { return *slot_->value.ptr; }
    element_type* operator->() const NOEXCEPT { return get(); }
    element_type* get() const NOEXCEPT {
      return slot_->value.ptr.get();
    }

   private:
    static void reset_impl(node_type*& slot) NOEXCEPT {
      if (slot == &EMPTY_SLOT) {
        // nothing to do
        return;
      }

      assert(slot->value.owner);
      slot->value.owner->unlock(*slot);
      slot = &EMPTY_SLOT; // release ownership
    }

    node_type* slot_;
  }; // ptr

  explicit bounded_object_pool(size_t size)
    : pool_(std::max(size_t(1), size)) {
    // initialize pool
    for (auto& node : pool_) {
      auto& slot = node.value;
      slot.owner = this;

      free_list_.push(node);
    }
  }

  template<typename... Args>
  ptr emplace(Args&&... args) {
    node_type* head = nullptr;

    while (!(head = free_list_.pop())) {
      wait_for_free_slots();
    }

    auto& slot = head->value;
    auto& value = slot.ptr;

    if (!value) {
      try {
        value = T::make(std::forward<Args>(args)...);
      } catch (...) {
        free_list_.push(*head);
        throw;
      }
    }

    if (value) {
      return ptr(*head);
    }

    free_list_.push(*head); // put empty slot back into the free list

    return ptr();
  }

  size_t size() const NOEXCEPT { return pool_.size(); }

  template<typename Visitor>
  bool visit(const Visitor& visitor) {
    return const_cast<const bounded_object_pool&>(*this).visit(visitor);
  }

  template<typename Visitor>
  bool visit(const Visitor& visitor) const {
    stack list;

    auto release_all = make_finally([this, &list] () {
      while (auto* head = list.pop()) {
        free_list_.push(*head);
      }
    });

    auto size = pool_.size();

    while (size) {
      node_type* head = nullptr;

      while (!(head = free_list_.pop())) {
        wait_for_free_slots();
      }

      list.push(*head);

      auto& obj = head->value.ptr;

      if (obj && !visitor(*obj)) {
        return false;
      }

      --size;
    }

    return true;
  }

 private:
  void wait_for_free_slots() const {
    SCOPED_LOCK_NAMED(mutex_, lock);

    if (free_list_.empty()) {
      cond_.wait_for(lock, std::chrono::milliseconds(1000));
    }
  }

  void unlock(node_type& slot) const NOEXCEPT {
    free_list_.push(slot);
    cond_.notify_all();
  }

  mutable std::condition_variable cond_;
  mutable std::mutex mutex_;
  mutable std::vector<node_type> pool_;
  mutable stack free_list_;
}; // bounded_object_pool

template<typename T>
typename bounded_object_pool<T>::node_type bounded_object_pool<T>::ptr::EMPTY_SLOT;

// -----------------------------------------------------------------------------
// --SECTION--                                                    unbounded pool
// -----------------------------------------------------------------------------

//////////////////////////////////////////////////////////////////////////////
/// @class async_value
/// @brief convenient class storing value and associated read-write lock
//////////////////////////////////////////////////////////////////////////////
template<typename T>
class async_value {
 public:
  typedef T value_type;
  typedef async_utils::read_write_mutex::read_mutex read_lock_type;
  typedef async_utils::read_write_mutex::write_mutex write_lock_type;

  template<typename... Args>
  explicit async_value(Args&&... args)
    : value_(std::forward<Args>(args)...) {
  }

  const value_type& value() const NOEXCEPT {
    return value_;
  }

  value_type& value() NOEXCEPT {
    return value_;
  }

  read_lock_type& read_lock() const NOEXCEPT {
    return read_lock_;
  }

  write_lock_type& write_lock() const NOEXCEPT {
    return write_lock_;
  }

 protected:
  value_type value_;
  async_utils::read_write_mutex lock_;
  mutable read_lock_type read_lock_{ lock_ };
  mutable write_lock_type write_lock_{ lock_ };
}; // async_value

//////////////////////////////////////////////////////////////////////////////
/// @class unbounded_object_pool_base
/// @brief base class for all unbounded object pool implementations
//////////////////////////////////////////////////////////////////////////////
template<typename T>
class unbounded_object_pool_base : private util::noncopyable {
 public:
  typedef typename T::ptr::element_type element_type;

  size_t size() const NOEXCEPT { return pool_.size(); }

 protected:
  typedef concurrent_stack<typename T::ptr> stack;
  typedef typename stack::node_type node;

  explicit unbounded_object_pool_base(size_t size)
    : pool_(size), free_slots_(pool_.data()) {
    // build up linked list
    for (auto begin = pool_.begin(), end = pool_.end(), next = begin < end ? (begin + 1) : end;
         next < end;
         begin = next, ++next) {
      begin->next = &*next;
    }
  }

  unbounded_object_pool_base(unbounded_object_pool_base&& rhs) NOEXCEPT
    : pool_(std::move(rhs.pool_)) {
  }

  template<typename... Args>
  typename T::ptr acquire(Args&&... args) {
    auto* head = free_objects_.pop();

    if (head) {
      auto value = std::move(head->value);
      assert(value);
      free_slots_.push(*head);
      return value;
    }

    return T::make(std::forward<Args>(args)...);
  }

  void release(typename T::ptr&& value) NOEXCEPT {
    if (!value) {
      return; // do not hold nullptr values in the pool since emplace(...) uses nullptr to denot creation failure
    }

    auto* slot = free_slots_.pop();

    if (!slot) {
      // no free slots
      return;
    }

    assert(value);
    slot->value = std::move(value);
    free_objects_.push(*slot);
  }

  std::vector<node> pool_;
  stack free_objects_; // list of created objects that are ready to be reused
  stack free_slots_; // list of free slots to be reused
}; // unbounded_object_pool_base

//////////////////////////////////////////////////////////////////////////////
/// @class unbounded_object_pool
/// @brief a fixed size pool of objects
///        if the pool is empty then a new object is created via make(...)
///        if an object is available in a pool then in is returned and no
///        longer tracked by the pool
///        when the object is released it is placed back into the pool if
///        space in the pool is available
///        pool owns produced object so it's not allowed to destroy before
///        all acquired objects will be destroyed
/// @note object 'ptr' that evaluate to false when returnd back into the pool
///       will be discarded instead
//////////////////////////////////////////////////////////////////////////////
template<typename T>
class unbounded_object_pool : public unbounded_object_pool_base<T> {
 private:
  typedef unbounded_object_pool_base<T> base_t;
  typedef typename base_t::node node;

 public:
  typedef typename base_t::element_type element_type;

  /////////////////////////////////////////////////////////////////////////////
  /// @class ptr
  /// @brief represents a control object of unbounded_object_pool with
  ///        semantic similar to smart pointers
  /////////////////////////////////////////////////////////////////////////////
  class ptr : util::noncopyable {
   public:
    ptr(typename T::ptr&& value,
        unbounded_object_pool& owner
    ) : value_(std::move(value)),
        owner_(&owner) {
    }

    ptr(ptr&& rhs) NOEXCEPT
      : value_(std::move(rhs.value_)),
        owner_(rhs.owner_) {
      rhs.owner_ = nullptr;
    }

    ptr& operator=(ptr&& rhs) NOEXCEPT {
      if (this != &rhs) {
        value_ = std::move(rhs.value_);
        owner_ = rhs.owner_;
        rhs.owner_ = nullptr;
      }
      return *this;
    }

    ~ptr() NOEXCEPT {
      reset();
    }

    FORCE_INLINE void reset() NOEXCEPT {
      reset_impl(value_, owner_);
    }

    // FIXME handle potential bad_alloc in shared_ptr constructor
    // mark method as NOEXCEPT and move back all the stuff in case of error
    std::shared_ptr<element_type> release() {
      auto* raw = get();
      auto moved_value = make_move_on_copy(std::move(value_));
      auto* owner = owner_;
      owner_ = nullptr; // moved

      // in case if exception occurs
      // destructor will be called
      return std::shared_ptr<element_type>(
        raw,
        [owner, moved_value] (element_type*) mutable NOEXCEPT {
          reset_impl(moved_value.value(), owner);
      });
    }

    element_type& operator*() const NOEXCEPT { return *value_; }
    element_type* operator->() const NOEXCEPT { return get(); }
    element_type* get() const NOEXCEPT { return value_.get(); }
    operator bool() const NOEXCEPT {
      return static_cast<bool>(value_);
    }

   private:
    static void reset_impl(typename T::ptr& obj, unbounded_object_pool*& owner) NOEXCEPT {
      if (!owner) {
        // already destroyed
        return;
      }

      owner->release(std::move(obj));
      obj = typename T::ptr{}; // reset value
      owner = nullptr; // mark as destroyed
    }

    typename T::ptr value_;
    unbounded_object_pool* owner_;
  };

  explicit unbounded_object_pool(size_t size = 0)
    : base_t(size) {
  }

#if defined(_MSC_VER)
  #pragma warning( disable : 4706 )
#elif defined (__GNUC__)
  #pragma GCC diagnostic push
  #pragma GCC diagnostic ignored "-Wparentheses"
#endif

  /////////////////////////////////////////////////////////////////////////////
  /// @brief clears all cached objects
  /////////////////////////////////////////////////////////////////////////////
  void clear() {
    node* head = nullptr;

    // reset all cached instances
    while (head = this->free_objects_.pop()) {
      head->value = typename T::ptr{}; // empty instance
      this->free_slots_.push(*head);
    }
  }

#if defined(_MSC_VER)
  #pragma warning( default : 4706 )
#elif defined (__GNUC__)
  #pragma GCC diagnostic pop
#endif

  template<typename... Args>
  ptr emplace(Args&&... args) {
    return ptr(this->acquire(std::forward<Args>(args)...), *this);
  }

 private:
  // disallow move
  unbounded_object_pool(unbounded_object_pool&&) = delete;
  unbounded_object_pool& operator=(unbounded_object_pool&&) = delete;

}; // unbounded_object_pool

NS_BEGIN(detail)

template<typename Pool>
struct pool_generation {
  explicit pool_generation(Pool* owner) NOEXCEPT
    : owner(owner) {
  }

  bool stale{false}; // stale mark
  Pool* owner; // current owner
}; // pool_generation

NS_END // detail

//////////////////////////////////////////////////////////////////////////////
/// @class unbounded_object_pool_volatile
/// @brief a fixed size pool of objects
///        if the pool is empty then a new object is created via make(...)
///        if an object is available in a pool then in is returned and no
///        longer tracked by the pool
///        when the object is released it is placed back into the pool if
///        space in the pool is available
///        pool may be safely destroyed even there are some produced objects
///        alive
/// @note object 'ptr' that evaluate to false when returnd back into the pool
///       will be discarded instead
//////////////////////////////////////////////////////////////////////////////
template<typename T>
class unbounded_object_pool_volatile
    : public unbounded_object_pool_base<T>,
      private atomic_shared_ptr_helper<
        async_value<detail::pool_generation<unbounded_object_pool_volatile<T>>>
      > {
 private:
  typedef unbounded_object_pool_base<T> base_t;

  typedef async_value<detail::pool_generation<unbounded_object_pool_volatile<T>>> generation_t;
  typedef std::shared_ptr<generation_t> generation_ptr_t;
  typedef atomic_shared_ptr_helper<generation_t> atomic_utils;

  typedef std::lock_guard<typename generation_t::read_lock_type> read_guard_t;
  typedef std::lock_guard<typename generation_t::write_lock_type> write_guard_t;

 public:
  typedef typename base_t::element_type element_type;

  /////////////////////////////////////////////////////////////////////////////
  /// @class ptr
  /// @brief represents a control object of unbounded_object_pool with
  ///        semantic similar to smart pointers
  /////////////////////////////////////////////////////////////////////////////
  class ptr : util::noncopyable {
   public:
    ptr(typename T::ptr&& value,
        const generation_ptr_t& gen) NOEXCEPT
      : value_(std::move(value)),
        gen_(std::move(gen)) {
    }

    ptr(ptr&& rhs) NOEXCEPT
      : value_(std::move(rhs.value_)),
        gen_(std::move(rhs.gen_)) {
    }

    ptr& operator=(ptr&& rhs) NOEXCEPT {
      if (this != &rhs) {
        value_ = std::move(rhs.value_);
        gen_ = std::move(rhs.gen_);
      }
      return *this;
    }

    ~ptr() NOEXCEPT {
      reset();
    }

    FORCE_INLINE void reset() NOEXCEPT {
      reset_impl(value_, gen_);
    }

    std::shared_ptr<element_type> release() {
      auto* raw = get();
      auto moved_value = make_move_on_copy(std::move(value_));
      auto moved_gen = make_move_on_copy(std::move(gen_));
      assert(!gen_); // moved

      // in case if exception occurs
      // destructor will be called
      return std::shared_ptr<element_type>(
        raw,
        [moved_gen, moved_value] (element_type*) mutable NOEXCEPT {
          reset_impl(moved_value.value(), moved_gen.value());
      });
    }

    element_type& operator*() const NOEXCEPT { return *value_; }
    element_type* operator->() const NOEXCEPT { return get(); }
    element_type* get() const NOEXCEPT { return value_.get(); }
    operator bool() const NOEXCEPT {
      return static_cast<bool>(gen_);
    }

   private:
    static void reset_impl(typename T::ptr& obj, generation_ptr_t& gen) NOEXCEPT {
      if (!gen) {
        // already destroyed
        return;
      }

      // do not remove scope!!!
      // variable 'lock' below must be destroyed before 'gen_'
      {
        read_guard_t lock(gen->read_lock());
        auto& value = gen->value();

        if (!value.stale) {
          value.owner->release(std::move(obj));
        }
      }

      obj = typename T::ptr{}; // clear object oustide the lock
      gen = nullptr; // mark as destroyed
    }

    typename T::ptr value_;
    generation_ptr_t gen_;
  }; // ptr

  explicit unbounded_object_pool_volatile(size_t size = 0)
    : base_t(size),
      gen_(memory::make_shared<generation_t>(this)) {
  }

  // FIXME check what if
  //
  // unbounded_object_pool_volatile p0, p1;
  // thread0: p0.clear();
  // thread1: unbounded_object_pool_volatile p1(std::move(p0));
  unbounded_object_pool_volatile(unbounded_object_pool_volatile&& rhs) NOEXCEPT
    : base_t(std::move(rhs)) {
    gen_ = atomic_utils::atomic_load(&rhs.gen_);

    write_guard_t lock(gen_->write_lock());
    gen_->value().owner = this; // change owner

    this->free_slots_ = std::move(rhs.free_slots_);
    this->free_objects_ = std::move(rhs.free_objects_);
  }

  ~unbounded_object_pool_volatile() NOEXCEPT {
    // prevent existing elements from returning into the pool
    // if pool doesn't own generation anymore
    const auto gen = atomic_utils::atomic_load(&gen_);
    write_guard_t lock(gen->write_lock());

    auto& value = gen->value();

    if (value.owner == this) {
      value.stale = true;
    }
  }

  /////////////////////////////////////////////////////////////////////////////
  /// @brief clears all cached objects and optionally prevents already created
  ///        objects from returning into the pool
  /// @param new_generation if true, prevents already created objects from
  ///        returning into the pool, otherwise just clears all cached objects
  /////////////////////////////////////////////////////////////////////////////
  void clear(bool new_generation = false) {
    // prevent existing elements from returning into the pool
    if (new_generation) {
      {
        auto gen = atomic_utils::atomic_load(&gen_);
        write_guard_t lock(gen->write_lock());
        gen->value().stale = true;
      }

      // mark new generation
      atomic_utils::atomic_store(&gen_, memory::make_shared<generation_t>(this));
    }

    typename base_t::node* head = nullptr;

    // reset all cached instances
    while ((head = this->free_objects_.pop())) {
      head->value = typename T::ptr{}; // empty instance
      this->free_slots_.push(*head);
    }
  }

  template<typename... Args>
  ptr emplace(Args&&... args) {
    static const generation_ptr_t no_gen;
    const auto gen = atomic_utils::atomic_load(&gen_); // retrieve before seek/instantiate
    auto value = this->acquire(std::forward<Args>(args)...);

    return value ? ptr(std::move(value), gen) : ptr(nullptr, no_gen);
  }

  size_t generation_size() const NOEXCEPT {
    const auto use_count = atomic_utils::atomic_load(&gen_).use_count();
    assert(use_count >= 2);
    return use_count - 2; // -1 for temporary object, -1 for this->_gen
  }

 private:
  // disallow move assignment
  unbounded_object_pool_volatile& operator=(unbounded_object_pool_volatile&&) = delete;

  generation_ptr_t gen_; // current generation
}; // unbounded_object_pool_volatile

NS_END

#endif

redpajama_set_name: RedPajamaGithub


text:
/* This is a generated file. */
FT_USE_MODULE(FT_Driver_ClassRec, tt_driver_class)
FT_USE_MODULE(FT_Driver_ClassRec, t1_driver_class)
FT_USE_MODULE(FT_Driver_ClassRec, cff_driver_class)
FT_USE_MODULE(FT_Driver_ClassRec, t1cid_driver_class)
FT_USE_MODULE(FT_Driver_ClassRec, pfr_driver_class)
FT_USE_MODULE(FT_Driver_ClassRec, t42_driver_class)
FT_USE_MODULE(FT_Driver_ClassRec, winfnt_driver_class)
FT_USE_MODULE(FT_Driver_ClassRec, pcf_driver_class)
FT_USE_MODULE(FT_Driver_ClassRec, bdf_driver_class)
FT_USE_MODULE(FT_Module_Class, sfnt_module_class)
FT_USE_MODULE(FT_Module_Class, autofit_module_class)
FT_USE_MODULE(FT_Module_Class, pshinter_module_class)
FT_USE_MODULE(FT_Renderer_Class, ft_raster1_renderer_class)
FT_USE_MODULE(FT_Renderer_Class, ft_smooth_renderer_class)
FT_USE_MODULE(FT_Renderer_Class, ft_smooth_lcd_renderer_class)
FT_USE_MODULE(FT_Renderer_Class, ft_smooth_lcdv_renderer_class)
FT_USE_MODULE(FT_Module_Class, gxv_module_class)
FT_USE_MODULE(FT_Module_Class, otv_module_class)
FT_USE_MODULE(FT_Module_Class, psaux_module_class)
FT_USE_MODULE(FT_Module_Class, psnames_module_class)
/* EOF */


text:
package com.alibaba.rocketmq.common;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/**
 *
 * @author yankai913@gmail.com
 * @date 2014-2-17
 */
public class Table {

    private final static String DEFAULT_NULL_VALUE = "CELL_IS_NULL";

    private final int column;

    private final int row;

    private final List<Object[]> tbodyData;

    private String[] thead;

    private LinkedHashMap<String, String> extData = new LinkedHashMap<String, String>();

    public Table(int row, int column) {
        if (row <= 0 || column <= 0) {
            throw new IllegalArgumentException("invalid row or column");
        }
        this.row = row;
        this.column = column;
        this.tbodyData = new ArrayList<Object[]>(getRow());
    }

    public Table(String[] thead, List<Object[]> tbodyData) {
        checkTheadNotNull(thead);
        this.thead = thead;
        this.column = getThead().length;
        checkTbodyDataNotNull(tbodyData);
        checkTbodyDataValid(tbodyData, getColumn());
        this.row = tbodyData.size();
        this.tbodyData = tbodyData;
    }

    public Table(List<Object[]> tbodyData) {
        checkTbodyDataNotNull(tbodyData);
        this.row = tbodyData.size();
        this.column = tbodyData.get(0).length;
        checkTbodyDataValid(tbodyData, getColumn());
        this.tbodyData = tbodyData;
    }

    public Table(String[] thead, int row) {
        checkTheadNotNull(thead);
        this.thead = thead;
        this.column = getThead().length;
        this.row = row;
        this.tbodyData = new ArrayList<Object[]>(getRow());
    }

    private void checkTheadNotNull(String[] thead) {
        if (thead == null || thead.length <= 0) {
            throw new IllegalArgumentException("thead is blank");
        }
    }

    private void checkTbodyDataNotNull(List<Object[]> tbodyData) {
        if (tbodyData == null || tbodyData.size() <= 0) {
            throw new IllegalArgumentException("tbodyData is blank");
        }
        for (Object[] tr : tbodyData) {
            if (tr == null || tr.length <= 0) {
                throw new IllegalArgumentException("tbodyData`tr is blank");
            }
        }
    }

    private void checkTbodyDataValid(List<Object[]> tbodyData, int column) {
        for (Object[] tr : tbodyData) {
            if (tr.length != column) {
                throw new IllegalArgumentException("tbodyData`tr is invalid");
            }
        }
    }

    public Object[] createTR() {
        Object[] tr = new Object[getColumn()];
        Arrays.fill(tr, DEFAULT_NULL_VALUE);
        return tr;
    }

    public Table insertTR(Object[] tr) {
        if (tr.length != getColumn()) {
            throw new IllegalArgumentException("column not equal tr.length!");
        }
        getTbodyData().add(tr);
        return this;
    }

    public void removeTR(int index) {
        getTbodyData().remove(index);
    }

    public List<Object[]> getTbodyData() {
        return tbodyData;
    }

    public String[] getThead() {
        return thead;
    }

    public int getColumn() {
        return this.column;
    }

    public int getRow() {
        return row;
    }

    static String[] getTheadFromMap(Map<String, String> map) {
        int column = map.entrySet().size();
        String[] thead = new String[column];
        Iterator<String> ite = map.keySet().iterator();
        int i = 0;
        while (ite.hasNext()) {
            thead[i] = ite.next();
            i++;
        }
        return thead;
    }

    static Object[] getTbodyFromMap(Map<String, String> map) {
        int column = map.entrySet().size();
        Object[] tbody = new Object[column];
        Iterator<Map.Entry<String, String>> ite = map.entrySet().iterator();
        int i = 0;
        while (ite.hasNext()) {
            tbody[i] = ite.next().getValue();
            i++;
        }
        return tbody;
    }

    public static Table Map2VTable(Map<String, String> map) {
        int row = map.entrySet().size();
        Table table = new Table(row, 2);
        Iterator<Map.Entry<String, String>> ite = map.entrySet().iterator();
        while (ite.hasNext()) {
            Map.Entry<String, String> entry = ite.next();
            Object[] tr = table.createTR();
            tr[0] = entry.getKey();
            tr[1] = entry.getValue();
            table.insertTR(tr);
        }
        return table;
    }

    public static Table Map2HTable(Map<String, String> map) {
        List<Object[]> tbody = new ArrayList<Object[]>();
        Object[] tr = getTbodyFromMap(map);
        tbody.add(tr);
        String[] thead = getTheadFromMap(map);
        return new Table(thead, tbody);
    }

    public static Table Maps2HTable(List<Map<String, String>> list) {
        Table table = null;
        for (Map<String, String> map : list) {
            if (table == null) {
                String[] thead = getTheadFromMap(map);
                table = new Table(thead, list.size());
            }
            Object[] tr = getTbodyFromMap(map);
            table.insertTR(tr);
        }
        return table;
    }

    public LinkedHashMap<String, String> getExtData() {
        return extData;
    }

    public void addExtData(String key, String value) {
        extData.put(key, value);
    }
}


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.execution.scheduler;

import com.google.common.base.Joiner;
import com.google.common.collect.ImmutableList;

import java.util.Arrays;
import java.util.List;

import static com.google.common.base.MoreObjects.toStringHelper;
import static java.util.Objects.requireNonNull;

/**
 * Represents a location in the network topology. Locations are assumed to be hierarchical
 * and all worker nodes and split locations should be at the same level of the hierarchy.
 */
public final class NetworkLocation
{
    public static final NetworkLocation ROOT_LOCATION = new NetworkLocation();

    private final List<String> segments;

    public NetworkLocation(String... segments)
    {
        this(Arrays.asList(segments));
    }

    private NetworkLocation(List<String> segments)
    {
        this.segments = segments;
    }

    public static NetworkLocation create(List<String> segments)
    {
        requireNonNull(segments, "segments is null");
        return new NetworkLocation(ImmutableList.copyOf(segments));
    }

    public NetworkLocation subLocation(int start, int end)
    {
        return new NetworkLocation(segments.subList(start, end));
    }

    public List<String> getSegments()
    {
        return segments;
    }

    @Override
    public boolean equals(Object obj)
    {
        if (this == obj) {
            return true;
        }
        if (obj == null || getClass() != obj.getClass()) {
            return false;
        }
        NetworkLocation that = (NetworkLocation) obj;
        // NOTE: This is performance sensitive and does not use Objects.equals to avoid excess object allocation
        return segments.equals(that.segments);
    }

    @Override
    public int hashCode()
    {
        // NOTE: This is performance sensitive and does not use Objects.hash to avoid excess object allocation
        return segments.hashCode();
    }

    @Override
    public String toString()
    {
        return toStringHelper(this)
                .add("location", "/" + Joiner.on("/").join(segments))
                .toString();
    }
}


text:
require 'spec_helper'

describe CaseSensitivity, models: true do
  describe '.iwhere' do
    let(:connection) { ActiveRecord::Base.connection }
    let(:model)      { Class.new { include CaseSensitivity } }

    describe 'using PostgreSQL' do
      before do
        allow(Gitlab::Database).to receive(:postgresql?).and_return(true)
        allow(Gitlab::Database).to receive(:mysql?).and_return(false)
      end

      describe 'with a single column/value pair' do
        it 'returns the criteria for a column and a value' do
          criteria = double(:criteria)

          expect(connection).to receive(:quote_table_name).
            with(:foo).
            and_return('"foo"')

          expect(model).to receive(:where).
            with(%q{LOWER("foo") = LOWER(:value)}, value: 'bar').
            and_return(criteria)

          expect(model.iwhere(foo: 'bar')).to eq(criteria)
        end

        it 'returns the criteria for a column with a table, and a value' do
          criteria = double(:criteria)

          expect(connection).to receive(:quote_table_name).
            with(:'foo.bar').
            and_return('"foo"."bar"')

          expect(model).to receive(:where).
            with(%q{LOWER("foo"."bar") = LOWER(:value)}, value: 'bar').
            and_return(criteria)

          expect(model.iwhere(:'foo.bar' => 'bar')).to eq(criteria)
        end
      end

      describe 'with multiple column/value pairs' do
        it 'returns the criteria for a column and a value' do
          initial = double(:criteria)
          final   = double(:criteria)

          expect(connection).to receive(:quote_table_name).
            with(:foo).
            and_return('"foo"')

          expect(connection).to receive(:quote_table_name).
            with(:bar).
            and_return('"bar"')

          expect(model).to receive(:where).
            with(%q{LOWER("foo") = LOWER(:value)}, value: 'bar').
            and_return(initial)

          expect(initial).to receive(:where).
            with(%q{LOWER("bar") = LOWER(:value)}, value: 'baz').
            and_return(final)

          got = model.iwhere(foo: 'bar', bar: 'baz')

          expect(got).to eq(final)
        end

        it 'returns the criteria for a column with a table, and a value' do
          initial = double(:criteria)
          final   = double(:criteria)

          expect(connection).to receive(:quote_table_name).
            with(:'foo.bar').
            and_return('"foo"."bar"')

          expect(connection).to receive(:quote_table_name).
            with(:'foo.baz').
            and_return('"foo"."baz"')

          expect(model).to receive(:where).
            with(%q{LOWER("foo"."bar") = LOWER(:value)}, value: 'bar').
            and_return(initial)

          expect(initial).to receive(:where).
            with(%q{LOWER("foo"."baz") = LOWER(:value)}, value: 'baz').
            and_return(final)

          got = model.iwhere(:'foo.bar' => 'bar',
                             :'foo.baz' => 'baz')

          expect(got).to eq(final)
        end
      end
    end

    describe 'using MySQL' do
      before do
        allow(Gitlab::Database).to receive(:postgresql?).and_return(false)
        allow(Gitlab::Database).to receive(:mysql?).and_return(true)
      end

      describe 'with a single column/value pair' do
        it 'returns the criteria for a column and a value' do
          criteria = double(:criteria)

          expect(connection).to receive(:quote_table_name).
            with(:foo).
            and_return('`foo`')

          expect(model).to receive(:where).
            with(%q{`foo` = :value}, value: 'bar').
            and_return(criteria)

          expect(model.iwhere(foo: 'bar')).to eq(criteria)
        end

        it 'returns the criteria for a column with a table, and a value' do
          criteria = double(:criteria)

          expect(connection).to receive(:quote_table_name).
            with(:'foo.bar').
            and_return('`foo`.`bar`')

          expect(model).to receive(:where).
            with(%q{`foo`.`bar` = :value}, value: 'bar').
            and_return(criteria)

          expect(model.iwhere(:'foo.bar' => 'bar')).
            to eq(criteria)
        end
      end

      describe 'with multiple column/value pairs' do
        it 'returns the criteria for a column and a value' do
          initial = double(:criteria)
          final   = double(:criteria)

          expect(connection).to receive(:quote_table_name).
            with(:foo).
            and_return('`foo`')

          expect(connection).to receive(:quote_table_name).
            with(:bar).
            and_return('`bar`')

          expect(model).to receive(:where).
            with(%q{`foo` = :value}, value: 'bar').
            and_return(initial)

          expect(initial).to receive(:where).
            with(%q{`bar` = :value}, value: 'baz').
            and_return(final)

          got = model.iwhere(foo: 'bar', bar: 'baz')

          expect(got).to eq(final)
        end

        it 'returns the criteria for a column with a table, and a value' do
          initial = double(:criteria)
          final   = double(:criteria)

          expect(connection).to receive(:quote_table_name).
            with(:'foo.bar').
            and_return('`foo`.`bar`')

          expect(connection).to receive(:quote_table_name).
            with(:'foo.baz').
            and_return('`foo`.`baz`')

          expect(model).to receive(:where).
            with(%q{`foo`.`bar` = :value}, value: 'bar').
            and_return(initial)

          expect(initial).to receive(:where).
            with(%q{`foo`.`baz` = :value}, value: 'baz').
            and_return(final)

          got = model.iwhere(:'foo.bar' => 'bar',
                             :'foo.baz' => 'baz')

          expect(got).to eq(final)
        end
      end
    end
  end
end


text:
package com.impossibl.stencil.engine;

public class InvocationException extends ExecutionException {

  private static final long serialVersionUID = -5527033329538312329L;

  public InvocationException() {
	}

  public InvocationException(String message, Throwable cause, ExecutionLocation location) {
    super(message, cause, location);
  }

  public InvocationException(String message, ExecutionLocation location) {
    super(message, location);
  }

}


text:
/* Generated By:JJTree: Do not edit this line. AstFunction.java */

package org.apache.struts2.el.parser;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

import javax.el.ELException;
import javax.el.FunctionMapper;

import org.apache.struts2.el.lang.EvaluationContext;
import org.apache.struts2.el.util.MessageFactory;

/**
 * @author Jacob Hookom [jacob@hookom.net]
 * @version $Change: 181177 $$DateTime: 2001/06/26 08:45:09 $$Author: markt $
 */
public final class AstFunction extends SimpleNode {

    protected String localName = "";

    protected String prefix = "";

    public AstFunction(int id) {
        super(id);
    }

    public String getLocalName() {
        return localName;
    }

    public String getOutputName() {
        if (this.prefix == null) {
            return this.localName;
        } else {
            return this.prefix + ":" + this.localName;
        }
    }

    public String getPrefix() {
        return prefix;
    }

    public Class getType(EvaluationContext ctx)
            throws ELException {

        FunctionMapper fnMapper = ctx.getFunctionMapper();

        // quickly validate again for this request
        if (fnMapper == null) {
            throw new ELException(MessageFactory.get("error.fnMapper.null"));
        }
        Method m = fnMapper.resolveFunction(this.prefix, this.localName);
        if (m == null) {
            throw new ELException(MessageFactory.get("error.fnMapper.method",
                    this.getOutputName()));
        }
        return m.getReturnType();
    }

    public Object getValue(EvaluationContext ctx)
            throws ELException {

        FunctionMapper fnMapper = ctx.getFunctionMapper();

        // quickly validate again for this request
        if (fnMapper == null) {
            throw new ELException(MessageFactory.get("error.fnMapper.null"));
        }
        Method m = fnMapper.resolveFunction(this.prefix, this.localName);
        if (m == null) {
            throw new ELException(MessageFactory.get("error.fnMapper.method",
                    this.getOutputName()));
        }

        Class[] paramTypes = m.getParameterTypes();
        Object[] params = null;
        Object result = null;
        int numParams = this.jjtGetNumChildren();
        if (numParams > 0) {
            params = new Object[numParams];
            try {
                for (int i = 0; i < numParams; i++) {
                    params[i] = this.children[i].getValue(ctx);
                    params[i] = coerceToType(params[i], paramTypes[i]);
                }
            } catch (ELException ele) {
                throw new ELException(MessageFactory.get("error.function", this
                        .getOutputName()), ele);
            }
        }
        try {
            result = m.invoke(null, params);
        } catch (IllegalAccessException iae) {
            throw new ELException(MessageFactory.get("error.function", this
                    .getOutputName()), iae);
        } catch (InvocationTargetException ite) {
            throw new ELException(MessageFactory.get("error.function", this
                    .getOutputName()), ite.getCause());
        }
        return result;
    }

    public void setLocalName(String localName) {
        this.localName = localName;
    }

    public void setPrefix(String prefix) {
        this.prefix = prefix;
    }

    public String toString()
    {
        return ELParserTreeConstants.jjtNodeName[id] + "[" + this.getOutputName() + "]";
    }
}


text: google-site-verification: google25fdb11d78551270.html


text:
namespace bbe
{
	template<typename T> class Vector2_t;
	using Vector2 = Vector2_t<float>;

	class Vector3
	{
	public:
		float x;
		float y;
		float z;

		Vector3();
		explicit Vector3(float xyz);
		Vector3(float x, float y, float z);
		Vector3(float x, const Vector2 &yz);
		Vector3(const Vector2 &xy, float z);

		Vector3& operator+=(const Vector3& other);
		Vector3& operator-=(const Vector3& other);
		Vector3& operator*=(const Vector3& other);
		Vector3& operator/=(const Vector3& other);
		Vector3& operator*=(const float scalar);
		Vector3& operator/=(const float scalar);

		Vector3 operator*(float scalar) const;
		Vector3 operator/(float scalar) const;
		float operator*(const Vector3 &other) const;
		Vector3 operator+(const Vector3 &other) const;
		Vector3 operator-(const Vector3 &other) const;
		Vector3 operator-() const;
		float& operator[](int index);
		const float& operator[](int index) const;

		bool operator==(const Vector3 &other) const;
		bool operator!=(const Vector3 &other) const;
		bool operator> (const Vector3 &other) const;
		bool operator>=(const Vector3 &other) const;
		bool operator< (const Vector3 &other) const;
		bool operator<=(const Vector3 &other) const;

		bool equals(const Vector3 &other, float epsilon = 0.001f) const;
		bool isSameLength(const Vector3 &other, float epsilon = 0.001f) const;
		bool isSameDirection(const Vector3 &other) const;
		bool isOppositeDirection(const Vector3 &other) const;
		bool isLeft(const Vector3 &other) const;
		bool isRight(const Vector3 &other) const;
		bool isContainingNaN() const;
		bool isContainingInfinity() const;
		bool isUnit(float epsilon = 0.001f) const;
		bool isCloseTo(const Vector3 &other, float maxDistance) const;
		bool isZero() const;

		Vector3 rotate(float radians, const Vector3 &axisOfRotation) const;
		Vector3 rotate(float radians, const Vector3 &axisOfRotation, const Vector3 &center) const;
		Vector3 withLenght(float length) const;
		Vector3 normalize() const;
		Vector3 abs() const;
		Vector3 clampComponents(float min, float max) const;
		Vector3 project(const Vector3 &other) const;
		Vector3 reflect(const Vector3 &normal) const;
		Vector3 cross(const Vector3 &other) const;

		float getLength() const;
		float getLengthSq() const;
		float getLengthSqSigned() const;
		float getDistanceTo(const Vector3 &other) const;
		float getMax() const;
		float getMin() const;
		float getMaxAbs() const;
		float getMinAbs() const;
		float getMaxAbsKeepSign() const;
		float getMinAbsKeepSign() const;
		float getAngle() const;
		float getAngle(const Vector3 &other) const;

		//Begin Swizzles
		Vector2 xx() const;
		Vector2 xy() const;
		Vector2 xz() const;
		Vector2 yx() const;
		Vector2 yy() const;
		Vector2 yz() const;
		Vector2 zx() const;
		Vector2 zy() const;
		Vector2 zz() const;

		Vector3 xxx() const;
		Vector3 xxy() const;
		Vector3 xxz() const;
		Vector3 xyx() const;
		Vector3 xyy() const;
		Vector3 xyz() const;
		Vector3 xzx() const;
		Vector3 xzy() const;
		Vector3 xzz() const;
		Vector3 yxx() const;
		Vector3 yxy() const;
		Vector3 yxz() const;
		Vector3 yyx() const;
		Vector3 yyy() const;
		Vector3 yyz() const;
		Vector3 yzx() const;
		Vector3 yzy() const;
		Vector3 yzz() const;
		Vector3 zxx() const;
		Vector3 zxy() const;
		Vector3 zxz() const;
		Vector3 zyx() const;
		Vector3 zyy() const;
		Vector3 zyz() const;
		Vector3 zzx() const;
		Vector3 zzy() const;
		Vector3 zzz() const;
	};
}


text:
package org.adonai.services;

import org.adonai.model.Line;
import org.adonai.model.LinePart;
import org.adonai.model.Song;
import org.adonai.model.SongPart;
import org.adonai.model.SongStructItem;

public class SongNavigationService {

  public LinePart stepToNextPart (final SongCursor songCursor) {

    SongStructItem currentStructItem = songCursor.getCurrentSongStructItem();
    Song currentSong = songCursor.getCurrentSong();
    if (currentStructItem.equals(currentSong.getLastStructItem()))
      return songCursor.getCurrentLinePart();
    else {
      SongStructItem nextStructItem = currentSong.getNextStructItem(currentStructItem);
      SongPart nextSongPart = currentSong.findSongPart(nextStructItem);
      return nextSongPart.getFirstLine().getFirstLinePart();
    }
  }

  public LinePart stepToPreviousPart (final SongCursor songCursor) {
    SongStructItem currentStructItem = songCursor.getCurrentSongStructItem();
    Song currentSong = songCursor.getCurrentSong();
    if (currentStructItem.equals(currentSong.getFirstStructItem()))
      return songCursor.getCurrentLinePart();
    else {
      SongStructItem nextStructItem = currentSong.getPreviousStructItem(currentStructItem);
      SongPart nextSongPart = currentSong.findSongPart(nextStructItem);
      return nextSongPart.getFirstLine().getFirstLinePart();
    }

  }

  /**
   * steps to previous line part
   * - previous line if we are in first part of line
   * - previous part if we are in first part of first line
   * @param songCursor  current position
   * @return line part to focus
   */
  public LinePart stepToPreviousLinePart (final SongCursor songCursor) {
    LinePart linePart = songCursor.getCurrentLinePart();
    Line line = songCursor.getCurrentLine();
    Song song = songCursor.getCurrentSong();
    SongStructItem songStructItem = songCursor.getCurrentSongStructItem();
    SongPart songPart = songCursor.getCurrentSongPart();

    if (! linePart.equals(line.getFirstLinePart())) { // if not last linepart in line
      return line.getPreviousLinePart(linePart);
    }
    else {
      if (!line.equals(songPart.getFirstLine())) {
        return songPart.getPreviousLine(line).getLastLinePart();
      }
      else if (!songStructItem.equals(song.getFirstStructItem())){
        SongStructItem previousStructItem = song.getPreviousStructItem(songStructItem);
        SongPart previousSongPart = song.findSongPart(previousStructItem);
        return previousSongPart.getLastLine().getLastLinePart();
      }
    }
    return linePart;

  }

  /**
   * steps to the next line part
   * - next line if we are in last part of line
   * - next part if we are in last part of last line
   * @param songCursor  current position
   * @return focusable linepart
   */
  public LinePart stepToNextLinePart (final SongCursor songCursor) {
    LinePart linePart = songCursor.getCurrentLinePart();
    Line line = songCursor.getCurrentLine();
    Song song = songCursor.getCurrentSong();
    SongStructItem songStructItem = songCursor.getCurrentSongStructItem();
    SongPart songPart = songCursor.getCurrentSongPart();

    if (! linePart.equals(line.getLastLinePart())) { // if not last linepart in line
      return line.getNextLinePart(linePart);
    }
    else {
      if (!line.equals(songPart.getLastLine())) {
        return songPart.getNextLine(line).getFirstLinePart();
      }
      else if (!songStructItem.equals(song.getLastStructItem())){
        SongStructItem nextStructItem = song.getNextStructItem(songStructItem);
        SongPart nextSongPart = song.findSongPart(nextStructItem);
        return nextSongPart.getFirstLine().getFirstLinePart();
      }
    }
    return linePart;
  }

  public LinePart stepToPreviousLine(SongCursor songCursor) {
    Line line = songCursor.getCurrentLine();
    SongPart songPart = songCursor.getCurrentSongPart();

    if (line.equals(songPart.getFirstLine()))
      return line.getFirstLinePart();
    else
    return songPart.getPreviousLine(line).getFirstLinePart();
  }

  public LinePart stepToNextLine(SongCursor songCursor) {
    Line line = songCursor.getCurrentLine();
    SongPart songPart = songCursor.getCurrentSongPart();

    if (line.equals(songPart.getLastLine()))
      return line.getFirstLinePart();
    else
      return songPart.getNextLine(line).getFirstLinePart();
  }
}


text:
require_relative "./static"

module Rack
  class ECG
    module Check
      # @!method initialize
      #   Always returns a basic error for testing purposes.
      class Error < Static
        STATIC_PARAMETERS = {
          name: :error,
          success: false,
          value: "PC LOAD LETTER",
        }.freeze

        def initialize
          super(STATIC_PARAMETERS)
        end
      end

      CheckRegistry.instance.register(:error, Error)
    end
  end
end


text:
using System;

namespace NeuroSystem.Workflow.UserData.UI.Html.Version1.DataSources
{
    public class HierarchicalItemsSource : DataSourceBase
    {
        public virtual object GetChildren(string parentId)
        {
            throw new NotImplementedException();
        }
    }
}