Example usage for java.util SortedSet size

List of usage examples for java.util SortedSet size

Introduction

In this page you can find the example usage for java.util SortedSet size.

Prototype

int size();

Source Link

Document

Returns the number of elements in this set (its cardinality).

Usage

From source file:com.mapr.synth.TermGeneratorTest.java

@Test
public void speciesCounts() {
    final boolean transpose = false;

    // generate an example of species sampled on multiple days
    LongTail<Integer> terms = new LongTail<Integer>(0.5, 0.3) {
        int max = 0;

        @Override//from   w ww .j a va  2s .c  o m
        protected Integer createThing() {
            return ++max;
        }
    };

    // I picked seeds to get a good illustration ... want a reasonable number of species and surprises
    terms.setSeed(2);

    Random gen = new Random(1);
    SortedSet<Integer> vocabulary = Sets.newTreeSet();
    List<Multiset<Integer>> r = Lists.newArrayList();

    for (int i = 0; i < 2000; i++) {
        double length = Math.rint(gen.nextGaussian() * 10 + 50);
        Multiset<Integer> counts = HashMultiset.create();
        for (int j = 0; j < length; j++) {
            counts.add(terms.sample());
        }
        r.add(counts);
    }

    if (transpose) {
        for (Multiset<Integer> day : r) {
            vocabulary.addAll(day.elementSet());
        }

        System.out.printf("%d\n", vocabulary.size());
        for (Integer s : vocabulary) {
            String sep = "";
            for (Multiset<Integer> day : r) {
                System.out.printf("%s%s", sep, day.count(s));
                sep = "\t";
            }
            System.out.printf("\n");
        }
    } else {
        System.out.printf("%d\n", vocabulary.size());
        for (Multiset<Integer> day : r) {
            vocabulary.addAll(day.elementSet());
            String sep = "";
            System.out.printf("%s%s", sep, vocabulary.size());
            sep = "\t";
            for (Integer s : vocabulary) {
                System.out.printf("%s%s", sep, day.count(s));
                sep = "\t";
            }
            System.out.printf("\n");
        }

        Multiset<Integer> total = HashMultiset.create();
        for (Multiset<Integer> day : r) {
            for (Integer species : day.elementSet()) {
                total.add(species, day.count(species));
            }
        }
        String sep = "";
        System.out.printf("%s%s", sep, total.elementSet().size());
        sep = "\t";
        for (Integer s : vocabulary) {
            System.out.printf("%s%s", sep, total.count(s));
            sep = "\t";
        }
        System.out.printf("\n");
    }
}

From source file:org.tonguetied.datatransfer.importing.ResourceImporterTest.java

/**
 * Test method for/*from w  ww .  java 2s.  c  o m*/
 * {@link ResourceImporter#importData(ImportParameters)}.
 */
public final void testImportInvalidSchemaData() throws Exception {
    final String fileName = "ResourceImporterInvalidTest";
    File file = new File(TEST_DATA_DIR, fileName + "." + FormatType.resx.getDefaultFileExtension());
    byte[] input = FileUtils.readFileToByteArray(file);
    final Importer importer = ImporterFactory.getImporter(FormatType.resx, keywordService, transferRepository);
    TranslationState expectedState = TranslationState.VERIFIED;
    ImportParameters parameters = new ImportParameters();
    parameters.setData(input);
    parameters.setTranslationState(expectedState);
    parameters.setFileName(RESOURCE_NAME_VALID);
    try {
        importer.importData(parameters);
        fail("this method should not succeed.");
    } catch (ImportException ie) {
        assertNotNull(ie.getMessage());
    }

    Keyword actual = keywordService.getKeyword("importTestOne");
    assertNotNull(actual);
    assertNull(actual.getContext());
    SortedSet<Translation> translations = actual.getTranslations();
    assertEquals(1, translations.size());
    Object[] actualTranslations = actual.getTranslations().toArray();
    Translation actualTranslation = (Translation) actualTranslations[0];
    assertEquals(defaultCountry, actualTranslation.getCountry());
    assertEquals(defaultLanguage, actualTranslation.getLanguage());
    assertEquals(bundle1, actualTranslation.getBundle());
    assertEquals(expectedState, actualTranslation.getState());
    assertEquals("plain text", actualTranslation.getValue());

    actual = keywordService.getKeyword("importTestTwo");
    assertNull(actual);

    actual = keywordService.getKeyword("importTestThree");
    assertNotNull(actual);
    assertEquals("updates an existing key", actual.getContext());
    translations = actual.getTranslations();
    assertEquals(1, translations.size());
    actualTranslations = actual.getTranslations().toArray();
    actualTranslation = (Translation) actualTranslations[0];
    assertEquals(defaultCountry, actualTranslation.getCountry());
    assertEquals(defaultLanguage, actualTranslation.getLanguage());
    assertEquals(bundle1, actualTranslation.getBundle());
    assertEquals(expectedState, actualTranslation.getState());
    assertEquals("new value 3", actualTranslation.getValue());

    actual = keywordService.getKeyword("importTestFour");
    assertNotNull(actual);
    assertNull(actual.getContext());
    translations = actual.getTranslations();
    assertEquals(1, translations.size());
    actualTranslations = actual.getTranslations().toArray();
    actualTranslation = (Translation) actualTranslations[0];
    assertEquals(defaultCountry, actualTranslation.getCountry());
    assertEquals(defaultLanguage, actualTranslation.getLanguage());
    assertEquals(bundle1, actualTranslation.getBundle());
    assertEquals(expectedState, actualTranslation.getState());
    assertNull(actualTranslation.getValue());

    actual = keywordService.getKeyword("importTestFive");
    assertNotNull(actual);
    assertEquals("existing", actual.getContext());
    translations = actual.getTranslations();
    assertEquals(2, translations.size());
    actualTranslations = actual.getTranslations().toArray();
    actualTranslation = (Translation) actualTranslations[0];
    assertEquals(defaultCountry, actualTranslation.getCountry());
    assertEquals(defaultLanguage, actualTranslation.getLanguage());
    assertEquals(bundle1, actualTranslation.getBundle());
    assertEquals(expectedState, actualTranslation.getState());
    assertEquals("<data> ! ?", actualTranslation.getValue());
}

From source file:org.codehaus.mojo.license.AbstractAddThirdPartyMojo.java

protected boolean checkUnsafeDependencies() {
    SortedSet<MavenProject> unsafeDeps = getUnsafeDependencies();
    boolean unsafe = !CollectionUtils.isEmpty(unsafeDeps);
    if (unsafe) {
        Log log = getLog();//from ww w. j  a  v a 2  s.  c  o m
        log.warn("There is " + unsafeDeps.size() + " dependencies with no license :");
        for (MavenProject dep : unsafeDeps) {

            // no license found for the dependency
            log.warn(" - " + MojoHelper.getArtifactId(dep.getArtifact()));
        }
    }
    return unsafe;
}

From source file:org.tonguetied.datatransfer.importing.ResourceImporterTest.java

/**
 * Test method for//from  w w  w.  j av a 2s  .c  o m
 * {@link ResourceImporter#importData(ImportParameters)}.
 */
public final void testImportData() throws Exception {
    final String fileName = RESOURCE_NAME_VALID;
    File file = new File(TEST_DATA_DIR, fileName + "." + FormatType.resx.getDefaultFileExtension());
    byte[] input = FileUtils.readFileToByteArray(file);
    final Importer importer = ImporterFactory.getImporter(FormatType.resx, keywordService, transferRepository);
    TranslationState expectedState = TranslationState.VERIFIED;
    ImportParameters parameters = new ImportParameters();
    parameters.setData(input);
    parameters.setTranslationState(expectedState);
    parameters.setFileName(fileName);
    importer.importData(parameters);
    Keyword actual = keywordService.getKeyword("importTestOne");
    assertNotNull(actual);
    assertNull(actual.getContext());
    SortedSet<Translation> translations = actual.getTranslations();
    assertEquals(1, translations.size());
    Object[] actualTranslations = actual.getTranslations().toArray();
    Translation actualTranslation = (Translation) actualTranslations[0];
    assertEquals(defaultCountry, actualTranslation.getCountry());
    assertEquals(defaultLanguage, actualTranslation.getLanguage());
    assertEquals(bundle1, actualTranslation.getBundle());
    assertEquals(expectedState, actualTranslation.getState());
    assertEquals("plain text", actualTranslation.getValue());

    actual = keywordService.getKeyword("importTestTwo");
    assertNotNull(actual);
    assertEquals("this is has an empty value", actual.getContext());
    translations = actual.getTranslations();
    assertEquals(1, translations.size());
    actualTranslations = actual.getTranslations().toArray();
    actualTranslation = (Translation) actualTranslations[0];
    assertEquals(defaultCountry, actualTranslation.getCountry());
    assertEquals(defaultLanguage, actualTranslation.getLanguage());
    assertEquals(bundle1, actualTranslation.getBundle());
    assertEquals(expectedState, actualTranslation.getState());
    assertNull(actualTranslation.getValue());

    actual = keywordService.getKeyword("importTestThree");
    assertNotNull(actual);
    assertEquals("updates an existing key", actual.getContext());
    translations = actual.getTranslations();
    assertEquals(1, translations.size());
    actualTranslations = actual.getTranslations().toArray();
    actualTranslation = (Translation) actualTranslations[0];
    assertEquals(defaultCountry, actualTranslation.getCountry());
    assertEquals(defaultLanguage, actualTranslation.getLanguage());
    assertEquals(bundle1, actualTranslation.getBundle());
    assertEquals(expectedState, actualTranslation.getState());
    assertEquals("new value 3", actualTranslation.getValue());

    actual = keywordService.getKeyword("importTestFour");
    assertNotNull(actual);
    assertNull(actual.getContext());
    translations = actual.getTranslations();
    assertEquals(1, translations.size());
    actualTranslations = actual.getTranslations().toArray();
    actualTranslation = (Translation) actualTranslations[0];
    assertEquals(defaultCountry, actualTranslation.getCountry());
    assertEquals(defaultLanguage, actualTranslation.getLanguage());
    assertEquals(bundle1, actualTranslation.getBundle());
    assertEquals(expectedState, actualTranslation.getState());
    assertNull(actualTranslation.getValue());

    actual = keywordService.getKeyword("importTestFive");
    assertNotNull(actual);
    assertEquals("existing", actual.getContext());
    translations = actual.getTranslations();
    assertEquals(2, translations.size());
    actualTranslations = actual.getTranslations().toArray();
    actualTranslation = (Translation) actualTranslations[0];
    assertEquals(defaultCountry, actualTranslation.getCountry());
    assertEquals(defaultLanguage, actualTranslation.getLanguage());
    assertEquals(bundle1, actualTranslation.getBundle());
    assertEquals(expectedState, actualTranslation.getState());
    assertEquals("<data> ! ?", actualTranslation.getValue());
}

From source file:org.tonguetied.datatransfer.importing.ResourceImporterTest.java

/**
 * Test method for//from  w w  w.ja  v  a  2  s .co  m
 * {@link ResourceImporter#importData(ImportParameters)}.
 */
public final void testImportDataWithPresetBundle() throws Exception {
    final String fileName = RESOURCE_NAME_VALID;
    File file = new File(TEST_DATA_DIR, fileName + "." + FormatType.resx.getDefaultFileExtension());
    byte[] input = FileUtils.readFileToByteArray(file);
    final Importer importer = ImporterFactory.getImporter(FormatType.resx, keywordService, transferRepository);
    TranslationState expectedState = TranslationState.VERIFIED;
    ImportParameters parameters = new ImportParameters();
    parameters.setData(input);
    parameters.setTranslationState(expectedState);
    parameters.setFileName(fileName);
    parameters.setBundle(bundle2);
    importer.importData(parameters);
    Keyword actual = keywordService.getKeyword("importTestOne");
    assertNotNull(actual);
    assertNull(actual.getContext());
    SortedSet<Translation> translations = actual.getTranslations();
    assertEquals(1, translations.size());
    Object[] actualTranslations = actual.getTranslations().toArray();
    Translation actualTranslation = (Translation) actualTranslations[0];
    assertEquals(defaultCountry, actualTranslation.getCountry());
    assertEquals(defaultLanguage, actualTranslation.getLanguage());
    assertEquals(bundle2, actualTranslation.getBundle());
    assertEquals(expectedState, actualTranslation.getState());
    assertEquals("plain text", actualTranslation.getValue());

    actual = keywordService.getKeyword("importTestTwo");
    assertNotNull(actual);
    assertEquals("this is has an empty value", actual.getContext());
    translations = actual.getTranslations();
    assertEquals(1, translations.size());
    actualTranslations = actual.getTranslations().toArray();
    actualTranslation = (Translation) actualTranslations[0];
    assertEquals(defaultCountry, actualTranslation.getCountry());
    assertEquals(defaultLanguage, actualTranslation.getLanguage());
    assertEquals(bundle2, actualTranslation.getBundle());
    assertEquals(expectedState, actualTranslation.getState());
    assertNull(actualTranslation.getValue());

    actual = keywordService.getKeyword("importTestThree");
    assertNotNull(actual);
    assertEquals("updates an existing key", actual.getContext());
    translations = actual.getTranslations();
    assertEquals(2, translations.size());
    actualTranslations = actual.getTranslations().toArray();
    actualTranslation = (Translation) actualTranslations[1];
    assertEquals(defaultCountry, actualTranslation.getCountry());
    assertEquals(defaultLanguage, actualTranslation.getLanguage());
    assertEquals(bundle2, actualTranslation.getBundle());
    assertEquals(expectedState, actualTranslation.getState());
    assertEquals("new value 3", actualTranslation.getValue());

    actual = keywordService.getKeyword("importTestFour");
    assertNotNull(actual);
    assertNull(actual.getContext());
    translations = actual.getTranslations();
    assertEquals(2, translations.size());
    actualTranslations = actual.getTranslations().toArray();
    actualTranslation = (Translation) actualTranslations[1];
    assertEquals(defaultCountry, actualTranslation.getCountry());
    assertEquals(defaultLanguage, actualTranslation.getLanguage());
    assertEquals(bundle2, actualTranslation.getBundle());
    assertEquals(expectedState, actualTranslation.getState());
    assertNull(actualTranslation.getValue());

    actual = keywordService.getKeyword("importTestFive");
    assertNotNull(actual);
    assertEquals("existing", actual.getContext());
    translations = actual.getTranslations();
    assertEquals(2, translations.size());
    actualTranslations = actual.getTranslations().toArray();
    actualTranslation = (Translation) actualTranslations[0];
    assertEquals(defaultCountry, actualTranslation.getCountry());
    assertEquals(defaultLanguage, actualTranslation.getLanguage());
    assertEquals(bundle2, actualTranslation.getBundle());
    assertEquals(expectedState, actualTranslation.getState());
    assertEquals("<data> ! ?", actualTranslation.getValue());
}

From source file:org.codehaus.mojo.license.DefaultThirdPartyTool.java

/**
 * {@inheritDoc}//  w w  w  .  ja  v  a  2  s .  c o  m
 */
@Override
public SortedSet<MavenProject> getProjectsWithNoLicense(LicenseMap licenseMap, boolean doLog) {

    Logger log = getLogger();

    // get unsafe dependencies (says with no license)
    SortedSet<MavenProject> unsafeDependencies = licenseMap.get(LicenseMap.getUnknownLicenseMessage());

    if (doLog) {
        if (CollectionUtils.isEmpty(unsafeDependencies)) {
            log.debug("There is no dependency with no license from poms.");
        } else {
            log.debug("There is " + unsafeDependencies.size() + " dependencies with no license from poms : ");
            for (MavenProject dep : unsafeDependencies) {

                // no license found for the dependency
                log.debug(" - " + MojoHelper.getArtifactId(dep.getArtifact()));
            }
        }
    }

    return unsafeDependencies;
}

From source file:org.easyrec.plugin.arm.impl.AssocRuleMiningServiceImpl.java

@Override
public Collection<SortedSet<ItemAssocVO<Integer, Integer>>> createBestRules(List<TupleVO> tuples,
        TObjectIntHashMap<ItemVO<Integer, Integer>> L1, ARMConfigurationInt configuration, ARMStatistics stats,
        Double minConfidence) {//from   ww w.  j  ava2s .  com
    // Integer h1, h2;
    Double dh1, dh2;

    Integer sup1, sup2;
    Double dsup1, dsup2, assocValue1, assocValue2;

    Double baskets = new Double(stats.getNrBaskets());
    stats.setMetricType(configuration.getMetricType());
    //Vector<ItemAssocVO<Integer,Integer>> ret = new Vector<ItemAssocVO<Integer,Integer>>();
    Map<ItemVO<Integer, Integer>, SortedSet<ItemAssocVO<Integer, Integer>>> ret = new HashMap<>();
    for (TupleVO tuple : tuples) {
        sup1 = L1.get(tuple.getItem1());
        dsup1 = new Double(sup1);
        sup2 = L1.get(tuple.getItem2());
        dsup2 = new Double(sup2);
        if (sup1 == null || sup2 == null) {
            continue;
        }
        // confidence
        //          h1 = (tuple.getSupport() * 100) / sup1;
        //          h2 = (tuple.getSupport() * 100) / sup2;

        // confidence
        dh1 = (tuple.getSupport() * 100) / dsup1;
        dh2 = (tuple.getSupport() * 100) / dsup2;

        // lift
        Double lift = tuple.getSupport() / (dsup1 * dsup2);

        // conviction
        Double conviction1 = (1 - (dsup2 / baskets)) / (100 - dh1);
        Double conviction2 = (1 - (dsup1 / baskets)) / (100 - dh2);

        // ltc
        Double ltc1 = dsup1 * Math.log10(dsup1 / dsup2);
        Double ltc2 = dsup2 * Math.log10(dsup2 / dsup1);

        switch (configuration.getMetricType()) {
        case CONFIDENCE:
            assocValue1 = dh1;
            assocValue2 = dh2;
            break;
        case CONVICTION:
            assocValue1 = conviction1;
            assocValue2 = conviction2;
            break;
        case LIFT:
            assocValue1 = lift;
            assocValue2 = lift;
            break;
        case LONGTAIL:
            assocValue1 = ltc1;
            assocValue2 = ltc2;
            break;
        default:
            assocValue1 = dh1;
            assocValue2 = dh2;
            break;
        }

        //          public ItemAssocVO(T tenant, ItemVO<T, I, IT> itemFrom, AT assocType,
        //                          Double assocValue, ItemVO<T, I, IT> itemTo, ST sourceType,
        //                          String sourceInfo, VT viewType, Boolean active)

        if (dh1 >= (minConfidence)) {

            SortedSet<ItemAssocVO<Integer, Integer>> bestRules = ret.get(tuple.getItem1());
            if (bestRules == null) {
                bestRules = new TreeSet<>();
            }
            if ((bestRules.size() < configuration.getMaxRulesPerItem())
                    || (assocValue1 > bestRules.first().getAssocValue())) { // no need to create objects if limit already reached and rule shows worse quality
                String comment1 = null;
                if (configuration.getStoreAlternativeMetrics()) {
                    comment1 = new StringBuilder("conf=").append(String.format("%04f", dh1)).append(" lift=")
                            .append(String.format("%04f", lift)).append(" convic=")
                            .append(String.format("%04f", conviction1)).append(" ltc=")
                            .append(String.format("%04f", ltc1)).append(" sup1=")
                            .append(String.format("%04f", dsup1)).append(" sup2=")
                            .append(String.format("%04f", dsup2)).append(" tsup=").append(tuple.getSupport())
                            .toString();
                }
                ItemAssocVO<Integer, Integer> rule = new ItemAssocVO<>(configuration.getTenantId(),
                        tuple.getItem1(), configuration.getAssocType(), assocValue1
                        /*new Double(h1)*/, tuple.getItem2(),
                        typeMappingService.getIdOfSourceType(configuration.getTenantId(),
                                ARMGenerator.ID.toString() + "/" + ARMGenerator.VERSION),
                        comment1, typeMappingService.getIdOfViewType(configuration.getTenantId(),
                                TypeMappingService.VIEW_TYPE_COMMUNITY),
                        true, stats.getStartDate());

                bestRules.add(rule);
                if (bestRules.size() > configuration.getMaxRulesPerItem()) {
                    bestRules.remove(bestRules.first());
                }
                ret.put(tuple.getItem1(), bestRules);
            }
        }

        if (dh2 >= (minConfidence)) {

            SortedSet<ItemAssocVO<Integer, Integer>> bestRules = ret.get(tuple.getItem2());
            if (bestRules == null) {
                bestRules = new TreeSet<>();
            }
            if ((bestRules.size() < configuration.getMaxRulesPerItem())
                    || (assocValue2 > bestRules.first().getAssocValue())) { // no need to create objects if limit already reached and rule shows worse quality
                String comment2 = null;
                if (configuration.getStoreAlternativeMetrics()) {
                    comment2 = new StringBuilder("conf=").append(String.format("%04f", dh2)).append(" lift=")
                            .append(String.format("%04f", lift)).append(" convic=")
                            .append(String.format("%04f", conviction2)).append(" ltc=")
                            .append(String.format("%04f", ltc2)).append(" sup2=")
                            .append(String.format("%04f", dsup2)).append(" sup1=")
                            .append(String.format("%04f", dsup1)).append(" tsup=").append(tuple.getSupport())
                            .toString();
                }
                ItemAssocVO<Integer, Integer> rule = new ItemAssocVO<>(configuration.getTenantId(),
                        tuple.getItem2(), configuration.getAssocType(), assocValue2
                        /*new Double(h2)*/, tuple.getItem1(),
                        typeMappingService.getIdOfSourceType(configuration.getTenantId(),
                                ARMGenerator.ID.toString() + "/" + ARMGenerator.VERSION),
                        comment2, typeMappingService.getIdOfViewType(configuration.getTenantId(),
                                TypeMappingService.VIEW_TYPE_COMMUNITY),
                        true, stats.getStartDate());
                bestRules.add(rule);
                if (bestRules.size() > configuration.getMaxRulesPerItem()) {
                    bestRules.remove(bestRules.first());
                }
                ret.put(tuple.getItem2(), bestRules);
            }
        }
    }
    return ret.values();
}

From source file:org.wrml.runtime.schema.Prototype.java

private void addProtoSlot(final ProtoSlot protoSlot) {

    final String slotName = protoSlot.getName();
    _ProtoSlots.put(slotName, protoSlot);
    _AllSlotNames.add(slotName);//  www.  j a  v  a  2 s . c  o m

    final SortedSet<String> aliases = protoSlot.getAliases();
    if (aliases != null && aliases.size() > 0) {
        for (final String alias : aliases) {
            _SlotAliases.put(alias, slotName);
        }
    }

    if (protoSlot instanceof CollectionPropertyProtoSlot) {

        final CollectionPropertyProtoSlot collectionPropertyProtoSlot = (CollectionPropertyProtoSlot) protoSlot;

        _CollectionPropertyProtoSlots.put(slotName, collectionPropertyProtoSlot);
    } else if (protoSlot instanceof PropertyProtoSlot) {
        final PropertyProtoSlot propertyProtoSlot = (PropertyProtoSlot) protoSlot;

        final boolean isSearchable = propertyProtoSlot.isSearchable();

        if (isSearchable) {
            _SearchableSlots.add(propertyProtoSlot.getName());
        }
    }

}

From source file:org.wrml.runtime.DefaultModel.java

private void initKeySlots(final Model model, final Keys keys) {

    final SchemaLoader schemaLoader = getContext().getSchemaLoader();
    final URI documentSchemaUri = schemaLoader.getDocumentSchemaUri();

    URI uri = null;/*w w  w.j a va  2s  .c  o m*/

    // Apply all of these Keys to the cached model (in case any Key values are "new").
    for (final URI keyedSchemaUri : keys.getKeyedSchemaUris()) {
        final Object keyValue = keys.getValue(keyedSchemaUri);

        final Prototype keyedPrototype = schemaLoader.getPrototype(keyedSchemaUri);
        final SortedSet<String> keySlotNames = keyedPrototype.getDeclaredKeySlotNames();

        if (keySlotNames.size() == 1) {
            if (documentSchemaUri.equals(keyedSchemaUri)) {
                // Save the document key slot (uri) for last so that the hypermedia engine has all other keys
                // available
                // (to auto-generate the Link href values).
                uri = (URI) keyValue;
            } else {
                setSlotValue(model, keySlotNames.first(), keyValue, keyedSchemaUri, false);
            }
        } else if (keyValue instanceof CompositeKey) {
            final CompositeKey compositeKey = (CompositeKey) keyValue;
            final Map<String, Object> keySlots = compositeKey.getKeySlots();
            for (final String keySlotName : keySlots.keySet()) {
                setSlotValue(model, keySlotName, keySlots.get(keySlotName), keyedSchemaUri, false);
            }
        }
    }

    // See comment above regarding saving the uri key slot for last.
    if (uri != null) {
        setSlotValue(model, Document.SLOT_NAME_URI, uri, documentSchemaUri, false);
    }
}

From source file:org.paxle.core.filter.impl.FilterManager.java

/**
 * @see MetaTypeProvider#getObjectClassDefinition(String, String)
 *//*www  .  j  av  a2  s. co m*/
public ObjectClassDefinition getObjectClassDefinition(final String id, final String localeStr) {
    final Locale locale = (localeStr == null) ? Locale.ENGLISH : new Locale(localeStr);
    final ResourceBundle rb = resourceBundleTool.getLocalization(IFilterManager.class.getSimpleName(), locale);

    return new ObjectClassDefinition() {
        public AttributeDefinition[] getAttributeDefinitions(int filter) {
            ArrayList<AttributeDefinition> attribs = new ArrayList<AttributeDefinition>();

            // default filter activation status
            attribs.add(new AttributeDefinition() {
                public String getID() {
                    return CM_FILTER_DEFAULT_STATUS;
                }

                public int getCardinality() {
                    return 0;
                }

                public String[] getDefaultValue() {
                    return new String[] { Boolean.TRUE.toString() };
                }

                public String getDescription() {
                    return rb.getString("filterDefaultStatus.desc");
                }

                public String getName() {
                    return rb.getString("filterDefaultStatus.name");
                }

                public String[] getOptionLabels() {
                    return null;
                }

                public String[] getOptionValues() {
                    return null;
                }

                public int getType() {
                    return AttributeDefinition.BOOLEAN;
                }

                public String validate(String value) {
                    return null;
                }
            });

            // current filter activation status
            for (Map.Entry<String, SortedSet<FilterContext>> entry : filters.entrySet()) {
                final String queueID = entry.getKey();
                final SortedSet<FilterContext> filtersForTarget = entry.getValue();
                if (filtersForTarget.size() == 0)
                    continue;

                attribs.add(new AttributeDefinition() {
                    public String getID() {
                        return CM_FILTER_ENABLED_FILTERS + queueID;
                    }

                    public int getCardinality() {
                        return filtersForTarget.size();
                    }

                    public String[] getDefaultValue() {
                        return getFilterContextPIDs(filtersForTarget, false);
                    }

                    public String getDescription() {
                        return MessageFormat.format(rb.getString("filterListParam.desc"), queueID);
                    }

                    public String getName() {
                        return MessageFormat.format(rb.getString("filterListParam.name"), queueID);
                    }

                    public String[] getOptionLabels() {
                        return getFilterNames(localeStr, filtersForTarget, true);
                    }

                    public String[] getOptionValues() {
                        return getFilterContextPIDs(filtersForTarget, true);
                    }

                    public int getType() {
                        return AttributeDefinition.STRING;
                    }

                    public String validate(String value) {
                        return null;
                    }
                });

            }

            return attribs.toArray(new AttributeDefinition[attribs.size()]);
        }

        public String getDescription() {
            return rb.getString("filterManager.desc");
        }

        public String getID() {
            return PID;
        }

        public InputStream getIcon(int size) throws IOException {
            return null;
        }

        public String getName() {
            return rb.getString("filterManager.name");
        }
    };
}