Example usage for java.lang String getClass

List of usage examples for java.lang String getClass

Introduction

In this page you can find the example usage for java.lang String getClass.

Prototype

@HotSpotIntrinsicCandidate
public final native Class<?> getClass();

Source Link

Document

Returns the runtime class of this Object .

Usage

From source file:net.big_oh.common.web.WebUtil.java

/**
 * Calculate an <b>approximation</b> of the memory consumed by all objects
 * stored in the {@link HttpSession}. The estimate will often be greater
 * than the actual value because of "double counting" objects that appear in
 * the object graphs of multiple session attributes.
 * //from   w ww . j  a va 2 s  . c om
 * @param session
 *            An HttpSession object from any web application.
 * @return An <b>approximation</b> of the memory consumed by objects stored
 *         in the HttpSession object.
 */
public static long approximateSessionSizeInBytes(HttpSession session) {
    // Strategy used here is to sum memory consumed by all key/value pairs
    // stored in the session

    long sizeInBytes = 0;

    Map<String, Integer> attributeNameMap = getSessionAttributeNameToApproxSizeInBytesMap(session);
    for (String attributeName : attributeNameMap.keySet()) {
        sizeInBytes += attributeNameMap.get(attributeName);
    }

    // Map<String, Integer> attributeMap =
    // getSessionAttributeNameToApproxSizeInBytesMap(session);
    for (String attributeName : attributeNameMap.keySet()) {
        try {
            sizeInBytes += approximateObjectSize(session.getAttribute(attributeName));
        } catch (IOException ioe) {
            logger.error("Failed to approximate size of value associated with session attribute name: "
                    + attributeName.getClass().getName(), ioe);
        }
    }

    return sizeInBytes;

}

From source file:org.apache.bookkeeper.meta.MetadataDrivers.java

private static void loadInitialClientDrivers() {
    Set<String> driverList = Sets.newHashSet();

    // add default zookeeper based driver
    driverList.add(ZK_CLIENT_DRIVER_CLASS);

    // load drivers from system property
    String driversStr = System.getProperty(BK_METADATA_CLIENT_DRIVERS_PROPERTY);
    if (null != driversStr) {
        String[] driversArray = StringUtils.split(driversStr, ':');
        for (String driver : driversArray) {
            driverList.add(driver);//from ww w .j  a  v  a 2s.c o  m
        }
    }

    // initialize the drivers
    for (String driverClsName : driverList) {
        try {
            MetadataClientDriver driver = ReflectionUtils.newInstance(driverClsName,
                    MetadataClientDriver.class);
            MetadataClientDriverInfo driverInfo = new MetadataClientDriverInfo(driver.getClass());
            clientDrivers.put(driver.getScheme().toLowerCase(), driverInfo);
        } catch (Exception e) {
            log.warn("Failed to load metadata client driver {}", driverClsName, e);
        }
    }
}

From source file:org.apache.bookkeeper.meta.MetadataDrivers.java

private static void loadInitialBookieDrivers() {
    Set<String> driverList = Sets.newHashSet();

    // add default zookeeper based driver
    driverList.add(ZK_BOOKIE_DRIVER_CLASS);

    // load drivers from system property
    String driversStr = System.getProperty(BK_METADATA_BOOKIE_DRIVERS_PROPERTY);
    if (null != driversStr) {
        String[] driversArray = StringUtils.split(driversStr, ':');
        for (String driver : driversArray) {
            driverList.add(driver);/*  w w w  .ja  va  2 s. c o m*/
        }
    }

    // initialize the drivers
    for (String driverClsName : driverList) {
        try {
            MetadataBookieDriver driver = ReflectionUtils.newInstance(driverClsName,
                    MetadataBookieDriver.class);
            MetadataBookieDriverInfo driverInfo = new MetadataBookieDriverInfo(driver.getClass());
            bookieDrivers.put(driver.getScheme().toLowerCase(), driverInfo);
        } catch (Exception e) {
            log.warn("Failed to load metadata bookie driver {}", driverClsName, e);
        }
    }
}

From source file:org.agnitas.dao.impl.MailingDaoImpl.java

/**
 * Build an SQL-expression from th egiven target_expression.
 * The expression is a list of targetIDs connected with the operators:
 * <ul>//from   w ww  .j av  a 2  s  .  c om
 * <li>( - block start
 * <li>) - block end
 * <li>&amp; - AND 
 * <li>| - OR 
 * <li>! - NOT 
 * </ul>
 * @param targetExpression The expression as string.
 * @param jdbc Template for SQL queries.
 * @return the resulting where clause.
 */
static String getSQLExpression(String targetExpression, JdbcTemplate jdbc) {
    StringBuffer buf = new StringBuffer();
    int tlen = targetExpression.length();

    if (targetExpression == null) {
        return null;
    }
    for (int n = 0; n < tlen; ++n) {
        char ch = targetExpression.charAt(n);

        if ((ch == '(') || (ch == ')')) {
            buf.append(ch);
        } else if ((ch == '&') || (ch == '|')) {
            if (ch == '&')
                buf.append(" AND");
            else
                buf.append(" OR");
            while (((n + 1) < tlen) && (targetExpression.charAt(n + 1) == ch))
                ++n;
        } else if (ch == '!') {
            buf.append(" NOT");
        } else if (Character.isDigit(ch)) {
            String temp = "";
            int first = n;
            int tid = (-1);

            while (n < tlen && Character.isDigit(ch)) {
                n++;
            }
            tid = Integer.parseInt(targetExpression.substring(first, n));
            temp = (String) jdbc.queryForObject("select target_sql from dyn_target_tbl where target_id = ?",
                    new Object[] { new Integer(tid) }, temp.getClass());
            if (temp != null && temp.trim().length() > 2)
                buf.append(" (" + temp + ")");
        }
    }
    if (buf.length() >= 3)
        return buf.toString();
    return null;
}

From source file:org.apache.tomcat.util.IntrospectionUtils.java

public static void callMain(Class c, String args[]) throws Exception {
    Class p[] = new Class[1];
    p[0] = args.getClass();
    Method m = c.getMethod("main", p);
    m.invoke(c, new Object[] { args });
}

From source file:org.hyperic.hq.plugin.jboss.JBossUtil.java

static Double getJSR77Statistic(MBeanServerConnection mServer, ObjectName objName, Metric metric, boolean lc)
        throws MetricNotFoundException, MetricInvalidException, MetricUnreachableException, PluginException {

    //jboss changed attribute case in version 4.0
    String[] attrs;//from  ww  w . j av a2s  .com
    if (lc) {
        attrs = STAT_PROVIDER_4;
    } else {
        attrs = STAT_PROVIDER;
    }

    Stats stats;
    try {
        Boolean provider = (Boolean) mServer.getAttribute(objName, attrs[0]);
        if ((provider == null) || !provider.booleanValue()) {
            String msg = "MBeanServerConnection does not provide statistics";
            throw new PluginException(msg);
        }

        stats = (Stats) mServer.getAttribute(objName, attrs[1]);
    } catch (RemoteException e) {
        throw unreachable(metric, e);
    } catch (InstanceNotFoundException e) {
        throw notfound(metric, e);
    } catch (AttributeNotFoundException e) {
        throw notfound(metric, e);
    } catch (ReflectionException e) {
        throw error(metric, e);
    } catch (MBeanException e) {
        throw error(metric, e);
    } catch (IOException e) {
        throw error(metric, e);
    }

    if (stats == null) {
        throw new PluginException("MBeanServerConnection has no stats");
    }

    String statName = metric.getAttributeName().substring(9);
    Statistic stat = stats.getStatistic(statName);
    if (stat == null) {
        String msg = "Statistic '" + statName + "' not found [" + metric + "]";
        throw new MetricNotFoundException(msg);
    }

    long value;
    if (stat instanceof CountStatistic) {
        value = ((CountStatistic) stat).getCount();
    } else if (stat instanceof RangeStatistic) {
        value = ((RangeStatistic) stat).getCurrent();
    } else {
        String msg = "Unsupported statistic type [" + statName.getClass().getName() + " for [" + metric + "]";
        throw new MetricInvalidException(msg);
    }

    return new Double(value);
}

From source file:gaffer.function.simple.filter.Regex.java

@Override
public boolean isValid(final String input) {
    return !(null == input || input.getClass() != String.class) && controlValue.matcher(input).matches();
}

From source file:gaffer.function.simple.filter.MultiRegex.java

@Override
public boolean isValid(final String input) {
    if (null == input || input.getClass() != String.class) {
        return false;
    }/* w  w  w . ja  v  a 2s  . c o m*/
    for (Pattern pattern : patterns) {
        if (pattern.matcher(input).matches()) {
            return true;
        }
    }
    return false;
}

From source file:com.cloudbees.plugins.credentials.matchers.IdMatcher.java

/**
 * Constructs a new instance.//from   www  . j a v a  2 s.co  m
 *
 * @param id the id to match.
 */
public IdMatcher(@NonNull String id) {
    id.getClass(); // throw NPE if null
    this.id = id;
}

From source file:com.cloudbees.plugins.credentials.matchers.UsernameMatcher.java

/**
 * Constructs a new instance./*from w w w .  j a va 2  s.  co  m*/
 *
 * @param username the username to match.
 */
public UsernameMatcher(@NonNull String username) {
    username.getClass(); // throw NPE if null
    this.username = username;
}