@Override
 public int getIndexOfChild(Object parent, Object child) {
   if (parent instanceof RepositoryManager) {
     if (onlyWriteableRepositories) {
       return getWritableRepositories(((RepositoryManager) parent)).indexOf(child);
     }
     return ((RepositoryManager) parent).getRepositories().indexOf(child);
   } else if (parent instanceof Folder) {
     Folder folder = (Folder) parent;
     try {
       if (child instanceof Folder) {
         return folder.getSubfolders().indexOf(child);
       } else if ((child instanceof Entry) && !onlyFolders) {
         return folder.getDataEntries().indexOf(child) + folder.getSubfolders().size();
       } else {
         return -1;
       }
     } catch (RepositoryException e) {
       // LogService.getRoot().log(Level.WARNING, "Cannot get child index for "+folder.getName()+":
       // "+e, e);
       LogService.getRoot()
           .log(
               Level.WARNING,
               I18N.getMessage(
                   LogService.getRoot().getResourceBundle(),
                   "com.rapidminer.repository.gui.RepositoryTreeModel.getting_child_index_of_folder_error",
                   folder.getName(),
                   e),
               e);
       return -1;
     }
   } else {
     return -1;
   }
 }
 /** Returns true if the user entered a valid, non-empty repository location. */
 public boolean hasSelection(boolean allowFolders) {
   if (!allowFolders
       && ((enforceValidRepositoryEntryName && locationFieldRepositoryEntry.getText().isEmpty())
           || (!enforceValidRepositoryEntryName && locationField.getText().isEmpty())
           || (enforceValidRepositoryEntryName
               && !RepositoryLocation.isNameValid(locationFieldRepositoryEntry.getText())))) {
     return false;
   } else {
     try {
       getRepositoryLocation();
       return true;
     } catch (MalformedRepositoryLocationException e) {
       // LogService.getRoot().warning("Malformed repository location: " + e);
       LogService.getRoot()
           .log(
               Level.WARNING,
               I18N.getMessage(
                   LogService.getRoot().getResourceBundle(),
                   "com.rapidminer.repository.gui.RepositoryLocationChooser.malformed_repository_location",
                   e),
               e);
       return false;
     }
   }
 }
 private void updateResult() {
   try {
     String repositoryLocation = getRepositoryLocation();
     resultLabel.setText(repositoryLocation);
   } catch (MalformedRepositoryLocationException e) {
     // LogService.getRoot().log(Level.WARNING, "Malformed location: " + e, e);
     LogService.getRoot()
         .log(
             Level.WARNING,
             I18N.getMessage(
                 LogService.getRoot().getResourceBundle(),
                 "com.rapidminer.repository.gui.RepositoryLocationChooser.malformed_location",
                 e),
             e);
   }
   if ((currentEntry instanceof Folder)
       && !enforceValidRepositoryEntryName
       && locationField.getText().isEmpty()) {
     this.folderSelected = true;
   }
   if ((currentEntry instanceof Folder)
       && enforceValidRepositoryEntryName
       && locationFieldRepositoryEntry.getText().isEmpty()) {
     this.folderSelected = true;
   } else {
     this.folderSelected = false;
   }
   for (ChangeListener l : listeners) {
     l.stateChanged(new ChangeEvent(this));
   }
 }
  /**
   * Generates all new attributes and updates the ExampleTable. Returns a list of Attributes for the
   * newly generated attributes.
   *
   * @param exampleTable the source example table
   * @param generatorList List of FeatureGenerators
   * @return A list of Attributes
   */
  public static List<Attribute> generateAll(
      ExampleTable exampleTable, Collection<FeatureGenerator> generatorList)
      throws GenerationException {
    // LogService.getGlobal().log("Starting feature generation with " + generatorList.size() + "
    // generators.", LogService.STATUS);
    LogService.getRoot()
        .log(
            Level.FINE,
            "com.rapidminer.generator.FeatureGenerator.starting_feature_generation",
            generatorList.size());

    Iterator<FeatureGenerator> gi = generatorList.iterator();
    while (gi.hasNext()) gi.next().setExampleTable(exampleTable);

    // for performance reasons convert the list to an array
    FeatureGenerator[] generators = new FeatureGenerator[generatorList.size()];
    generatorList.toArray(generators);

    List<Attribute> newAttributeList = newAttributes(generators, exampleTable);
    // add the attributes to the example table and ensure length of the
    // DataRows
    exampleTable.addAttributes(newAttributeList);
    // LogService.getGlobal().log("Generator list: " + generatorList, LogService.STATUS);
    LogService.getRoot()
        .log(Level.FINE, "com.rapidminer.generator.FeatureGenerator.generator_list", generatorList);
    // LogService.getGlobal().log("Input set has " + exampleTable.getAttributeCount() + " features,
    // " + exampleTable.size() + " examples.", LogService.STATUS);
    LogService.getRoot()
        .log(
            Level.FINE,
            "com.rapidminer.generator.FeatureGenerator.input_has_feature_count_and_example_count",
            new Object[] {exampleTable.getAttributeCount(), exampleTable.size()});

    // generate the attribute values:
    DataRowReader reader = exampleTable.getDataRowReader();
    while (reader.hasNext()) {
      DataRow dataRow = reader.next();

      for (int j = 0; j < generators.length; j++) {
        generators[j].generate(dataRow);
      }
    }

    // LogService.getGlobal().log("Finished feature generation.", LogService.STATUS);
    LogService.getRoot()
        .log(Level.FINE, "com.rapidminer.generator.FeatureGenerator.finished_feature_generation");
    // LogService.getGlobal().log("Generated set has " + exampleTable.getAttributeCount() + "
    // features, " + exampleTable.size() + " examples.", LogService.STATUS);
    LogService.getRoot()
        .log(
            Level.FINE,
            "com.rapidminer.generator.FeatureGenerator.generated_set_has_feature_count_and_example_count",
            new Object[] {exampleTable.getAttributeCount(), exampleTable.size()});

    return newAttributeList;
  }
  /**
   * Enqueues this task and waits for its completion. If you call this method, you probably want to
   * set the runInForeground flag in the constructor to true.
   *
   * <p>Be careful when using this method for {@link ProgressThread}s with dependencies, this call
   * might block for a long time.
   */
  public void startAndWait() {
    // set flag indicating we are a busy waiting task - these are not started automatically by
    // #checkQueueForDependenciesAndExecuteUnblockedTasks()
    isWaiting = true;
    try {
      // no dependency -> start immediately
      if (dependencies.isEmpty()) {
        EXECUTOR.submit(makeWrapper()).get();
      } else {
        synchronized (LOCK) {
          queuedThreads.add(this);
        }
        taskQueued(this);
        // because this method waits, we can't just queue and leave. Instead we check on a
        // regular basis and see if it can be executed now.
        do {
          boolean blocked = true;
          synchronized (LOCK) {
            blocked = isBlockedByDependencies();
          }
          if (!blocked) {
            // no longer blocked? Execute and wait and afterwards leave loop
            synchronized (LOCK) {
              queuedThreads.remove(this);
            }
            EXECUTOR.submit(makeWrapper()).get();
            break;
          }
          Thread.sleep(BUSY_WAITING_INTERVAL);
        } while (true);
      }
    } catch (InterruptedException e) {
      LogService.getRoot()
          .log(
              Level.SEVERE,
              I18N.getMessage(
                  LogService.getRoot().getResourceBundle(),
                  "com.rapidminer.gui.tools.ProgressThread.executing_error",
                  name),
              e);

    } catch (ExecutionException e) {
      LogService.getRoot()
          .log(
              Level.SEVERE,
              I18N.getMessage(
                  LogService.getRoot().getResourceBundle(),
                  "com.rapidminer.gui.tools.ProgressThread.executing_error",
                  name),
              e);
    }
  }
  public void locateExpandedEntries() {

    for (String absoluteLocation : expandedNodes) {
      try {
        RepositoryLocation repositoryLocation = new RepositoryLocation(absoluteLocation);
        repositoryLocation.locateEntry();
      } catch (MalformedRepositoryLocationException e) {
        LogService.getRoot().warning("Unable to expand the location:" + absoluteLocation);
        e.printStackTrace();
      } catch (RepositoryException e) {
        LogService.getRoot().warning("Unable to expand the location:" + absoluteLocation);
        e.printStackTrace();
      }
    }
  }
 public void setLevel(Level level) {
   LogService.getRoot().setLevel(level);
   handler.setLevel(level);
   ParameterService.setParameterValue(
       MainFrame.PROPERTY_RAPIDMINER_GUI_LOG_LEVEL, level.getName());
   ParameterService.saveParameters();
 }
 private void delete() {
   Object[] selection = templateList.getSelectedValues();
   for (int i = 0; i < selection.length; i++) {
     String name = (String) selection[i];
     Template template = templateMap.remove(name);
     File templateFile = template.getFile();
     File expFile = new File(templateFile.getParent(), template.getFilename());
     boolean deleteResult = templateFile.delete();
     if (!deleteResult)
       LogService.getGlobal().logWarning("Unable to delete template file: " + templateFile);
     deleteResult = expFile.delete();
     if (!deleteResult)
       LogService.getGlobal().logWarning("Unable to delete template experiment file: " + expFile);
   }
   update();
 }
 /** Creates a new FeatureGenerator for a given function name. */
 public static FeatureGenerator createGeneratorForFunction(String functionName) {
   if (functionName == null) return null;
   Class genClass = generatorMap.get(functionName);
   if (genClass == null) {
     if (functionName.startsWith(ConstantGenerator.FUNCTION_NAME)) {
       FeatureGenerator gen = new ConstantGenerator();
       gen.setFunction(functionName);
       return gen;
     } else {
       return null;
     }
   } else {
     try {
       FeatureGenerator gen = (FeatureGenerator) genClass.newInstance();
       gen.setFunction(functionName);
       return gen;
     } catch (Exception e) {
       // LogService.getGlobal().log("Cannot instantiate '" + genClass.getName() + "'",
       // LogService.ERROR);
       LogService.getRoot()
           .log(
               Level.SEVERE,
               "com.rapidminer.generator.FeatureGenerator.instantiating_error",
               genClass.getName());
       return null;
     }
   }
 }
  /** Returns a list of new Attributes that are generated by the given generators. */
  private static List<Attribute> newAttributes(
      FeatureGenerator[] generators, ExampleTable exampleTable) {
    List<Attribute> newAttributeList = new LinkedList<Attribute>();

    // add the attributes to the example table
    for (int i = 0; i < generators.length; i++) {
      Attribute outputAttribute[] = generators[i].getOutputAttributes(exampleTable);
      generators[i].resultAttributes = new Attribute[outputAttribute.length];

      for (int j = 0; j < outputAttribute.length; j++) {
        newAttributeList.add(outputAttribute[j]);
        generators[i].resultAttributes[j] = outputAttribute[j];
      }

      // check the arguments
      if (!generators[i].argumentsSet()) {
        throw new RuntimeException(
            "Catastrophic error: arguments not set for " + generators[i] + "!");
      }
      if (!generators[i].argumentsOk(exampleTable)) {
        // LogService.getGlobal().log("Wrong argument types for " + generators[i] + ".",
        // LogService.WARNING);
        LogService.getRoot()
            .log(
                Level.WARNING,
                "com.rapidminer.generator.FeatureGenerator.wrong_argument_types",
                generators[i]);
      }
    }
    return newAttributeList;
  }
 public void setText(String text) {
   try {
     remove(0, getLength());
     insertString(0, text, null);
   } catch (BadLocationException e) {
     LogService.getRoot()
         .log(Level.WARNING, RegexpPropertyDialog.class.getName() + ".bad_location", e);
   }
 }
  /**
   * Checks whether the given domain belongs to an unsigned extension or not.
   *
   * @param domain the domain in question, never {@code null}
   * @return {@code true} if the domain belongs to an unsigned extension; {@code false} otherwise
   */
  private static boolean isUnsignedPlugin(ProtectionDomain domain) {
    // everything not loaded by the plugin classloader is no plugin
    if (!(domain.getClassLoader() instanceof PluginClassLoader)) {
      return false;
    }

    // if the public key could not be initialized, we treat all plugins as unsafe
    if (key == null) {
      return true;
    }

    // some sanity checks
    if (domain.getCodeSource() == null) {
      return true;
    }
    // special case for SNAPSHOT version: grant all permissions for all extensions
    // unless security is enforced via system property
    if (RapidMiner.getVersion().isSnapshot() && !isSecurityEnforced()) {
      return false;
    }
    if (domain.getCodeSource().getCertificates() == null) {
      // if no certificate: unsigned permissions only
      return true;
    }

    try {
      verifyCertificates(domain.getCodeSource().getCertificates());
      // signed by us, we are good at this point as we found a valid certificate
      return false;
    } catch (GeneralSecurityException e) {
      // invalid certificate
      LogService.getRoot()
          .log(Level.WARNING, "Invalid certificate for " + domain.getCodeSource().getLocation());
      return true;
    } catch (Exception e) {
      // some other error during certificate verification
      LogService.getRoot()
          .log(
              Level.WARNING,
              "Error verifying certificate for " + domain.getCodeSource().getLocation(),
              e);
      return true;
    }
  }
 @Override
 public Object getChild(Object parent, int index) {
   if (parent instanceof RepositoryManager) {
     if (onlyWriteableRepositories) {
       return getWritableRepositories(((RepositoryManager) parent)).get(index);
     }
     return ((RepositoryManager) parent).getRepositories().get(index);
   } else if (parent instanceof Folder) {
     Folder folder = (Folder) parent;
     if (folder.willBlock()) {
       unblock(folder);
       return "Pending...";
     } else {
       try {
         int numFolders = folder.getSubfolders().size();
         if (index < numFolders) {
           return folder.getSubfolders().get(index);
         } else if (onlyFolders) {
           return null;
         } else {
           return folder.getDataEntries().get(index - numFolders);
         }
       } catch (RepositoryException e) {
         // LogService.getRoot().log(Level.WARNING, "Cannot get children of "+folder.getName()+":
         // "+e, e);
         LogService.getRoot()
             .log(
                 Level.WARNING,
                 I18N.getMessage(
                     LogService.getRoot().getResourceBundle(),
                     "com.rapidminer.repository.gui.RepositoryTreeModel.getting_children_of_folder_error",
                     folder.getName(),
                     e),
                 e);
         return null;
       }
     }
   } else {
     return null;
   }
 }
Exemplo n.º 14
0
 /** Sets the name of the main average (must be added by {@link #addAveragable(Averagable)}) */
 public void setMainCriterionName(String mcName) {
   if ((!mcName.equals(MAIN_CRITERION_FIRST)) && (getAveragable(mcName) == null)) {
     // LogService.getGlobal().log("Main criterion not found: '" + mcName + "'.",
     // LogService.ERROR);
     LogService.getRoot()
         .log(
             Level.SEVERE,
             "com.rapidminer.operator.performance.PerformanceVector.main_criterion_not_found",
             mcName);
   }
   this.mainCriterion = mcName;
 }
 public static void init() {
   File connectionsFile = getOldConnectionsFile();
   File xmlConnectionsFile = getXMLConnectionsFile();
   if (!xmlConnectionsFile.exists() && !connectionsFile.exists()) {
     // both files do not exist, create the new xml format file
     try {
       xmlConnectionsFile.createNewFile();
       writeXMLConnectionsEntries(getConnectionEntries(), xmlConnectionsFile);
     } catch (IOException ex) {
       // do nothing
     }
   } else if (!xmlConnectionsFile.exists() && connectionsFile.exists()) {
     // only the old text format exists, read it and save as new xml format so next time only the
     // new xml format exists
     connections = readConnectionEntries(connectionsFile);
     writeXMLConnectionsEntries(getConnectionEntries(), xmlConnectionsFile);
     connectionsFile.delete();
   } else {
     try {
       if (!"".equals(Tools.readTextFile(xmlConnectionsFile))) {
         Document document = XMLTools.parse(xmlConnectionsFile);
         Element jdbcElement = document.getDocumentElement();
         connections = new LinkedList<FieldConnectionEntry>(parseEntries(jdbcElement));
       }
     } catch (Exception e) {
       // LogService.getRoot().log(Level.WARNING, "Failed to read database connections file: "+e,
       // e);
       LogService.getRoot()
           .log(
               Level.WARNING,
               I18N.getMessage(
                   LogService.getRoot().getResourceBundle(),
                   "com.rapidminer.tools.jdbc.connection.DatabaseConnectionService.reading_database_error",
                   e),
               e);
     }
   }
 }
  private LoggingViewer(JTextPane textArea) {
    super(new BorderLayout());
    final Level level = getSpecifiedLogLevelIndex();
    handler.setLevel(level);
    LogService.getRoot().setLevel(level);
    maxRows = 1000;
    try {
      String maxRowsString =
          ParameterService.getParameterValue(
              MainFrame.PROPERTY_RAPIDMINER_GUI_MESSAGEVIEWER_ROWLIMIT);
      if (maxRowsString != null) maxRows = Integer.parseInt(maxRowsString);
    } catch (NumberFormatException e) {
      // LogService.getGlobal().log("Bad integer format for property '', using default number of
      // maximum rows for logging (1000).", LogService.WARNING);
      LogService.getRoot()
          .log(
              Level.WARNING,
              "com.rapidminer.gui.tools.LoggingViewer.bad_integer_format_for_property");
    }

    this.textArea = textArea;
    this.textArea.setToolTipText(
        "Displays logging messages according to the current log verbosity (parameter of root operator).");
    this.textArea.setEditable(false);
    this.textArea.addMouseListener(this);
    this.textArea.setFont(this.textArea.getFont().deriveFont(Font.PLAIN));
    LogService.getRoot().addHandler(handler);

    JToolBar toolBar = new ExtendedJToolBar();
    toolBar.setBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, Color.LIGHT_GRAY));
    toolBar.add(SAVE_LOGFILE_ACTION);
    toolBar.add(CLEAR_MESSAGE_VIEWER_ACTION);
    toolBar.add(SEARCH_ACTION);
    add(toolBar, BorderLayout.NORTH);
    JScrollPane scrollPane = new ExtendedJScrollPane(textArea);
    scrollPane.setBorder(null);
    add(scrollPane, BorderLayout.CENTER);
  }
Exemplo n.º 17
0
 public void addCriterion(PerformanceCriterion crit) {
   PerformanceCriterion pc = getCriterion(crit.getName());
   if (pc != null) {
     removeAveragable(pc);
     // LogService.getGlobal().log("Performance criterion '" + crit.getName() + "' was already part
     // of performance vector. Overwritten...", LogService.WARNING);
     LogService.getRoot()
         .log(
             Level.WARNING,
             "com.rapidminer.operator.performance.PerformanceVector.performance_criterion_already_part_of_performance_vector",
             crit.getName());
   }
   addAveragable(crit);
 }
  public static void writeXMLConnectionsEntries(
      Collection<FieldConnectionEntry> connectionEntries, File connectionEntriesFile) {
    Key key;
    try {
      key = KeyGeneratorTool.getUserKey();
    } catch (IOException e) {
      // LogService.getRoot().log(Level.WARNING, "Cannot retrieve key, probably no one was created:
      // "+e, e);
      LogService.getRoot()
          .log(
              Level.WARNING,
              I18N.getMessage(
                  LogService.getRoot().getResourceBundle(),
                  "com.rapidminer.tools.jdbc.connection.DatabaseConnectionService.retrieving_key_error",
                  e),
              e);
      return;
    }

    try {
      XMLTools.stream(
          toXML(connectionEntries, key, null, false),
          connectionEntriesFile,
          Charset.forName("UTF-8"));
    } catch (Exception e) {
      // LogService.getRoot().log(Level.WARNING, "Failed to write database connections file: "+e,
      // e);
      LogService.getRoot()
          .log(
              Level.WARNING,
              I18N.getMessage(
                  LogService.getRoot().getResourceBundle(),
                  "com.rapidminer.tools.jdbc.connection.DatabaseConnectionService.writing_database_connection_error",
                  e),
              e);
    }
  }
  /** @return the text for the beta eula */
  private String loadBetaEULA() {
    String eulaText = null;
    // read EULA text
    try (InputStream inputStream = Tools.getResourceInputStream(BETA_EULA)) {
      eulaText = Tools.readTextFile(inputStream);
    } catch (IOException | RepositoryException e2) {
      // loading the EULA failed (this should never happen)
      LogService.getRoot()
          .log(
              Level.SEVERE,
              "com.rapidminer.gui.properties.BetaFeaturesListener.cannot_open_beta_eula");
    }

    return eulaText;
  }
  public void addTabI18N(String key, Component component, String... i18nArgs) {
    String name;
    if (i18nArgs != null && i18nArgs.length > 0) {
      name = formatMessage(key, "label", i18nArgs);
    } else {
      name = getMessage(key, "label");
    }
    Icon icon = null;
    String iconName = getMessageOrNull(key, "icon");
    if (iconName != null) {
      icon = SwingTools.createIcon((isLargeIcons() ? "24/" : "16/") + iconName);
    }
    addTab(name, icon, component);
    int index = getTabCount() - 1;

    String tip;
    if (i18nArgs != null && i18nArgs.length > 0) {
      tip = formatMessage(key, "tip", i18nArgs);
    } else {
      tip = getMessageOrNull(key, "tip");
    }
    if (tip != null) {
      setToolTipTextAt(index, tip);
    }

    // try to look up and set mnemonic
    String mne = getMessageOrNull(key, "mne");
    if (mne != null) {
      mne = mne.toUpperCase();
      if (name.indexOf(mne.charAt(0)) == -1) {
        if (name.indexOf(mne.toUpperCase().charAt(0)) != -1) {
          mne = mne.toUpperCase();
          LogService.getRoot()
              .warning(
                  "Mnemonic key "
                      + mne
                      + " not found for tab "
                      + i18KeyPrefix
                      + "."
                      + key
                      + " ("
                      + name
                      + "), converting to upper case.");
        }
      }
      setMnemonicAt(index, mne.charAt(0));
    }
  }
 private static void initFormatDelegate(
     ValueSource valueSource, FormattedRenderer formattedRenderer, PlotInstance plotInstance) {
   ValueSourceData valueSourceData = plotInstance.getPlotData().getValueSourceData(valueSource);
   List<Integer> seriesIndices = new LinkedList<Integer>();
   if (valueSourceData != null) {
     for (int i = 0; i < valueSourceData.getSeriesCount(); ++i) {
       seriesIndices.add(i);
     }
   } else {
     LogService.getRoot()
         .log(
             Level.WARNING,
             "com.rapidminer.gui.new_plotter.engine.jfreechart.ChartRendererFactory.null_value_source");
   }
   initFormatDelegate(valueSource, seriesIndices, formattedRenderer, plotInstance);
 }
 @Override
 public void setFunction(String name) {
   for (int i = 0; i < FUNCTION_NAMES.length; i++) {
     if (FUNCTION_NAMES[i].equals(name)) {
       this.mode = i;
       return;
     }
   }
   // LogService.getGlobal().log("Illegal function name '" + name + "' for " + getClass().getName()
   // + ".", LogService.ERROR);
   LogService.getRoot()
       .log(
           Level.SEVERE,
           "com.rapidminer.generator.FloorCeilGenerator.illegal_function_name",
           new Object[] {name, getClass().getName()});
 }
    private void checkDocument() {

      setCharacterAttributes(0, getLength(), rootStyle, true);
      try {
        matcher.reset(getText(0, getLength()));
        int count = 0;
        resultsListModel.clear();
        while (matcher.find()) {
          if (matcher.end() <= matcher.start()) {
            continue;
          }
          setCharacterAttributes(matcher.start(), matcher.end() - matcher.start(), keyStyle, true);

          String[] groups = new String[matcher.groupCount()];
          for (int i = 1; i <= matcher.groupCount(); i++) {
            groups[i - 1] = matcher.group(i);
          }
          resultsListModel.addElement(
              new RegExpResult(
                  this.getText(matcher.start(), matcher.end() - matcher.start()),
                  groups,
                  count + 1));
          count++;
        }

        if (count == 0) {
          // add empty element
          resultsListModel.addElement(new RegExpResult());
        }

        testExp.setTitleAt(
            1,
            I18N.getMessage(
                    I18N.getGUIBundle(),
                    "gui.dialog.parameter.regexp.regular_expression.result_list.title")
                + " ("
                + count
                + ")");
        inlineReplaceDocument.setText(matcher.replaceAll(replacementTextField.getText()));
        updateRegexpOptions();
      } catch (BadLocationException ex) {
        LogService.getRoot()
            .log(Level.WARNING, RegexpPropertyDialog.class.getName() + ".bad_location", ex);
      }
    }
Exemplo n.º 24
0
 public double getStatistics(Attribute attribute, String name, String parameter) {
   if (AVERAGE.equals(name)) {
     return this.sum / this.valueCounter;
   } else if (VARIANCE.equals(name)) {
     if (valueCounter <= 1) {
       return 0;
     }
     double variance = (squaredSum - (sum * sum) / valueCounter) / (valueCounter - 1);
     if (variance < 0) // this is due to rounding errors above
     return 0;
     return variance;
   } else if (SUM.equals(name)) {
     return this.sum;
   } else {
     LogService.getGlobal()
         .log("Cannot calculate statistics, unknown type: " + name, LogService.WARNING);
     return Double.NaN;
   }
 }
 public static Color string2Color(String colorString) {
   try {
     return Color.decode(colorString);
   } catch (Exception e) {
     String[] colors = colorString.split(",");
     if (colors.length == 3) {
       return new Color(
           Integer.parseInt(colors[0]), Integer.parseInt(colors[1]), Integer.parseInt(colors[2]));
     } else {
       // LogService.getRoot().warning("Cannot parse color: "+colorString);
       LogService.getRoot()
           .log(
               Level.WARNING,
               "com.rapidminer.parameter.ParameterTypeColor.parsing_color_error",
               colorString);
       return Color.BLACK;
     }
   }
 }
 public Attribute getRegular(String name) {
   AttributeRole role = findRoleByName(name);
   if (role != null) {
     if (!role.isSpecial()) {
       return role.getAttribute();
     } else {
       // LogService.getGlobal().logWarning("No regular attribute with name '"+name+"' found,
       // however, there is a special attribute with the same name.");
       LogService.getRoot()
           .log(
               Level.WARNING,
               "com.rapidminer.example.AbstractAttributes.no_regular_attribute_found",
               name);
       return null;
     }
   } else {
     return null;
   }
   // return findAttribute(name, iterator());
 }
 protected void parseCondition(Element childElem) {
   NodeList conditionNodes = childElem.getChildNodes();
   for (int j = 0; j < conditionNodes.getLength(); j++) {
     Node conditionNode = conditionNodes.item(j);
     if (conditionNode instanceof Element) {
       Element conditionElem = (Element) conditionNode;
       if (conditionElem.getTagName().equals("parameter_equals")) {
         conditions.add(new ParameterEqualsCondition((Element) conditionNode));
       } else if (conditionElem.getTagName().equals("parameter_unequals")) {
         conditions.add(new ParameterUnequalsCondition((Element) conditionNode));
       } else {
         // LogService.getRoot().warning("Unknown condition: "+conditionElem.getTagName());
         LogService.getRoot()
             .log(
                 Level.WARNING,
                 "com.rapidminer.io.process.rules.AbstractConditionedParseRule.unknown_condition",
                 conditionElem.getTagName());
       }
     }
   }
 }
  /**
   * Adds a new attribute to this example table by invoking the super method. If the number of
   * attributes reaches a threshold, the number of attributes is increased by INCREMENT attributes.
   * This avoids a large number of array copies in cases like automatic feature construction etc.
   */
  @Override
  public synchronized int addAttribute(Attribute attribute) {
    int index = super.addAttribute(attribute);
    if (dataList == null) return index;
    int n = getNumberOfAttributes();
    if (n <= columns) return index;
    int newSize = n + INCREMENT;
    // LogService.getGlobal().log("Resizing example table from " + columns + " to " + newSize + "
    // columns.", LogService.STATUS);
    LogService.getRoot()
        .log(
            Level.FINE,
            "com.rapidminer.example.table.MemoryExampleTable.rezising_example_table",
            new Object[] {columns, newSize});
    columns = newSize;

    if (dataList != null) {
      Iterator<DataRow> i = dataList.iterator();
      while (i.hasNext()) i.next().ensureNumberOfColumns(columns);
    }
    return index;
  }
 public ExecutionUnit(OperatorChain enclosingOperator, String name) {
   this.name = name;
   this.enclosingOperator = enclosingOperator;
   innerInputPorts.addObserver(delegatingPortObserver, false);
   innerOutputPorts.addObserver(delegatingPortObserver, false);
   // innerInputPorts.addObserver(portObserver, false);
   // innerOutputPorts.addObserver(portObserver, false);
   int index = 0;
   do {
     char c = name.charAt(index);
     if (!(Character.isUpperCase(c) || Character.isDigit(c))) {
       // LogService.getRoot().warning("Process name does not follow naming conventions: "+name+"
       // (in "+enclosingOperator.getOperatorDescription().getName()+")");
       LogService.getRoot()
           .log(
               Level.WARNING,
               "com.rapidminer.operator.ExecutionUnit.process_name_does_not_follow_name_conventions",
               new Object[] {name, enclosingOperator.getOperatorDescription().getName()});
     }
     index = name.indexOf(' ', index) + 1;
   } while (index != 0);
 }
  /**
   * Saves the content of the comment editor as the new comment for the given {@link
   * WorkflowAnnotation}.
   *
   * @param selected the annotation for which the content of the editor pane should be saved as new
   *     comment
   */
  private void saveEdit(final WorkflowAnnotation selected) {
    if (editPane == null) {
      return;
    }
    HTMLDocument document = (HTMLDocument) editPane.getDocument();
    StringWriter writer = new StringWriter();
    try {
      editPane.getEditorKit().write(writer, document, 0, document.getLength());
    } catch (IndexOutOfBoundsException | IOException | BadLocationException e1) {
      // should not happen
      LogService.getRoot()
          .log(
              Level.WARNING,
              "com.rapidminer.gui.flow.processrendering.annotations.AnnotationsDecorator.cannot_save");
    }
    String comment = writer.toString();
    comment = AnnotationDrawUtils.removeStyleFromComment(comment);
    Rectangle2D loc = selected.getLocation();
    Rectangle2D newLoc =
        new Rectangle2D.Double(
            loc.getX(),
            loc.getY(),
            editPane.getBounds().getWidth(),
            editPane.getBounds().getHeight());
    selected.setLocation(newLoc);

    boolean overflowing = false;
    int prefHeight =
        AnnotationDrawUtils.getContentHeight(
            AnnotationDrawUtils.createStyledCommentString(comment, selected.getStyle()),
            (int) newLoc.getWidth());
    if (prefHeight > newLoc.getHeight()) {
      overflowing = true;
    }
    selected.setOverflowing(overflowing);

    model.setAnnotationComment(selected, comment);
  }