<commit_before>/**
 * Copyright 2016 Red Hat, Inc. and/or its affiliates.
 *
 * Licensed under the Eclipse Public License version 1.0, available at
 * http://www.eclipse.org/legal/epl-v10.html
 */
package org.jboss.forge.addon.ui.context;

import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;

import org.jboss.forge.addon.ui.UIProvider;
import org.jboss.forge.addon.ui.command.CommandExecutionListener;
import org.jboss.forge.addon.ui.util.Selections;
import org.jboss.forge.furnace.spi.ListenerRegistration;

/**
 * This class provides a skeletal implementation of the <tt>UIContext</tt> interface, to minimize the effort required to
 * implement this interface.
 *
 * @author <a href="mailto:<EMAIL>"><NAME>, III</a>
 * @author <a href="mailto:<EMAIL>"><NAME></a>
 */
public abstract class AbstractUIContext implements UIContext
{
   private final Map<Object, Object> map;
   private UISelection<?> selection;
   private final Set<CommandExecutionListener> listeners = new LinkedHashSet<>();

   public AbstractUIContext()
   {
      // Initializing with System properties by default
      map = new HashMap<>(System.getProperties());
   }

   @Override
   @SuppressWarnings("unchecked")
   public <SELECTIONTYPE> UISelection<SELECTIONTYPE> getSelection()
   {
      return (UISelection<SELECTIONTYPE>) (selection != null ? selection : getInitialSelection());
   }

   @SuppressWarnings("unchecked")
   @Override
   public <SELECTIONTYPE> void setSelection(SELECTIONTYPE selection)
   {
      if (selection == null)
      {
         this.selection = null;
      }
      else if (selection instanceof UISelection)
      {
         this.selection = (UISelection<?>) selection;
      }
      else
      {
         this.selection = Selections.from(selection);
      }
   }

   @Override
   public <SELECTIONTYPE> void setSelection(UISelection<SELECTIONTYPE> selection)
   {<commit_msg>FORGE-2773: Moved map creation to a protected method<commit_after>/**
 * Copyright 2016 Red Hat, Inc. and/or its affiliates.
 *
 * Licensed under the Eclipse Public License version 1.0, available at
 * http://www.eclipse.org/legal/epl-v10.html
 */
package org.jboss.forge.addon.ui.context;

import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;

import org.jboss.forge.addon.ui.UIProvider;
import org.jboss.forge.addon.ui.command.CommandExecutionListener;
import org.jboss.forge.addon.ui.util.Selections;
import org.jboss.forge.furnace.spi.ListenerRegistration;

/**
 * This class provides a skeletal implementation of the <tt>UIContext</tt> interface, to minimize the effort required to
 * implement this interface.
 *
 * @author <a href="mailto:<EMAIL>"><NAME>, III</a>
 * @author <a href="mailto:<EMAIL>"><NAME></a>
 */
public abstract class AbstractUIContext implements UIContext
{
   private final Map<Object, Object> map = createAttributeMap();
   private UISelection<?> selection;
   private final Set<CommandExecutionListener> listeners = new LinkedHashSet<>();

   protected Map<Object, Object> createAttributeMap()
   {
      // Initializing with System properties by default
      return new HashMap<>(System.getProperties());
   }

   @Override
   @SuppressWarnings("unchecked")
   public <SELECTIONTYPE> UISelection<SELECTIONTYPE> getSelection()
   {
      return (UISelection<SELECTIONTYPE>) (selection != null ? selection : getInitialSelection());
   }

   @SuppressWarnings("unchecked")
   @Override
   public <SELECTIONTYPE> void setSelection(SELECTIONTYPE selection)
   {
      if (selection == null)
      {
         this.selection = null;
      }
      else if (selection instanceof UISelection)
      {
         this.selection = (UISelection<?>) selection;
      }
      else
      {
         this.selection = Selections.from(selection);
      }
   }

   @Override
   public <SELECTIONTYPE> void setSelection(UISelection<SELECTIONTYPE> selection)
   {
{'fraction_non_alphanumeric': 0.1153750311487665, 'fraction_numerical': 0.0049838026414154, 'mean_word_length': 3.8129496402877696, 'pattern_counts': {'":': 0, '<': 48, '<?xml version=': 0, '>': 48, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2499976', 'n_tokens_mistral': 1213, 'n_tokens_neox': 1176, 'n_words': 286}