source: trunk/java-client/org/nzdl/gsdl/classification/LibraryOfCongressCollectionsPolicy.java@ 2194

Last change on this file since 2194 was 2194, checked in by say1, 23 years ago

added Library of Congress files

  • Property svn:keywords set to Author Date Id Revision
File size: 4.4 KB
Line 
1/*
2 * TODO.java
3 * Copyright (C) 2000 Stuart Yeates
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19
20// the package we're in
21package org.nzdl.gsdl.classification;
22
23// java standard library classes used
24import java.util.Enumeration;
25import java.util.Vector;
26import java.util.Properties;
27
28/**
29 * Class ...
30 *
31 * Based on algorithms in ...
32 *
33 * @author stuart yeates ([email protected])
34 * @version $Revision: 2194 $
35 * @see
36 * @see
37 * @see
38 *
39 */
40
41public class LibraryOfCongressCollectionsPolicy implements CollectionsPolicy
42{
43 Properties byClass = null;
44
45 LibraryOfCongressCollectionsPolicy() {
46 byClass = new Properties();
47 }
48 LibraryOfCongressCollectionsPolicy(Properties p) {
49 byClass = p;
50 }
51
52 /**
53 * Get the ClassificationSystem used by the CollectionsPolicy
54 *
55 * @return ClassificationSystem
56 * @see ClassificationSystem
57 */
58 public ClassificationSystem getClassificationSystem(){
59 return LibraryOfCongressClassificationSystem.getInstance();
60 }
61 /**
62 * Assign a level to a piece of metadata.
63 *
64 * The metadata must be in a format understood by the
65 * ClassificationSystem used by the CollectionsPolicy
66 *
67 * @param metadata the metadata
68 * @return the level
69 * @see ClassificationSystem
70 */
71 public int level(String metadata){
72 Enumeration e = getClassificationSystem().parse(metadata);
73 if (e.hasMoreElements())
74 return ((Integer)byClass.get(e.nextElement())).intValue();
75 else
76 return 0;
77 }
78
79 /**
80 * Assign a level to a collection of metadata.
81 *
82 * The metadata must be in a format understood by the
83 * ClassificationSystem used by the CollectionsPolicy
84 *
85 * @exception java.io.IOException when ...
86 * @param metadata the metadata
87 * @return the level
88 * @see ClassificationSystem
89 */
90 public int level(String[] metadata) {
91 int top = 0;
92 for (int i = 0; i < metadata.length; i++)
93 top = Math.max(top, level(metadata[i]));
94 return top;
95 }
96
97 /**
98 * Get all Classifications for a given level
99 *
100 * @exception java.io.IOException when ...
101 * @param level the level for which Classifications are returned
102 * @return the Classifications
103 * @see Classification
104 */
105 public Enumeration getClassificationsForLevel(int level){
106 Vector vec = new Vector ();
107 Enumeration e = byClass.keys();
108 while (e.hasMoreElements()) {
109 Classification c = (Classification) e.nextElement();
110 Integer I = (Integer) byClass.get(c);
111 int i = I.intValue();
112 if (i == level)
113 vec.add(c);
114 }
115 return vec.elements();
116 }
117
118 /**
119 * Tests...
120 *
121 *
122 * @param args the arguments ...
123 */
124
125 public static void main(String args[])
126 {
127 Properties p = new Properties();
128 p.put("004",new Integer(5));
129 p.put("005",new Integer(5));
130 p.put("006",new Integer(5));
131 p.put("001",new Integer(4));
132 p.put("002",new Integer(4));
133 p.put("003",new Integer(4));
134 LibraryOfCongressCollectionsPolicy policy = new LibraryOfCongressCollectionsPolicy(p);
135
136 System.out.println("the level of 001 should is: " + policy.level("001") + " should be 4");
137 System.out.println("the level of 002 should is: " + policy.level("002") + " should be 4");
138 System.out.println("the level of 003 should is: " + policy.level("003") + " should be 4");
139 System.out.println("the level of 004 should is: " + policy.level("004") + " should be 5");
140 System.out.println("the level of 005 should is: " + policy.level("005") + " should be 5");
141 System.out.println("the level of 006 should is: " + policy.level("006") + " should be 5");
142 System.out.println("the level of 010 should is: " + policy.level("010") + " should be 0");
143 System.out.println("the level of 005.5 should is: " + policy.level("005.5") + " should be 5");
144
145
146 }
147}
148
Note: See TracBrowser for help on using the repository browser.