com.igormaznitsa.meta.annotation.MustNotContainNull Java Examples

The following examples show how to use com.igormaznitsa.meta.annotation.MustNotContainNull. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PackageList.java    From mvn-golang with Apache License 2.0 6 votes vote down vote up
public PackageList(@Nonnull @MustNotContainNull final File file, @Nonnull final String text, @Nonnull final ContentProvider contentProvider) throws ParseException, IOException {
  final List<Package> list = new ArrayList<>();

  for (final String s : text.split("\\n")) {
    final String trimmed = s.trim();

    if (!trimmed.isEmpty() && !trimmed.startsWith("//")) {
      if (trimmed.startsWith(DIRECTIVE_INCLUDE)) {
        final String filePath = removeQuotes(removeComment(trimmed.substring(DIRECTIVE_INCLUDE.length()).trim(), true));

        final File includeFile = new File(file, filePath);

        final String includedText = contentProvider.readContent(includeFile);
        list.addAll(new PackageList(includeFile, includedText, contentProvider).getPackages());
      } else {
        list.add(new Package(trimmed));
      }
    }
  }

  this.packages = Collections.unmodifiableList(list);
}
 
Example #2
Source File: NodeProject.java    From netbeans-mmd-plugin with Apache License 2.0 6 votes vote down vote up
@Nonnull
@MustNotContainNull
public List<File> deleteAllLinksToFile(@Nonnull @MustNotContainNull final List<File> listOfFilesToProcess, @Nonnull final File fileToRemove) {
  final List<File> affectedFiles = new ArrayList<>();

  final File baseFolder = makeFileForNode();
  final MMapURI fileURI = new MMapURI(baseFolder, fileToRemove, null);

  listOfFilesToProcess.stream().filter((file) -> (file.isFile())).forEachOrdered((file) -> {
    try {
      final MindMap map = new MindMap(new StringReader(FileUtils.readFileToString(file, "UTF-8"))); //NOI18N
      if (map.deleteAllLinksToFile(baseFolder, fileURI)) {
        SystemUtils.saveUTFText(file, map.packToString());
        affectedFiles.add(file);
      }
    } catch (IOException ex) {
      LOGGER.error("Can't process mind map file", ex); //NOI18N
    }
  });

  return affectedFiles;
}
 
Example #3
Source File: MindMapDocumentEditor.java    From netbeans-mmd-plugin with Apache License 2.0 6 votes vote down vote up
@Override
public boolean allowedRemovingOfTopics(@Nonnull final MindMapPanel mindMapPanel, @Nonnull @MustNotContainNull final Topic[] topics) {
  boolean topicsNotImportant = true;

  for (final Topic t : topics) {
    topicsNotImportant &= this.panelController.canTopicBeDeleted(this.mindMapPanel, t);
    if (!topicsNotImportant) {
      break;
    }
  }

  final boolean result;

  if (topicsNotImportant) {
    result = true;
  } else {
    result = this.getDialogProvider().msgConfirmYesNo(null, BUNDLE.getString("MMDGraphEditor.allowedRemovingOfTopics,title"),
        String.format(BUNDLE.getString("MMDGraphEditor.allowedRemovingOfTopics.message"), topics.length));
  }
  return result;
}
 
Example #4
Source File: GolangTestMojo.java    From mvn-golang with Apache License 2.0 6 votes vote down vote up
@Override
@Nullable
@MustNotContainNull
protected String[] getDefaultPackages() {
  final String definedTest = System.getProperty("test");
  if (definedTest != null) {
    final int index = definedTest.indexOf('#');
    final String[] name;
    if (index >= 0) {
      name = new String[]{definedTest.substring(0, index), definedTest.substring(index + 1)};
    } else {
      name = new String[]{definedTest};
    }
    final List<String> result = new ArrayList<>();
    result.add(ensureGoExtension(name[0]));
    if (definedTest.length() > 1) {
      result.add("-run");
      result.add(name[1]);
    }
    return result.toArray(new String[0]);
  } else {
    return new String[]{'.' + File.separator + "..."};
  }
}
 
Example #5
Source File: Topic.java    From netbeans-mmd-plugin with Apache License 2.0 6 votes vote down vote up
public boolean removeExtraFromSubtree(@Nonnull @MustNotContainNull final Extra.ExtraType... type) {
  boolean result = false;

  this.map.lock();
  try {
    for (final Extra.ExtraType t : type) {
      result |= this.extras.remove(t) != null;
    }
    for (final Topic c : this.children) {
      result |= c.removeExtraFromSubtree(type);
    }
    return result;
  } finally {
    this.map.unlock();
  }
}
 
Example #6
Source File: NodeFileOrFolder.java    From netbeans-mmd-plugin with Apache License 2.0 6 votes vote down vote up
void fireNotifySubtreeChanged(@Nonnull TreeModel model, @Nonnull @MustNotContainNull final List<TreeModelListener> listeners) {
  if (this.parent != null && this.folderFlag) {
    final Object[] childrenObject = new Object[children.size()];
    final int[] indexes = new int[children.size()];
    for (int i = 0; i < this.children.size(); i++) {
      final NodeFileOrFolder c = this.children.get(i);
      childrenObject[i] = c;
      indexes[i] = i;
      c.fireNotifySubtreeChanged(model, listeners);
    }
    final TreeModelEvent event = new TreeModelEvent(model, this.parent.makeTreePath(), indexes, childrenObject);
    for (final TreeModelListener l : listeners) {
      l.treeStructureChanged(event);
    }
  }
}
 
Example #7
Source File: MindMapPluginRegistry.java    From netbeans-mmd-plugin with Apache License 2.0 6 votes vote down vote up
@Nonnull
@MustNotContainNull
public <T extends MindMapPlugin> List<T> findFor(@Nullable final Class<T> klazz) {
  synchronized (FIND_CACHE) {
    List<T> result = (List<T>) FIND_CACHE.get(klazz);

    if (result == null) {
      result = new ArrayList<T>();
      if (klazz != null) {
        for (final MindMapPlugin p : this.pluginList) {
          if (klazz.isInstance(p)) {
            result.add(klazz.cast(p));
          }
        }
      }
      result = Collections.unmodifiableList(result);
      FIND_CACHE.put(klazz, result);
    }
    return result;
  }
}
 
Example #8
Source File: CoggleMM2MindMapImporter.java    From netbeans-mmd-plugin with Apache License 2.0 6 votes vote down vote up
@Nonnull
@MustNotContainNull
private List<String> extractImageURLs(@Nonnull final String mdText, @Nonnull final StringBuilder resultText) {
  final List<String> result = new ArrayList<String>();
  final Matcher matcher = MD_IMAGE_LINK.matcher(mdText);
  int lastFoundEnd = 0;
  while (matcher.find()) {
    final String text = matcher.group(1);
    result.add(matcher.group(2));
    resultText.append(mdText, lastFoundEnd, matcher.start()).append(text);
    lastFoundEnd = matcher.end();
  }

  if (lastFoundEnd < mdText.length()) {
    resultText.append(mdText, lastFoundEnd, mdText.length());
  }

  return result;
}
 
Example #9
Source File: Topic.java    From netbeans-mmd-plugin with Apache License 2.0 6 votes vote down vote up
public boolean removeAttributeFromSubtree(@Nonnull @MustNotContainNull final String... names) {
  boolean result = false;

  this.map.lock();
  try {
    for (final String t : names) {
      result |= this.attributes.remove(t) != null;
    }
    for (final Topic c : this.children) {
      result |= c.removeAttributeFromSubtree(names);
    }
    return result;
  } finally {
    this.map.unlock();
  }
}
 
Example #10
Source File: PluginClassLoader.java    From netbeans-mmd-plugin with Apache License 2.0 6 votes vote down vote up
@Nonnull
@MustNotContainNull
public String[] extractPluginClassNames() {
  final String classNameList = this.getAttributes(Attribute.PLUGINS);
  String[] result;
  if (classNameList == null) {
    result = new String[0];
  } else {
    final String[] splitted = classNameList.split("\\,");
    result = new String[splitted.length];
    for (int i = 0; i < splitted.length; i++) {
      final String str = splitted[i].trim();
      if (SourceVersion.isName(str)) {
        result[i] = str;
      } else {
        LOGGER.error("Detected illegal plugin class name " + str + " at " + this.pluginFile);
      }
    }
  }
  return result;
}
 
Example #11
Source File: ColorChooser.java    From netbeans-mmd-plugin with Apache License 2.0 6 votes vote down vote up
@Nonnull
@MustNotContainNull
private static List<Color> makeSteps(@Nonnull final Color start, @Nonnull final Color end, final int steps) {
  float sr = start.getRed();
  float sg = start.getGreen();
  float sb = start.getBlue();

  final int GRADATIONS = steps + 2;

  float dr = (end.getRed() - sr) / GRADATIONS;
  float dg = (end.getGreen() - sg) / GRADATIONS;
  float db = (end.getBlue() - sb) / GRADATIONS;

  final List<Color> result = new ArrayList<>();

  for (int i = 0; i < GRADATIONS; i++) {
    if (i > 0 && i < (GRADATIONS - 1)) {
      result.add(new Color(Math.round(sr), Math.round(sg), Math.round(sb)));
    }
    sr += dr;
    sg += dg;
    sb += db;
  }

  return result;
}
 
Example #12
Source File: AbstractGolangMojo.java    From mvn-golang with Apache License 2.0 6 votes vote down vote up
protected void addTmpBuildFlagIfNotPresented(@Nonnull @MustNotContainNull final String... flags) {
  for (final String s : flags) {
    if (this.tempBuildFlags.contains(s)) {
      continue;
    }
    boolean found = false;
    if (this.buildFlags != null) {
      for (final String b : this.buildFlags) {
        if (s.equals(b)) {
          found = true;
          break;
        }
      }
    }
    if (!found) {
      this.tempBuildFlags.add(s);
    }
  }
}
 
Example #13
Source File: Main.java    From netbeans-mmd-plugin with Apache License 2.0 6 votes vote down vote up
@Nonnull
private static String makeMnemonicList(@Nonnull @MustNotContainNull final List<? extends MindMapPlugin> plugins) {
  final StringBuilder result = new StringBuilder();
  for (final MindMapPlugin p : plugins) {
    if (p instanceof HasMnemonic) {
      final String mnemo = ((HasMnemonic) p).getMnemonic();
      if (mnemo != null) {
        if (result.length() > 0) {
          result.append('|');
        }
        result.append(mnemo);
      }
    }
  }
  return result.toString();
}
 
Example #14
Source File: MindMapDialogProvider.java    From netbeans-mmd-plugin with Apache License 2.0 6 votes vote down vote up
@Nullable
@Override
public File msgOpenFileDialog(@Nullable final Component parentComponent,
        @Nonnull final String id,
        @Nonnull final String title,
        @Nullable final File defaultFolder,
        final boolean fileOnly,
        @Nullable @MustNotContainNull final FileFilter[] fileFilters,
        @Nonnull final String approveButtonText) {

  final JFileChooser fileChooser = new JFileChooser(defaultFolder == null ? cacheOpenFileThroughDialog.find(null, id) : defaultFolder);
  fileChooser.setDialogTitle(title);
  for (final FileFilter f : fileFilters) {
    fileChooser.addChoosableFileFilter(f);
  }
  fileChooser.setAcceptAllFileFilterUsed(true);
  fileChooser.setMultiSelectionEnabled(false);
  fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);

  if (fileChooser.showOpenDialog(WindowManager.getInstance().findVisibleFrame()) == JFileChooser.APPROVE_OPTION) {
    return cacheOpenFileThroughDialog.put(id, fileChooser.getSelectedFile());
  } else {
    return null;
  }
}
 
Example #15
Source File: SysFileExtensionEditorPanel.java    From netbeans-mmd-plugin with Apache License 2.0 6 votes vote down vote up
private static String prepareStringFromLines(@Nonnull @MustNotContainNull final String [] lines) {
  final StringBuilder builder = new StringBuilder();
  for (final String s : lines) {
    for (final String ext : s.split("\\,")) {
      final String trimmed = ext.toLowerCase(Locale.ENGLISH).trim();
      if (trimmed.isEmpty()) {
        continue;
      }
      if (builder.length() > 0) {
        builder.append(',');
      }
      builder.append(trimmed);
    }
  }
  return builder.toString();
}
 
Example #16
Source File: ColorPickerPanel.java    From netbeans-mmd-plugin with Apache License 2.0 6 votes vote down vote up
public ColorPickerPanel(
    @Nonnull final JPanel panel,
    final int rows,
    final int cols,
    final int gapHorz,
    final int gapVert,
    @Nullable @MustNotContainNull final List<Color> predefinedColors
) {
  this.panel = panel;
  this.panel.setOpaque(false);

  this.gapHorz = Math.max(0, gapHorz);
  this.gapVert = Math.max(0, gapVert);
  this.predefinedColors = predefinedColors;

  this.rows = Math.min(32, Math.max(1, rows));
  this.cols = Math.min(32, Math.max(1, cols));

  updateColorButtons(this.predefinedColors);
}
 
Example #17
Source File: TextAlignMenuPlugin.java    From netbeans-mmd-plugin with Apache License 2.0 5 votes vote down vote up
@Nullable
private TextAlign findSharedTextAlign(@Nonnull @MustNotContainNull final Topic[] topics) {
  TextAlign result = null;

  for (final Topic t : topics) {
    final TextAlign topicAlign = TextAlign.findForName(t.getAttribute("align"));
    if (result == null) {
      result = topicAlign;
    } else if (result != topicAlign) {
      return null;
    }
  }

  return result == null ? TextAlign.CENTER : result;
}
 
Example #18
Source File: AbstractGoDependencyAwareMojo.java    From mvn-golang with Apache License 2.0 5 votes vote down vote up
@Nonnull
@MustNotContainNull
private List<Tuple<GoMod, File>> listRightPart(@Nonnull @MustNotContainNull final List<Tuple<Artifact, Tuple<GoMod, File>>> list) {
  final List<Tuple<GoMod, File>> parsed = new ArrayList<>();
  for (final Tuple<Artifact, Tuple<GoMod, File>> i : list) {
    parsed.add(i.right());
  }
  return parsed;
}
 
Example #19
Source File: NodeFileOrFolder.java    From netbeans-mmd-plugin with Apache License 2.0 5 votes vote down vote up
@Nonnull
@MustNotContainNull
@ReturnsOriginal
public List<NodeFileOrFolder> findRelatedNodes(@Nonnull final File file, @Nonnull @MustNotContainNull final List<NodeFileOrFolder> list) {
  final File theFile = makeFileForNode();
  if (theFile != null) {
    if (file.equals(theFile) || theFile.toPath().startsWith(file.toPath())) {
      list.add(this);
      for (final NodeFileOrFolder f : this.children) {
        f.findRelatedNodes(file, list);
      }
    }
  }
  return list;
}
 
Example #20
Source File: FileHistoryManager.java    From netbeans-mmd-plugin with Apache License 2.0 5 votes vote down vote up
@Nonnull
private static String packToString(@Nonnull @MustNotContainNull final File[] files) {
  final StringBuilder result = new StringBuilder();
  for (final File f : files) {
    if (result.length() > 0) {
      result.append(File.pathSeparatorChar);
    }
    result.append(FilenameUtils.normalize(f.getAbsolutePath()));
  }
  return result.toString();
}
 
Example #21
Source File: MapUtils.java    From netbeans-mmd-plugin with Apache License 2.0 5 votes vote down vote up
@Nonnull
@MustNotContainNull
public static List<Topic> findTopicsRelatedToFile(@Nullable final File baseFolder, @Nonnull final File file, @Nonnull final MindMap map) {

  final List<Topic> result = new ArrayList<>();

  final Path theFile = file.isAbsolute() ? file.toPath() : new File(baseFolder, file.getAbsolutePath()).toPath();

  final boolean folder = file.isDirectory();

  for (final Topic t : map) {
    final ExtraFile linkToFile = (ExtraFile) t.getExtras().get(Extra.ExtraType.FILE);
    if (linkToFile != null) {
      final MMapURI uri = linkToFile.getAsURI();
      final Path linkFile = uri.asFile(baseFolder).toPath();
      if (folder) {
        if (linkFile.startsWith(theFile)) {
          result.add(t);
        }
      } else if (linkFile.equals(theFile)) {
        result.add(t);
      }
    }
  }

  return result;
}
 
Example #22
Source File: GolangMvnInstallMojo.java    From mvn-golang with Apache License 2.0 5 votes vote down vote up
private void safeCopyDirectory(@Nullable final String src, @Nonnull final File dst, @Nullable @MustNotContainNull final List<File> dstList) throws IOException {
  if (!(src == null || src.isEmpty())) {
    final File srcFile = new File(src);
    if (srcFile.isDirectory()) {
      if (getLog().isDebugEnabled()) {
        getLog().debug(String.format("Copying %s => %s", srcFile.getAbsolutePath(), dst.getAbsolutePath()));
      }
      FileUtils.copyDirectoryToDirectory(srcFile, dst);
      if (dstList != null) {
        dstList.add(new File(dst, srcFile.getName()));
      }
    }
  }
}
 
Example #23
Source File: MindMap.java    From netbeans-mmd-plugin with Apache License 2.0 5 votes vote down vote up
@Nonnull
@MustNotContainNull
public List<Topic> findAllTopicsForExtraType(@Nonnull final Extra.ExtraType type) {
  final List<Topic> result = new ArrayList<Topic>();
  final Topic rootTopic = this.root;
  if (rootTopic != null) {
    this.locker.lock();
    try {
      _findAllTopicsForExtraType(rootTopic, type, result);
    } finally {
      this.locker.unlock();
    }
  }
  return result;
}
 
Example #24
Source File: NodeProjectGroup.java    From netbeans-mmd-plugin with Apache License 2.0 5 votes vote down vote up
public void startProjectFolderRefresh(@Nonnull final NodeProject nodeProject, @Nullable @MustNotContainNull final Runnable... invokeLater) {
  final int index = this.getIndex(nodeProject);
  if (index >= 0) {
    Main.getApplicationFrame().asyncReloadProject(nodeProject, ArrayUtils.joinArrays(invokeLater, new Runnable[]{new Runnable() {
      @Override
      public void run() {
        nodeProject.fireNotifySubtreeChanged(NodeProjectGroup.this, listeners);
      }
    }}));
  }
}
 
Example #25
Source File: UiUtils.java    From netbeans-mmd-plugin with Apache License 2.0 5 votes vote down vote up
@Nullable
public static Color extractCommonColorForColorChooserButton(@Nonnull final String colorAttribute, @Nonnull @MustNotContainNull final Topic[] topics) {
  Color result = null;
  for (final Topic t : topics) {
    final Color color = html2color(t.getAttribute(colorAttribute), false);
    if (result == null) {
      result = color;
    } else if (!result.equals(color)) {
      return ColorChooserButton.DIFF_COLORS;
    }
  }
  return result;
}
 
Example #26
Source File: GolangGetMojo.java    From mvn-golang with Apache License 2.0 5 votes vote down vote up
@Override
@Nonnull
@MustNotContainNull
public String[] getPackages() {
  final String[] result = new String[this.integralPackageList.size()];
  for (int i = 0; i < this.integralPackageList.size(); i++) {
    result[i] = this.integralPackageList.get(i).getPackage();
  }
  return result;
}
 
Example #27
Source File: XMind2MindMapImporter.java    From netbeans-mmd-plugin with Apache License 2.0 5 votes vote down vote up
@Nonnull
@MustNotContainNull
private static List<Element> getChildTopics(@Nonnull final Element topic) {
  List<Element> result = new ArrayList<Element>();

  for (final Element c : Utils.findDirectChildrenForName(topic, "children")) {
    for (Element t : Utils.findDirectChildrenForName(c, "topics")) {
      result.addAll(Utils.findDirectChildrenForName(t, "topic"));
    }
  }

  return result;
}
 
Example #28
Source File: AbstractRepo.java    From mvn-golang with Apache License 2.0 5 votes vote down vote up
public int execute(@Nullable String customCommand, @Nonnull final Log logger, @Nonnull final File cvsFolder, @Nonnull @MustNotContainNull final String... args) {
  final List<String> cli = new ArrayList<>();
  cli.add(GetUtils.findFirstNonNull(customCommand, this.command));
  cli.addAll(Arrays.asList(args));

  if (logger.isDebugEnabled()) {
    logger.debug("Executing repo command : " + cli);
  }

  final ByteArrayOutputStream errorStream = new ByteArrayOutputStream();
  final ByteArrayOutputStream outStream = new ByteArrayOutputStream();

  final ProcessExecutor executor = new ProcessExecutor(cli);

  int result = -1;

  try {
    final ProcessResult processResult = executor.directory(cvsFolder).redirectError(errorStream).redirectOutput(outStream).executeNoTimeout();
    result = processResult.getExitValue();

    if (logger.isDebugEnabled()) {
      logger.debug("Exec.out.........................................");
      logger.debug(new String(errorStream.toByteArray(), Charset.defaultCharset()));
      logger.debug(".................................................");
    }

    if (result != 0) {
      logger.error(new String(errorStream.toByteArray(), Charset.defaultCharset()));
    }

  } catch (IOException | InterruptedException | InvalidExitValueException ex) {
    if (ex instanceof InterruptedException) {
      Thread.currentThread().interrupt();
    }
    logger.error("Unexpected error", ex);
  }

  return result;
}
 
Example #29
Source File: MindMapPanelConfig.java    From netbeans-mmd-plugin with Apache License 2.0 5 votes vote down vote up
public boolean isKeyEventDetected(@Nonnull final KeyEvent event, @Nonnull final int effectiveModifiers, @Nonnull @MustNotContainNull final String... shortCutIDs) {
  for (final String k : shortCutIDs) {
    final KeyShortcut shortCut = this.mapShortCut.get(k);
    if (shortCut != null && shortCut.isEvent(event, effectiveModifiers)) {
      return true;
    }
  }
  return false;
}
 
Example #30
Source File: Utils.java    From netbeans-mmd-plugin with Apache License 2.0 5 votes vote down vote up
@Nonnull
@MustNotContainNull
private static List<JMenuItem> findPopupMenuItems(
    @Nonnull final PluginContext context,
    @Nonnull final PopUpSection section,
    final boolean fullScreenModeActive,
    @Nonnull @MayContainNull final List<JMenuItem> list,
    @Nullable final Topic topicUnderMouse,
    @Nonnull @MustNotContainNull final List<PopUpMenuItemPlugin> pluginMenuItems
) {
  list.clear();

  for (final PopUpMenuItemPlugin p : pluginMenuItems) {
    if (fullScreenModeActive && !p.isCompatibleWithFullScreenMode()) {
      continue;
    }
    if (p.getSection() == section) {
      if (!(p.needsTopicUnderMouse() || p.needsSelectedTopics())
          || (p.needsTopicUnderMouse() && topicUnderMouse != null)
          || (p.needsSelectedTopics() && context.getSelectedTopics().length > 0)) {

        final JMenuItem item = p.makeMenuItem(context, topicUnderMouse);
        if (item != null) {
          item.setEnabled(p.isEnabled(context, topicUnderMouse));
          list.add(item);
        }
      }
    }
  }
  return list;
}