Home > Domino Tips > Developer > Java > Java version of @Unique
Domino Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

JAVA

Java version of @Unique


Mike Marcavage
02.01.2005
Rating: -2.33- (out of 5)


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


View member feedback to this tip.

This is a static method of the Lotus formula @Unique, where you pass it a vector and it returns you a string without duplicate values.

  Code: Usage:
String returnList = Unique(vector value);

static String Unique(Vector vValue) {
    try
       {
         Vector hList = vValue;
         String gListH = hList.toString();
         String gListH1 = gListH.replace('[', ' ');
         String gList = gListH1.replace(']', ' ');
         String gListClean = gList.trim();
               
         Vector v1 = new Vector();
         Vector v2 = new Vector();
         Vector temp=new Vector();
         String test = gListClean;
         StringTokenizer st = new StringTokenizer(test,",");
         while(st.hasMoreTokens())
                   {
                     String tmp = st.nextToken();
                      v1.add(tmp);
                      v2.add(tmp);
                    }
         String item2="";
        
         for(int k=0; k < v1.size(); k++)
             {
               String item=(String)v1.get(k);
                if(!temp.contains(item))
                   temp.addElement(item);
             }
          v2 = temp;
               
         Vector hReturnList = v2;
         String gReturnListH = hReturnList.toString();
         String gReturnListH1 = gReturnListH.replace('[', ' ');
         String gReturnListH2 = gReturnListH1.replace(']', ' ');
         String gReturnListClean = gReturnListH2.trim();
         
         return gReturnListClean;
       }
       catch(Exception e)
                {                  
                  return "";  
               }
}               

MEMBER FEEDBACK TO THIS TIP

I have a feeling that @Unique can be done with some help from Java by using Set.

A Set is a collection that cannot contain duplicate elements. See: http://java.sun.com/docs/books/tutorial/collections/index.html

The code fragment to get unique entries is only one line of code:
Set set = new TreeSet(vector);

I include the whole program to show the Set usage:
(the Unique method is included as well)

import java.util.Arrays;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.TreeSet;
import java.util.Vector;

public class Main {

 static String Unique(Vector vValue) {
  try {
   Vector hList = vValue;
   String gListH = hList.toString();
   String gListH1 = gListH.replace('[', ' ');
   String gList = gListH1.replace(']', ' ');
   String gListClean = gList.trim();

   Vector v1 = new Vector();
   Vector v2 = new Vector();
   Vector temp = new Vector();
   String test = gListClean;
   StringTokenizer st = new StringTokenizer(test, ",");
   while (st.hasMoreTokens()) {
    String tmp = st.nextToken();
    v1.add(tmp);
    v2.add(tmp);
   }
   String item2 = "";

   for (int k = 0; k < v1.size(); k++) {
    String item = (String) v1.get(k);
    if (!temp.contains(item))
     temp.addElement(item);
   }
   v2 = temp;

   Vector hReturnList = v2;
   String gReturnListH = hReturnList.toString();
   String gReturnListH1 = gReturnListH.replace('[', ' ');
   String gReturnListH2 =
gReturnListH1.replace(']', ' ');
   String gReturnListClean = gReturnListH2.trim();

   return gReturnListClean;
  } catch (Exception e) {
   return "";
  }
 }

 
 /**
  * Return some data for the test.
  * @return
  */
 private static Vector getNewVector() {
  
  Integer inputArray[] = new Integer[5];

  for (int index = 0; index < inputArray.length; index++) {
   inputArray[index] = new Integer(index + 1);
  }
  
  Vector vector = new Vector();

  vector.addAll(Arrays.asList(inputArray));
  vector.addAll(Arrays.asList(inputArray));
  vector.addAll(Arrays.asList(inputArray));

  return vector;

 }

 public static void main(String[] args) {

  Vector vector = new Vector(getNewVector());

  System.out.println("The original vector: " + vector);

  System.out.println("The result of Unique Method: \n"
    + "(I think see a bug there.. the '1'
appears twice \n"
    + Unique(vector));

  // Using the set interface
  Set set = new TreeSet(vector);
  System.out.println("set content: " + set);
  vector.removeAllElements();
  vector.addAll(set);
  System.out.println("vector after removeAllElements()"
    + "and addAll(set) : " + vector);
 }
}


This is the result:

The original vector: [1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5] The result 
of Unique Method: 
(I think see a bug there.. the '1' appears twice 1,  2,  3,  4,  5,  1 
setcontent: [1, 2, 3, 4, 5] vector after removeAllElements()and addAll(set) : 
[1, 2, 3, 4, 5]

—Eitan R.

Do you have comments on this tip? Let us know.

This tip was submitted to the SearchDomino.com tip exchange by member Mike Marcavage. Please let others know how useful it is via the rating scale at the end of the tip. Do you have a useful Notes/Domino tip or code to share? Submit it to our monthly tip contest and you could win a prize and a spot in our Hall of Fame.

Rate this Tip
To rate tips, you must be a member of SearchDomino.com.
Register now to start rating these tips. Log in if you are already a member.




Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   



RELATED CONTENT
Java
Java code inserts data from Notes documents into a SQL table
Java code shortens strings in a SQL table
How to execute a stored procedure in Lotus Notes Domino using Java
How to return an HTML representation of a Lotus Notes rich-text field
Shrink Lotus Notes databases with many attachments
Converting Lotus Notes Domino Web pages to PDF files with a Java agent
A bevy of Notes/Domino development tips
Converting Web pages to images using Java
Creating Microsoft Word documents from Lotus Notes
FAQ: Java for Lotus Notes and Domino

Java for Lotus Notes Domino
Top 10 Lotus Notes/Domino coding and development tips of 2008
Java code inserts data from Notes documents into a SQL table
Java code shortens strings in a SQL table
How to execute a stored procedure in Lotus Notes Domino using Java
Top 10 Lotus Notes Domino programming and development tips of 2007
How to return an HTML representation of a Lotus Notes rich-text field
Shrink Lotus Notes databases with many attachments
Converting Lotus Notes Domino Web pages to PDF files with a Java agent
Developing Eclipse plug-ins for Lotus Notes and Domino -- 7 tips in 7 minutes
A bevy of Notes/Domino development tips

Lotus Notes Domino Formula Language
View hidden fields on Lotus Notes/Domino forms
Case-insensitive @Unique version combines fields on Lotus Notes forms
Do I use Formula or LotusScript to include a doclink to a Notes view?
Top 10 Lotus Notes/Domino coding and development tips of 2008
Provide rich-text formatting via the Profile document and Formula
Top 10 Formula language tips
Using Formula language code to sort Lotus Notes messages by subject
How to create dynamic JavaScript in Notes Domino without formulas
Stop response documents from showing in a Lotus Notes form
Formula language button manages Deny Access list searches

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary

DISCLAIMER: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.



Domino & Lotus Notes Security Solutions: Authentication, Antispam, Encryption and Antivirus
HomeTopicsITKnowledge ExchangeTipsAsk the ExpertsMultimediaWhite PapersDomino IT Downloads
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Site Map




All Rights Reserved, Copyright 1999 - 2009, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts