Java Code Examples for java.util.Collections

The following code examples are extracted from open source projects. You can click to vote up the examples that are useful to you.

Example 1

From project ades, under directory /src/main/java/com/cloudera/science/pig/.

Source file: Bin.java

  19 
vote

@Override public DataBag exec(Tuple input) throws IOException {
  DataBag output=bagFactory.newDefaultBag();
  Object o1=input.get(0);
  if (!(o1 instanceof DataBag)) {
    throw new IOException("Expected input to be a bag, but got: " + o1.getClass());
  }
  DataBag inputBag=(DataBag)o1;
  Object o2=input.get(1);
  if (!(o2 instanceof DataBag)) {
    throw new IOException("Expected second input to be a bag, but got: " + o2.getClass());
  }
  List<Double> quantiles=getQuantiles((DataBag)o2);
  for (  Tuple t : inputBag) {
    if (t != null && t.get(0) != null) {
      double val=((Number)t.get(0)).doubleValue();
      int index=Collections.binarySearch(quantiles,val);
      if (index > -1) {
        t=tupleFactory.newTuple(ImmutableList.of(index,t.get(0)));
      }
 else {
        t=tupleFactory.newTuple(ImmutableList.of(-index - 1,t.get(0)));
      }
      output.add(t);
    }
  }
  return output;
}
 

Example 2

From project aether-core, under directory /aether-api/src/main/java/org/eclipse/aether/artifact/.

Source file: AbstractArtifact.java

  18 
vote

/** 
 * Copies the specified artifact properties. This utility method should be used when creating new artifact instances with caller-supplied properties.
 * @param properties The properties to copy, may be {@code null}.
 * @return The copied and read-only properties, never {@code null}.
 */
protected static Map<String,String> copyProperties(Map<String,String> properties){
  if (properties != null && !properties.isEmpty()) {
    return Collections.unmodifiableMap(new HashMap<String,String>(properties));
  }
 else {
    return Collections.emptyMap();
  }
}
 

Example 3

From project acceleo-modules, under directory /psm-gen-scala/plugins/com.github.sbegaudeau.acceleo.modules.psm.gen.scala.editor/src-gen/com/github/sbegaudeau/acceleo/modules/psm/gen/scala/model/scala/presentation/.

Source file: ScalaEditor.java

  16 
vote

/** 
 * Handles what to do with changed resources on activation. <!-- begin-user-doc --> <!-- end-user-doc -->
 * @generated
 */
protected void handleChangedResources(){
  if (!changedResources.isEmpty() && (!isDirty() || handleDirtyConflict())) {
    if (isDirty()) {
      changedResources.addAll(editingDomain.getResourceSet().getResources());
    }
    editingDomain.getCommandStack().flush();
    updateProblemIndication=false;
    for (    Resource resource : changedResources) {
      if (resource.isLoaded()) {
        resource.unload();
        try {
          resource.load(Collections.EMPTY_MAP);
        }
 catch (        IOException exception) {
          if (!resourceToDiagnosticMap.containsKey(resource)) {
            resourceToDiagnosticMap.put(resource,analyzeResourceProblems(resource,exception));
          }
        }
      }
    }
    if (AdapterFactoryEditingDomain.isStale(editorSelection)) {
      setSelection(StructuredSelection.EMPTY);
    }
    updateProblemIndication=true;
    updateProblemIndication();
  }
}
 

Example 4

From project acceleo-webapp-generator, under directory /plugins/org.eclipse.acceleo.tutorial.webapp.editor/src-gen/org/eclipse/acceleo/tutorial/webapp/presentation/.

Source file: WebappEditor.java

  16 
vote

/** 
 * Handles what to do with changed resources on activation. <!-- begin-user-doc --> <!-- end-user-doc -->
 * @generated
 */
protected void handleChangedResources(){
  if (!changedResources.isEmpty() && (!isDirty() || handleDirtyConflict())) {
    if (isDirty()) {
      changedResources.addAll(editingDomain.getResourceSet().getResources());
    }
    editingDomain.getCommandStack().flush();
    updateProblemIndication=false;
    for (    Resource resource : changedResources) {
      if (resource.isLoaded()) {
        resource.unload();
        try {
          resource.load(Collections.EMPTY_MAP);
        }
 catch (        IOException exception) {
          if (!resourceToDiagnosticMap.containsKey(resource)) {
            resourceToDiagnosticMap.put(resource,analyzeResourceProblems(resource,exception));
          }
        }
      }
    }
    if (AdapterFactoryEditingDomain.isStale(editorSelection)) {
      setSelection(StructuredSelection.EMPTY);
    }
    updateProblemIndication=true;
    updateProblemIndication();
  }
}
 

Example 5

From project activiti-webapp-rest-generic, under directory /activiti-webapp-rest/src/main/java/org/activiti/rest/api/cycle/dto/.

Source file: TreeFolderDto.java

  16 
vote

public void sortChildNodes(){
  Collections.sort(children,new Comparator<TreeNodeDto>(){
    public int compare(    TreeNodeDto arg0,    TreeNodeDto arg1){
      if (arg0 instanceof TreeFolderDto) {
        if (arg1 instanceof TreeFolderDto) {
          return arg0.getLabel().compareTo(arg1.getLabel());
        }
        return -1;
      }
      if (arg1 instanceof TreeFolderDto) {
        return 1;
      }
      return arg0.getLabel().compareTo(arg1.getLabel());
    }
  }
);
}
 

Example 6

From project AeminiumRuntime, under directory /src/aeminium/runtime/implementations/implicitworkstealing/task/.

Source file: ImplicitAtomicTask.java

  16 
vote

public void addDataGroupDependecy(DataGroup required){
  if (requiredGroups == null) {
synchronized (this) {
      if (requiredGroups == null) {
        requiredGroups=Collections.synchronizedSet(new HashSet<DataGroup>());
      }
    }
  }
  requiredGroups.add(required);
}
 

Example 7

From project 16Blocks, under directory /src/main/java/de/minestar/sixteenblocks/Threads/.

Source file: BroadcastThread.java

  15 
vote

private void loadMessages(){
  File file=new File(dataFolder,"messages.txt");
  if (!file.exists()) {
    ConsoleUtils.printWarning(Core.NAME,"Can't find " + file + "! No messages for broadcast thread are loaded!");
    return;
  }
  try {
    messages=new ArrayList<String>(32);
    BufferedReader bReader=new BufferedReader(new FileReader(file));
    String line="";
    while ((line=bReader.readLine()) != null) {
      if (!line.isEmpty())       messages.add(line);
    }
    bReader.close();
    index=0;
    Collections.shuffle(messages);
  }
 catch (  Exception e) {
    ConsoleUtils.printException(e,Core.NAME,"Error while loading " + file + " !");
  }
}
 

Example 8

From project 2Degrees-Toolbox, under directory /ActionBarSherlock/src/com/actionbarsherlock/widget/.

Source file: ActivityChooserModel.java

  15 
vote

/** 
 * Sorts the activities based on history and an intent. If a sorter is not specified this a default implementation is used.
 * @see #setActivitySorter(ActivitySorter)
 */
private void sortActivities(){
synchronized (mInstanceLock) {
    if (mActivitySorter != null && !mActivites.isEmpty()) {
      mActivitySorter.sort(mIntent,mActivites,Collections.unmodifiableList(mHistoricalRecords));
      notifyChanged();
    }
  }
}
 

Example 9

From project Aardvark, under directory /aardvark/src/main/test/gw/vark/it/.

Source file: ForkedAardvarkProcess.java

  15 
vote

@Override protected List<File> createClasspath(){
  try {
    File assemblyDir=ITUtil.getAssemblyDir();
    File libDir=new File(assemblyDir,"lib");
    File launcherJar=ITUtil.findFile(libDir,"gosu-launcher-[\\d\\.]+\\.jar");
    return Collections.singletonList(launcherJar);
  }
 catch (  FileNotFoundException e) {
    throw new RuntimeException(e);
  }
}
 

Example 10

From project Absolute-Android-RSS, under directory /src/com/AA/Recievers/.

Source file: AAWidgetProvider.java

  15 
vote

/** 
 * Updates the widget with the newest article
 * @param context - Context that gives us access to some system operations
 * @param intent - The intent that launched this receiver
 */
private static void updateArticles(Context context,Intent intent){
  Bundle articleBundle=intent.getBundleExtra("articles");
  ArrayList<String> titles=articleBundle.getStringArrayList("titles");
  ArrayList<Article> articles=new ArrayList<Article>();
  if (titles == null)   titles=new ArrayList<String>();
  for (  String title : titles)   articles.add((Article)articleBundle.getSerializable(title));
  Collections.sort(articles);
  if (!articles.isEmpty())   updateWidget(context,articles.get(0).getTitle(),articles.get(0).getDescription());
 else   updateWidget(context,"Uh Oh","Something happened. No data received");
}
 

Example 11

From project AceWiki, under directory /src/ch/uzh/ifi/attempto/acewiki/aceowl/.

Source file: ACELexiconExporter.java

  15 
vote

protected void writeContent() throws IOException {
  List<String> lexiconEntries=new ArrayList<String>();
  for (  OntologyElement oe : getOntologyElements()) {
    if (oe instanceof ACEOWLOntoElement) {
      for (      LexiconEntry le : ((ACEOWLOntoElement)oe).getLexiconEntries()) {
        if (!lexiconEntries.contains(le.toString())) {
          lexiconEntries.add(le.toString());
        }
      }
    }
  }
  Collections.sort(lexiconEntries,String.CASE_INSENSITIVE_ORDER);
  for (  String s : lexiconEntries) {
    write(s + ".\n");
  }
}
 

Example 12

From project ActionBarSherlock, under directory /library/src/com/actionbarsherlock/widget/.

Source file: ActivityChooserModel.java

  15 
vote

/** 
 * Sorts the activities based on history and an intent. If a sorter is not specified this a default implementation is used.
 * @see #setActivitySorter(ActivitySorter)
 */
private void sortActivities(){
synchronized (mInstanceLock) {
    if (mActivitySorter != null && !mActivites.isEmpty()) {
      mActivitySorter.sort(mIntent,mActivites,Collections.unmodifiableList(mHistoricalRecords));
      notifyChanged();
    }
  }
}
 

Example 13

From project activejdbc, under directory /activejdbc/src/main/java/org/javalite/activejdbc/.

Source file: Model.java

  15 
vote

/** 
 * TODO: write good JavaDoc, use code  inside method above
 * @param formatters
 * @return
 */
public String toInsert(Formatter... formatters){
  HashMap<Class,Formatter> formatterMap=new HashMap<Class,Formatter>();
  for (  Formatter f : formatters) {
    formatterMap.put(f.getValueClass(),f);
  }
  List<String> names=new ArrayList<String>(attributes.keySet());
  Collections.sort(names);
  List<Object> values=new ArrayList();
  for (  String name : names) {
    Object value=get(name);
    if (value == null) {
      values.add("NULL");
    }
 else     if (value instanceof String && !formatterMap.containsKey(String.class)) {
      values.add("'" + value + "'");
    }
 else {
      if (formatterMap.containsKey(value.getClass())) {
        values.add(formatterMap.get(value.getClass()).format(value));
      }
 else {
        values.add(value);
      }
    }
  }
  return new StringBuffer("INSERT INTO ").append(getMetaModelLocal().getTableName()).append(" (").append(Util.join(names,", ")).append(") VALUES (").append(Util.join(values,", ")).append(")").toString();
}
 

Example 14

From project activemq-apollo, under directory /apollo-openwire/src/main/scala/org/apache/activemq/apollo/openwire/command/.

Source file: Message.java

  15 
vote

@SuppressWarnings("unchecked") public Map<String,Object> getProperties() throws IOException {
  if (properties == null) {
    if (marshalledProperties == null) {
      return Collections.EMPTY_MAP;
    }
    properties=unmarsallProperties(marshalledProperties);
  }
  return Collections.unmodifiableMap(properties);
}
 

Example 15

From project activiti-explorer, under directory /src/main/java/org/activiti/explorer/ui/management/deployment/.

Source file: DeploymentDetailPanel.java

  15 
vote

protected void addResourceLinks(){
  List<String> resourceNames=repositoryService.getDeploymentResourceNames(deployment.getId());
  Collections.sort(resourceNames);
  if (resourceNames.size() > 0) {
    Label resourceHeader=new Label(i18nManager.getMessage(Messages.DEPLOYMENT_HEADER_RESOURCES));
    resourceHeader.setWidth("95%");
    resourceHeader.addStyleName(ExplorerLayout.STYLE_H3);
    resourceHeader.addStyleName(ExplorerLayout.STYLE_DETAIL_BLOCK);
    addDetailComponent(resourceHeader);
    VerticalLayout resourceLinksLayout=new VerticalLayout();
    resourceLinksLayout.setSpacing(true);
    resourceLinksLayout.setMargin(true,false,false,false);
    addDetailComponent(resourceLinksLayout);
    for (    final String resourceName : resourceNames) {
      StreamResource.StreamSource streamSource=new StreamSource(){
        public InputStream getStream(){
          return repositoryService.getResourceAsStream(deployment.getId(),resourceName);
        }
      }
;
      Link resourceLink=new Link(resourceName,new StreamResource(streamSource,resourceName,ExplorerApp.get()));
      resourceLinksLayout.addComponent(resourceLink);
    }
  }
}
 

Example 16

From project Activiti-KickStart, under directory /activiti-kickstart-rest/src/main/java/org/activiti/kickstart/.

Source file: WorkflowResource.java

  15 
vote

protected ObjectNode deployWorkflow(KickstartWorkflow workflow,String json){
  String workflowId=getKickstartService().deployWorkflow(workflow,Collections.singletonMap(MetaDataKeys.WORKFLOW_JSON_SOURCE,json));
  ObjectNode idNode=new ObjectMapper().createObjectNode();
  idNode.put("id",workflowId);
  return idNode;
}
 

Example 17

From project adbcj, under directory /api/src/main/java/org/adbcj/support/.

Source file: DefaultRow.java

  15 
vote

@Override public Set<java.util.Map.Entry<Object,Value>> entrySet(){
  if (entrySet == null) {
    Set<java.util.Map.Entry<Object,Value>> set=new HashSet<Entry<Object,Value>>();
    for (    Value value : values) {
      set.add(new AbstractMap.SimpleEntry<Object,Value>(value.getField(),value));
    }
    entrySet=Collections.unmodifiableSet(set);
  }
  return entrySet;
}
 

Example 18

From project addis, under directory /application/src/main/java/org/drugis/addis/entities/analysis/.

Source file: StudyBenefitRiskAnalysis.java

  15 
vote

public StudyBenefitRiskAnalysis(String name,Indication indication,Study study,List<OutcomeMeasure> criteria,Arm baseline,List<Arm> alternatives,AnalysisType analysisType,DecisionContext context){
  super(name);
  d_baseline=baseline;
  assertMeasurementsPresent(study,criteria,alternatives);
  d_indication=indication;
  d_study=study;
  setCriteria(criteria);
  d_alternatives=new ArrayListModel<Arm>(Collections.unmodifiableList(alternatives));
  d_analysisType=analysisType;
  if (d_analysisType == AnalysisType.LyndOBrien && (d_criteria.size() != 2 || d_alternatives.size() != 2)) {
    throw new IllegalArgumentException("Attempt to create Lynd & O'Brien analysis with not exactly 2 criteria and 2 alternatives");
  }
  d_decisionContext=context;
}
 

Example 19

From project AdminCmd, under directory /src/main/java/be/Balor/Tools/.

Source file: Utils.java

  15 
vote

/** 
 * Get the player list ordered by group and alphabetically for the sender
 * @param sender sender of the command
 * @return a Collection containing what to display
 */
public static Collection<String> getPlayerList(final CommandSender sender){
  final List<Player> online=Utils.getOnlinePlayers();
  final Map<Player,String> players=new TreeMap<Player,String>(new PlayerComparator());
  for (  final Player p : online) {
    if ((InvisibleWorker.getInstance().hasInvisiblePowers(p) || ACPlayer.getPlayer(p).hasPower(Type.FAKEQUIT)) && !PermissionManager.hasPerm(sender,"admincmd.invisible.cansee",false)) {
      continue;
    }
    players.put(p,Utils.getPlayerName(p,sender));
  }
  return Collections.unmodifiableCollection(players.values());
}
 

Example 20

From project aether-ant, under directory /src/main/java/org/eclipse/aether/ant/.

Source file: AntModelResolver.java

  15 
vote

public void addRepository(Repository repository) throws InvalidRepositoryException {
  if (!repositoryIds.add(repository.getId())) {
    return;
  }
  List<RemoteRepository> newRepositories=Collections.singletonList(convert(repository));
  this.repositories=remoteRepositoryManager.aggregateRepositories(session,repositories,newRepositories,true);
}