Skip to content

Instantly share code, notes, and snippets.

@gastaldi
Last active December 27, 2015 01:59
Show Gist options
  • Select an option

  • Save gastaldi/7249211 to your computer and use it in GitHub Desktop.

Select an option

Save gastaldi/7249211 to your computer and use it in GitHub Desktop.
/**
* Copyright 2013 Red Hat, Inc. and/or its affiliates.
*
* Licensed under the Eclipse Public License version 1.0, available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package org.jboss.forge.addon.javaee;
import org.jboss.forge.addon.facets.Facet;
import org.jboss.forge.furnace.util.Predicate;
/**
* Registers constraints for a specific facet
*
* @author <a href="ggastald@redhat.com">George Gastaldi</a>
*/
public interface FacetFilterRegistry
{
public <T extends Facet<?>> void register(Class<T> facetType, Predicate<T> filter);
}
/**
* Copyright 2013 Red Hat, Inc. and/or its affiliates.
*
* Licensed under the Eclipse Public License version 1.0, available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package org.jboss.forge.addon.javaee;
import java.util.Collection;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map;
import javax.enterprise.inject.spi.InjectionPoint;
import org.jboss.forge.addon.facets.Facet;
import org.jboss.forge.addon.ui.cdi.CommandScoped;
import org.jboss.forge.addon.ui.input.InputComponent;
import org.jboss.forge.addon.ui.input.InputComponentInjectionEnricher;
import org.jboss.forge.addon.ui.input.SelectComponent;
import org.jboss.forge.furnace.util.Assert;
import org.jboss.forge.furnace.util.Predicate;
/**
* Implementation of the {@link FacetFilterRegistry} interface
*
* @author <a href="ggastald@redhat.com">George Gastaldi</a>
*/
@CommandScoped
@SuppressWarnings("unchecked")
public class FacetFilterRegistryImpl implements InputComponentInjectionEnricher, FacetFilterRegistry
{
private Map<String, Predicate<Object>> filters = new HashMap<String, Predicate<Object>>();
@Override
public <T extends Facet<?>> void register(Class<T> facetType, Predicate<T> filter)
{
Assert.notNull(facetType, "Facet type may not be null");
Assert.notNull(filter, "Filter may not be null");
String key = facetType.getName();
filters.put(key, (Predicate<Object>) filter);
}
@Override
public void enrich(InjectionPoint injectionPoint, InputComponent<?, ?> input)
{
// Works only for SelectComponents
if (input instanceof SelectComponent && Facet.class.isAssignableFrom(input.getValueType()))
{
SelectComponent<?, Object> select = (SelectComponent<?, Object>) input;
String key = input.getValueType().getName();
Predicate<Object> filter = filters.get(key);
if (filter != null)
{
Collection<Object> filteredFacets = new LinkedList<Object>();
Iterable<Object> valueChoices = select.getValueChoices();
if (valueChoices != null)
{
for (Object choice : valueChoices)
{
if (filter.accept(choice))
{
filteredFacets.add(choice);
}
}
}
select.setValueChoices(filteredFacets);
}
}
}
}
@SMDANISH

SMDANISH commented Sep 2, 2015

Copy link
Copy Markdown

I wan in form like.

abstract
abstrac/t
abstra/ct
abstr/act
abst/ract
abs/tract
ab/stract

@SMDANISH

SMDANISH commented Sep 2, 2015

Copy link
Copy Markdown

How ever i could reach with output as

word description

Stem/Suffix: descriptio/n
Stem/Suffix: descripti/no
Stem/Suffix: descript/noi
Stem/Suffix: descrip/noit ................

suffix should come in reverse of what its showing.. with below code

import java.util.Collections;
import java.util.Scanner;
public class MorphemeA
{
public static void main(String args[])
{
Scanner sh = new Scanner(System.in);
System.out.println("Enter a word");
String str = sh.next();
char[] ch = str.toCharArray();
int y = str.length();
for (int m = y ; m <= y; m--)
{
String pl1 = new String(ch,0,m);
if(pl1.length()>=2)
{
int l=8;
char[] dh = new char[l];
int c=y-1;
int g = l-1;
char[] eh = new char[l];
int h = 0;
for (int j=c; j<=y; j--)
{
if(m>2)
{
eh[h] = ch[j];
// Collections.reverse(dh);

            String pl = new String(ch,0,--m);

            //Collections.reverse(eh);

            String mpm  = new String(eh,0,8);


            System.out.println("Stem/Suffix:"+pl +"/"+mpm);
            h++;
 }

    }

}
}
}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment